Point on line closest to two points outside that line

I know there must be an elegant solution I’m just not thinking of here:
Given: two points A and B and a line C,
I’m looking to find: the point X on line C, where line AXB has the minimum distance of any possible point on C.

I realize that if line C is co-planar with A and B, then X can be thought of as the tangent point of an ellipse tangent to C and with foci A and B.
If line C is NOT co-planar with A and B, then X can be thought of as the tangent point of an ellipsoid tangent to C and with foci A and B. Not sure if this helps us at all…

I know there must be an elegant algebraic solution here I’m just not seeing… Anyone have any ideas?

Thanks!
WD

1 Like

Find the closest point on C for both A and B, then find the midpoint between them?

Or find the midpoint between A and B first (their Average) and then find the closest point on C to that?

Hmmm, unfortunately not that easy! See attached screenshot showing closest points in green…

In case it helps here is the *.gh file I used to make the illustration… this only illustrates the co-planar case… but maybe helps give a better sense of what I’m after.

Point on line close to two points2.gh (11.1 KB)

Never underestimate the effectiveness of brute force. :wink:


Point on line close to two points2_2020Aug25b.gh (21.5 KB)

1 Like


Shortest distance.gh (11.2 KB)

For anything more complicated than a line, this problem becomes extremely complex and an analytical solution for a circle was only derived fairly recently! For that, @Joseph_Oster’s method is probably best.

6 Likes

This method avoids the use of Repeat Data and is likely much more efficient.


Point on line close to two points2_2020Aug25c.gh (22.1 KB)

Well done Ethan (@akilli), that is very elegant! Brilliant.

You didn’t internalize your C curve so I copied your code into mine and used @Walt-D’s geometry, then compared your result to mine. Spot on mate!

P.S. That Dots component was annoying (too big) and disabling preview didn’t work so I had to delete it to see the intersection point.

Thanks Joseph @Joseph_Oster but I think this solution goes back to the Greeks. I think I remember reading that Leonardo invented a mechanical device to solve it in the case of a circle It’s a question that ,might have come up when painting a column or a pot and wondering where the reflection of a light source would appear.

Yeah, I read the wikipedia history - still, thanks for bringing it to this thread, it’s the perfect solution.

Joseph and Ethan,
Thanks for both of your insightful replies…
Joseph, I was also thinking about a brute force approach --yours is very nicely done!

Ethan,
Thanks for referring me to Alhazen’s Problem --I have his Book of Optics on the shelf! And your solution using the line to reflect points A and B is indeed quite elegant! Correct me if I’m wrong, but this solution will only work if the line is co-planar to A and B… if the line is not co-planar, we would first need to figure out which plane to reflect in…? Any other thoughts on the non-co-planar case?

Thanks again both of you for your thoughts!

WD

If the points and line are non-planar you can still come up with a similar argument.

Shortest distance non-planar.gh (14.8 KB)

2 Likes

That non-planar solution isn’t as obvious as when they are co-planar but seems to work. However, I see an implementation issue due to an assumption about surface normals from EvalSrf. If the C curve (line) is flipped, the surface normals are reversed and the model fails. There must be a way to code a solution that doesn’t depend on curve direction?

I know. When I first posted it, I thought the image was not adequate, so I adjusted one of the points so it would be more apparent, and the normal flipped on that surface, requiring the need to use an Expression so the rotated plane would again be parallel, so it’s not just curve direction. Maybe EvalSrf isn’t the best choice.

almost, but it seems that using the weighted average do works (using point distance to line as weight), haven’t tested deeply.


weighted average.gh (6.0 KB)

3 Likes

I took a closer look at your planar solution and simplified it to how I thought it was working, using Mirror Curve instead of creating a vertical plane,


Point on line close to two points2_2020Aug26b.gh (14.1 KB)

Not sure yet if/how this might apply to the non-planar case?

1 Like

BRAVO!!! I was wondering about a weighted average but wasn’t sure how to do it. From what I can tell, your solution works fine on both the planar and non-planar cases. I LOVE a simple solution! Very nice.

Still, i feel like i “cheated”.
Is like, pencil on paper, comparing a guy that finds the tangent of a circle by drawing another circle and finding the intersection, and another guy that measure distance and diameter and calculate the position of the tangent point. The latter is so uncool!

Geometrical solution is always more elegant and let you really understand what is going on.
A mathematical solution is more abstract.

I’m not a genius, i was reading this interesting thread and only at @akilli 's non-planar solution i understood that weighted average could be used :sweat_smile:

It does look like it’s correct, so the question is why? Since this all comes down to vector algebra there must be a derivation. Nice work!

Ha ha! Now that I’ve gone over it again I see how I “inspired” you. Once you look at the unfolding into one plane, it’s obvious that its the weighted average along the line. It also avoids the nastiness that @Joseph_Oster mentioned about curve direction.

1 Like