tag:blogger.com,1999:blog-13053610.post5346379086165973017..comments2024-01-07T10:01:32.421-08:00Comments on Q & Stuff: Exercise for the ReaderJustin Olbrantz (Quantam)http://www.blogger.com/profile/02155606291145056334noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-13053610.post-62414671087064296922007-11-29T00:02:00.000-08:002007-11-29T00:02:00.000-08:00Err. (yA, yB, yP) x (xA, xB, xP)? I'm not familiar...Err. (yA, yB, yP) x (xA, xB, xP)? I'm not familiar with using the cross product in that manner - only the standard (xA, yA, zA) x (xB, yB, zB).Justin Olbrantz (Quantam)https://www.blogger.com/profile/02155606291145056334noreply@blogger.comtag:blogger.com,1999:blog-13053610.post-39501012804218736412007-11-28T13:28:00.000-08:002007-11-28T13:28:00.000-08:00sqrt((xB * yA - xP * yA - xA * yB + xP * yB + xA *...sqrt((xB * yA - xP * yA - xA * yB + xP * yB + xA * yP - xB * yP)^2 / ((xA - xB)^2 + (yA - yB)^2)<BR/><BR/>where (xA, yA) and (xB, yB) are the endpoints to your line, and (xP, yP) is your point.<BR/><BR/>Note that this extends your line infinitely. you could do a simple check to make sure that yP falls between yA and yB. If not, use the distance formula to both endpoints and take the minimum.<BR/><BR/>If you're doing many comparisons to the same line segment, you could cache the products xB * yA, xA * yB, and the square of the distance of the line (in the denominator).<BR/><BR/>If you have an infinite line (no endpoints), but have its slope and y-intercept, you can find the distance with:<BR/><BR/>sqrt((xP - (-bAB * mAB + xP + mAB * yP) / (1 + mAB^2))^2 + (-(xP / mAB) + ( -bAB * mAB + xP + mAB * yP) / (mAB * (1 + mAB^2)))^2)rgovhttps://www.blogger.com/profile/14896757708297311326noreply@blogger.com