Jump to content
  • Advertisement
Sign in to follow this  
Marianne

ray-axis intersection (anything easier than ray-plane?)

This topic is 4668 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

(my maths are very poor so excuse me for that probably obvious question - if you could just point out a website or search to do i could probably manage) lets's say i have a square plane along the X and Y axises, with Z always equal to 0. i have a ray (2 vectors) i want to know where they'll collide. i found a lot of docs on ray-plane intersection, but they all assume the plane can be rotated any way. i just use the axises. is there an easier way to do it than ray-plane collision? likle some kind of ray-axis intersection, like i can do in 2D (but can't figure out how to apply it in 3D) thanks

Share this post


Link to post
Share on other sites
Advertisement
Hi Marianne,

Ray-plane intersection is ray-plane intersection, pretty much no matter how you look at it. However, for a cardinal plane it simplifies considerably.

For the purpose of ray-plane intersection we usually represent our ray as an origin and a direction vector. You mention that you have two vectors, but didn't specify what they represent. If they already represent origin and direction, you're good. If they represent the start and end points of the 'ray', the origin is 'start' and the direction is 'end-start'. You might also choose to normalize the direction vector.

Let O be the ray origin, D be the direction, N be the plane normal, and d be the plane distance. The general equation for intersection between the two is then:

(O+tD).N = d

Now we'll solve for t:

(O.N)+(D.N)t = d
(D.N)t = d-(O.N)
t = (d-(O.N))/(D.N)

In your case, N = (0,0,1) and d = 0. Plug those in and you get:

t = -Oz/Dz

Doesn't get much easier than that! Here it is in code:

float t = -origin.z / direction.z;
Vector3 intersectionPoint = origin + t * direction;

That should do it (unless I made a mistake somewhere).

Oh, and if Dz is near zero, the ray is nearly parallel to the plane and you bail.

Share this post


Link to post
Share on other sites
2D, 3D, it's the same. use vector representations, and it should be straight forward. Well, it's probably the most basic example on applied vector maths for intersections (3D or 2D). can't get much simpler than a plane and a ray. in 2D, a plane really becomes a line, but put it in vector maths, and the equations will be exactly the same.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!