Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Distance Between a Line Segment and a Point???

Status
Not open for further replies.

turtlepokerman

Junior Member level 2
Joined
Nov 8, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,463
Good afternoon everyone,

I am currently working on a program that needs to find the distance between a point and a line SEGMENT. There are plenty of formulas out there that provide the distance between a point and a line, but it is important that it be a line segment and a point. The formula should also be in 3-dimensions. So let's say that I know the Point Vector P = <71,54,29> and the two end segments of the lines at Q1 = <200,200,15> and Q2 = <250,250,15>. Any help is greatly appreciated!!! Please do not provide any code.

Thanks,
 

Are you looking for the distance between the (point A) and a the (point B) on the line segment that is the minimum distance from the (point A), or are you looking for the distance between (Point A) and the mid point of the line segment?
 

Kral - I am looking for the shortest distance between the point and any point on the line segment.

KerimF - That finds the distance between a point and a line. I want to find the distance between a point and a line segment.
 

But the distance between a point and a line is ALWAYS calculated as being the shortest distance (perpendicular).
On the other hand, I agree with you, the formula in the previous webpage is given in function of vectors (of the points Q1, Q2 and P, as x1, x2 and x0), not their coordinates. I mean this needs more work to get the final result (d).

For instance, what is the difference between the distance between a point and a line... and between a point and a line segment?

Added:
I searched for the difference and I knew that in the case of segment there are 3 distances to be verified from which the shortest is chosen.
 
Last edited:

I am currently working on a program that needs to find the distance between a point and a line SEGMENT. There are plenty of formulas out there that provide the distance between a point and a line, but it is important that it be a line segment and a point. The formula should also be in 3-dimensions. So let's say that I know the Point Vector P = <71,54,29> and the two end segments of the lines at Q1 = <200,200,15> and Q2 = <250,250,15>. Any help is greatly appreciated!!! Please do not provide any code.

Thanks,

Try something like this:

Code:
P = <71,54,29>
Q1 = <200,200,15>
Q2 = <250,250,15>

;  Uppercase: Vectors   Lowercase: scalars

V = P - (Q2+Q1)/2
M = (Q2-Q1)/2
v2 = V•V    ; dot product
m2 = M•M
dp = abs(V•M)    ; absolute value

if dp < m2 then
 dist = sqrt(v2-dp^2/m2)
else 
 dist = sqrt(v2+m2-2*dp)
endif
 

I think you can proceed as follows:

first of all let's determine the parametric equation of the straigth line passing by Q1(x1,y1,z1) and Q2(x2,y2,z2). In general:

xt=x1+m*t
yt=y1+n*t
zt=z1+k*t

where: m=x2-x1, n=y2-y1, k=z2-z1

so in our case:

xt=200+50*t
yt=200+50*t
zt=15

zt is constant so we could use the plane geometry, however in general the distance between the point P(xp,yp,zp) and any point of the line is given by:

d^2=(xp-xt)^2 + (yp-yt)^2 + (zp-zt)^2

since P(71,54,29) then:

d^2=(71-200-50*t)^2+(54-200-50*t)^2+29^2 that is:

d^2=(-29-50*t)^2+(-46-50*t)^2+29^2

since we have to find the minimum distance let's derive with respect to "t" and equate to zero:

d(d^2)/dt=2*(-29-50*t)*(-50)+2*(-46-50*t)*(-50)=0

solving we have t=-0.75

substituting "t=-0.75" in the above formula that gives the distance we obtain d=31.39 that is the minimum distance with respect to the line.
We have now to check if this point fall inside the segment (that is 200<=xt<=250, 200<=yt<=250, zt=15). Substitute "t=-0.75" in the equation of the line:

xt=162.5
yt=162.5
zt=15

It's not inside, then the minimum distance will be from Q1 or from Q2

dpq1=sqrt[200-71)^2+(200-54)^2+(15-29)^2] = 195.33
dpq1=sqrt[250-71)^2+(250-54)^2+(15-29)^2] = 265.81

So the minimum distance Point segment should be 195.33

Hope there are no errors in my reasoning.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top