
I am trying to work this out in java with LatLng point
I was looking at this post here Circle line-segment collision detection algorithm?
I have a method to find distance between 2 point. The instruction says
Project the vector AC onto AB. The projected vector, AD, gives the new point D. If the distance between D and C is smaller than (or equal to) R we have an intersection.
I don't have knowledge about vector, could anyone help me how to find point D here ?
Thanks in advance
If you really need D point coordinates - let's vectors
AB = (B.X-A.X, B.Y-A.Y)
AC = (C.X-A.X, C.Y-A.Y)
then the simplest (I believe) form of projection of C to AB is:
AD = AB * (AB.dot.AC) / (AB.dot.AB);
In coordinates:
CF=((B.X-A.X)*(C.X-A.X)+(B.Y-A.Y)*(C.Y-A.Y))/((B.X-A.X)^2+(B.Y-A.Y)^2)
D.X=A.X+(B.X-A.X)*CF
D.Y=A.Y+(B.Y-A.Y)*CF
Distance CD, as David Wallace has already written, is
|CD| = |AC x AB|/|AB| (x = cross product)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With