Jump to content
  • Advertisement
Sign in to follow this  
Kitasia

Distance from point to plane along a vector

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm looking for a way to find the distance from a point toa plane along a vector. I can get the distance from the point to the plane like so DotProduct(point,plane.Normal) +plane.Distance; but I'm not sure how to do it about a vector. This may explain what I want to do....
                O < Point
                |
                | 
                |
 _______________V_____________________________ < Plane

//
//This is the regular distance to plane, what I want is this
//


                O < Point
               /  
              /    
             /      
            /       
 _________|/__________________________________ < Plane


Any suggestions? Worst case scenario, I have to cast a ray into the plane. Is that practical for such an operation?

Share this post


Link to post
Share on other sites
Advertisement
Find the intersection between the plane and the line P + t*v and then calculate the distance between the two points.

EDIT: if the vector is of unit length than t is the distance you are searching. If it isn’t of unit length than the distance is t * length(v)

[Edited by - apatriarca on June 11, 2008 6:49:12 PM]

Share this post


Link to post
Share on other sites
So in other words, I'd need to cast a ray to find out the information? It seems as if it would be even simpler than that.

Share this post


Link to post
Share on other sites
Ray-Plane intersection isn’t a very expensive operation. I assume the plane is identified by the normal N and the distance D from the origin. To find the distance along the direction v from P to the plane (s in the following formula) you can use the following:

t = - (dot(N,P) + D) / dot(N,v)
s = t * length(v)

I don’t know if it’s possible to reduce the number of operations in some way.

EDIT: You haven’t to divide for the length but multiply by it.

[Edited by - apatriarca on June 11, 2008 6:09:44 PM]

Share this post


Link to post
Share on other sites
I guess it isn't very expensive : )! By the time I find a work around it'll more than likely have more work to it than that.

Thanks for the tip-off!

Share this post


Link to post
Share on other sites
Find the length of the projection of the unit vector, and scale accordingly (hint: similar triangles).


//
// Check a unit vector first
//


O
/|
1 / |
/ | determine this as per the "regular distance to plane
/ |
_________|/____|_____________________________ < Plane


O
/|
1 / | O <-- point
/ | A /|
/ | B/ | C
_________|/____|_____|/__|___________________ < Plane


1/A = B/C, therefore B (which is what you're looking for) = C/A.



You don't actually need to normalize the "reference" vector ahead of time, if it isn't already; you can factor its length into the calculation at the end instead. Of course you find that length simply by Pythagoras :)

Also, try the Math&Physics forum for this kind of stuff in general.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Find the length of the projection of the unit vector, and scale accordingly (hint: similar triangles).

*** Source Snippet Removed ***

You don't actually need to normalize the "reference" vector ahead of time, if it isn't already; you can factor its length into the calculation at the end instead. Of course you find that length simply by Pythagoras :)

Also, try the Math&Physics forum for this kind of stuff in general.


Doesn’t it produce practically the same code as mine?

C = dot(P,N) + D
A = dot(v,N)/length(v) // is there a faster way?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!