Determine If Two Points Are Near
.net, c#, math, vb.net
Solution
You can use the Pythagorean formula to calculate the distance between two points. In C#:
var d = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2))
Why does this work? Have a look at the following diagram and remember that `a^2 + b^2 = c^2` holds for right triangles:
Problem
I have the following: ``` bool AreNear(Point Old, Point Current) { int x1 = Convert.ToInt32(Old.X); int x2 = Convert.ToInt32(Current.X); int y1 = Convert.ToInt32(Old.Y); int y2 = Convert.ToInt32(Current.Y); if (x1 == x2) { if (y1 == y2) { return true; } } return false; } ``` I want to return true in the function if the current point is in 25 pixels radius of the old point. Can anyone tell me how to do that?