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

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

## 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 on other sites
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 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.

ok thank you

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009398
• ### Who's Online (See full list)

There are no registered users currently online

×