Ask Your Question

function for detecting proximity of points

asked 2013-04-17 02:42:04 -0600

steve55 gravatar image


Is there a function available that will indicate if a set of coordinates is within a proximity of another set of coordinates?

I have a straight line and i want to detect if that is close to another line's coordinates or the edge of a circle.

Thanks in advance


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-04-18 01:58:54 -0600

You actually need to define close, since that has a relative meaning. Do you mean smaller then 5 pixels? Smaller then 50 pixels?

What you basically want to do is look into distance calculation between points. What you could do is determine the center point of both groups of points and then do an euclidean distance between them. You can easily program this yourself.

edit flag offensive delete link more


I was looking for a function that could possible accept a distance variable as an input (5 pixels, 10 pixels) when the function is called. Thanks for the advice, when you mention center point are you talking about an (x, y) coordinate? and do an euclidean distance between 2 sets of theses (x, y) coordinated?

steve55 gravatar imagesteve55 ( 2013-04-18 02:35:09 -0600 )edit

What I would suggest in your case is

  • Create a function bool close(Point point1, Point point2, int distance){ ... }
  • Inside the function, calculate the euclidean distance between both
  • Once calculated threshold it towards the distance variable and return false or true

This would mean you would need to calculate the center points first. Which can actually be done by taking a point cloud and calculating the average x and average y coordinate.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-18 02:38:41 -0600 )edit

Question Tools


Asked: 2013-04-17 02:42:04 -0600

Seen: 812 times

Last updated: Apr 18 '13