We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a line segment and a circle in my processing sketch. I want the center of the circle, point q, to find the closest point, p, on the line segment and the circle will move towards it. I'm not quite sure how to code this, so any suggestions would be great! Thanks!
Answers
Draw us a picture
Two hints:
1) the calculated point can be outside the line
2) check division by zero
Have a look at pages 7 & 8 of my Geometry Cookbook. It provides the code to solve this problem and many others to boot :)
that book has a lot of great examples in there, thanks!
Would anyone have any suggestions of how we could show the circle moving towards that point on the line segment?
Ceaser, what do you mean?
I pushed the projection code here - https://openprocessing.org/sketch/413945.
@cameo your solution is very good
I'we made a function zoning on on the closest point along a "line spline" by O(log n) comparisons of dot products.
I think ill make it break the loop and do your calculation when the closest segment is found.
@causar