Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


In 3D, finding the perpendicular distance of a point to a line?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 johnnyBravo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 12 July 2007 - 09:33 PM

In 3D, I'm finding the perpendicular distance of a point to a line (consisting of a point and a direction vector). I've found two different ways, one using the dot product, distance between point on the line and using sin to find the length of the side aka the distance. the second was with the distance forumulae combined with the vector multiplied by an unknown, and i derive the the equation to find the min of the unknown which subbed into the dist forumale to get the distance. My problem is I feel there should be much a simpler solution to this. Is there another simpler way of doing this? thx

Sponsor:

#2 Ezbez   Crossbones+   -  Reputation: 1164

Like
0Likes
Like

Posted 12 July 2007 - 09:55 PM

1). Find slope of line perpendicular to the line, call it pm
2). Create a line that goes through the point and has a slope of pm
3). Intersect this new line and the original line
4). Find distance between the intersection point and the original point

Of course, it's a bit more than four steps when you do it out in code, but it shouldn't be bad.

Edit: Oh gods, I forgot step 4! How could I do that?

#3 johnnyBravo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 12 July 2007 - 11:31 PM

Isn't that just for 2D?

#4 scgames   Members   -  Reputation: 1981

Like
0Likes
Like

Posted 13 July 2007 - 02:02 AM

Quote:
Original post by johnnyBravo
Isn't that just for 2D?
Yeah (also, even in 2D I wouldn't recommend approaching this sort of problem in terms of slopes).

The equation to find the closest point on a line to a point (in any dimension) is:
closest = O + ((P-O).D)/(D.D) * D

Where:

P is the query point
O is the line origin
D is the line direction
There are several ways to derive this, one of which is as a minimization problem (which I assume is what you were referring to earlier). However you derive it though, I don't think there's any simpler solution than the above.

#5 johnnyBravo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 July 2007 - 02:19 AM

Ah ok.
Quote:
Original post by jyk
[code=auto:0]((P-O).D)/(D.D)


I had pretty much the same thing except I had ((P-O).D)/(2*(D.D))

The 2 was from in the distance formulae part eg (2*b)*t + (c^2)*t^2


Or am I wrong?

thx





#6 scgames   Members   -  Reputation: 1981

Like
0Likes
Like

Posted 13 July 2007 - 02:28 AM

Quote:
Original post by johnnyBravo
Ah ok.
Quote:
Original post by jyk
[code=auto:0]((P-O).D)/(D.D)


I had pretty much the same thing except I had ((P-O).D)/(2*(D.D))

The 2 was from in the distance formulae part eg (2*b)*t + (c^2)*t^2


Or am I wrong?

thx
Yeah, it looks like you've got an extra '2' in there.

I'll sketch out the derivation here (very informally) so you can compare it to yours:
f(P) = (P-(O+tD))^2
f(P) = (P-O-tD)^2
d = P-O
f(P) = (d-tD)^2
f(P) = D^2t^2-2dDt+d^2
f'(P) = 2D^2t - 2dD
2D^2t - 2dD = 0
2D^2t = 2dD
D^2t = dD
t = dD/D^2


#7 relsoft   Members   -  Reputation: 255

Like
0Likes
Like

Posted 13 July 2007 - 02:33 AM

The above equation Jyk made is the simplest one I could imagine.

What the equation does is this:

1. Get vector from O to P
2. Project the OP vector to line(vector) D , which would drop a perpendicular from point P to line D.
3. Now the projection would give you the component(a distance) of the OP vector from O to P parallel to D. I hope you could understand me.
4. The return depends on where P lies. Left or right of the line.

#8 johnnyBravo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 July 2007 - 02:53 AM

Quote:
Original post by jyk

f(P) = D^2t^2-2dDt+d^2
f'(P) = 2D^2t - 2dD


Ah I forgot to multiply it by 2 when I derived the t^2

Thanks!





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS