Suppose line segment is defined by two points A and B. Let C be another point. Our goal is to compute the shortest distance from point C to line segment AB.
First, let’s write the parametric equation for the line going through the points A and B:
Let P be the point on the line L and let’s assume that C-P is the shortest distance from C to L:
So the magnitude of C-P is:
Since we are looking for the shortest distance we shall find the derivative of |C-P| as a function of t, then seek for the minimum:
thus we can find t:
The most trivial way to check if point P is on the line segment AB is to check if |AB|=|AP|+|PB|.
Checking distance involves a calculation of sqrt. Sometimes it could be better to just check if Px \in (min(Ax,Bx), max(Ax,Bx)) and Py \in (min(Ay,By), max(Ay,By)). As P is on the line this actually suffices.
ReplyDeleteContrats on your first post!
JTG: Welcome to JTG - Casino | Official Website | JamBase
ReplyDeleteJTG is a premier 구미 출장샵 social casino in 전라남도 출장샵 Washington State offering slots, table 충주 출장안마 games, live 고양 출장안마 entertainment 익산 출장마사지 and top-notch dining destinations.
crusedFtoda Dan Hacker https://wakelet.com/wake/Pzbk_xWzsrgODznjFdZIo
ReplyDeletebreathracmofan