I need to calculate the distance between two places the mouse was clicked on the screen.
target(x & Y) & source(X & Y) are populated on the mouse move event (e.X & e.Y)
I have distance = Math.Sqrt(Math.Pow(targetX - sourceX, 2) + Math.Pow(targetY - sourceY, 2));
This gives me a result but if I'm honest I am not sure what unit the measurement is in or how to convert it. How can I convert that result in a meaningful result such as cm's or inches? I'm guessing I will need to take the screen res into account?
Update Im just killing time really. Not looking for an excellent solution just something that works. It will only last a day or two.
Here is the MoveMove
event and the call made. Should have posted it all before to be clearer.
private void HookManager_MouseMove(object sender, MouseEventArgs e)
{
labelMousePosition.Text = string.Format("x={0:0000}; y={1:0000}", e.X, e.Y);
AddDistance(Convert.ToDouble(e.X), Convert.ToDouble(e.Y));
}
private void AddDistance(double targetX, double targetY)
{
if (sourceX != 0 && sourceY != 0)
{
double distance = Convert.ToDouble(lblDistanceTravelled.Text);
distance =+ Math.Sqrt(Math.Pow(targetX - sourceX, 2) + Math.Pow(targetY - sourceY, 2));
lblDistanceTravelled.Text = distance.ToString();
}
sourceX = targetX;
sourceY = targetY;
}