0
$\begingroup$

I have a set of points P1(x1,y1), P2(x2,y2), P3(x3,y3), P4(x4,y4), P5(x5,y5) in the Cartesian plane. I am trying to find the closest point to P1 based on the orientation and Euclidean distance. What I mean is the following:

Suppose that P3 is the closet to P1 and P5 is the second closest, but the angle between P1 and P3 is greater than the angle between P1 and P5.

How can I find this balance between the points?

$\endgroup$
5
  • 1
    $\begingroup$ You will have to define exactly how you want to trade off a better angular match against a better distance match. As is, your problem is not well posed. For example, a simple way is define an error metric that weights the squares of the deviations: $J = \alpha (\Delta \theta)^2 + \beta (\Delta r)^2$. $\endgroup$ – Victor Liu Oct 21 '13 at 9:19
  • $\begingroup$ Hi @Victor Can u please check this Link I posted a picture to explain what I mean : link $\endgroup$ – Hani Gotc Oct 21 '13 at 9:22
  • $\begingroup$ I see Yes Actually That's what i am trying to find you can say that it's a trade off between the distance and angles I see $\endgroup$ – Hani Gotc Oct 21 '13 at 9:24
  • 1
    $\begingroup$ I'm going to go out on a limb and guess that you don't know what Euclidean distance actually means. Instead of using the horizontal distance and the angle, you can use the horizontal displacement (call it dx) and the vertical displacement (call it dy). Then the distance you want is sqrt(dxdx + dydy). This automatically adjusts for both the horizontal offset and the vertical angle. $\endgroup$ – k20 Oct 21 '13 at 18:09
  • $\begingroup$ Naa I don't have to go that far. As @Virtor mentioned i want to find a trade-off between the distance and angle. I only had to divide the distance by the cos(theta) That's all. Y-distance / cos(\theta) $\endgroup$ – Hani Gotc Oct 23 '13 at 10:03
0
$\begingroup$

Unless you have a huge number of points, you can just do a linear search through the sorted list to evaluate your error metric, trying to find the smallest value. You might be able to do slightly better if you sort them all by distance away from your query point, in increasing order, then you likely only have to search the beginning portion of the sorted list.

But as I mentioned above in the comments, you don't seem to know exactly how you want to gauge "nearness," so I can't give you a more detailed solution.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.