I have two points (x1,y1) and (x2,y2). I want to know whether the points are within 5 meters of one another.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
measure the square distance from one point to the other:
where d is the distance, (x1,y1) are the coordinates of the ‘base point’ and (x2,y2) the coordinates of the point you want to check.
or if you prefer:
Noticed that the preferred one does not call Pow at all for speed reasons, and the second one, probably slower, as well does not call
Math.Sqrt, always for performance reasons. Maybe such optimization are premature in your case, but they are useful if that code has to be executed a lot of times.Of course you are talking in meters and I supposed point coordinates are expressed in meters too.