## Ray/Plane Intersection Point

Member
Posts: 153
Joined: 2004.12
Post: #1
How can i find the point of intersection between a ray and a plane?

There was a long silence...
'I claim them all,' said the Savage at last.
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Member
Posts: 153
Joined: 2004.12
Post: #3
Let me rephrase: The current algorithm that i am using is inaccurate (or the way i implemented it is inaccurate). I assume that most of you calculate this somehow in your games. Would anybody be so kind as to post the algorithm that you use, or describe the mathematical steps that it follows.

OSC's response, although cute, is totally useless to me, but more importantly totally useless to whoever might read this thread later.

There was a long silence...
'I claim them all,' said the Savage at last.
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
My response is appropriate to the question. If you've done as much as you say, you should put some of that information in the question to avoid responses like that.

Why don't you post some code, or your current algorithm?
Member
Posts: 153
Joined: 2004.12
Post: #5
That response was appropriate to the question.

I have two points, bPoint (before the transformation) and aPoint (after the transformation) Im testing to see if my transformation is valid (doesnt collide)
I calculate the distance to the plane for both points. "if the distances are opposite in there signed values." (one is positive and one is negative or vica versa) I continue to check the exact point on the plane that the ray intersects.

Code:
```//nx = plane normal x, ny = plane normal y, nz = plane normal z //distance2 = distance from aPoint to plane //find ray direction float rdx = [aPoint x] - [bPoint x]; float rdy = [aPoint y] - [bPoint y]; float rdz = [aPoint z] - [bPoint z]; //a = N.RayDirection float a = (nx * rdx) + (ny * rdy) + (nz * rdz); //IntersectinoPoint = aPoint - RayDirection * (distanceToPlane(aPoint)/a) float ix = ([aPoint x] - rdx) * (distance2 / a); float iy = ([aPoint y] - rdy) * (distance2 / a); float iz = ([aPoint z] - rdz) * (distance2 / a);```

There was a long silence...
'I claim them all,' said the Savage at last.
Nibbie
Posts: 2
Joined: 2006.10
Post: #6
I'm sure that I'll later regret this, but here goes.

Let r(t) = p + v*t be the equation of your ray. Let n be the plane normal and q be a point on the plane. Then any point x on the plane satisfies the equation

n . (q - x) = 0.

So substitute the ray equation r(t) in for x and solve for t:

n . (q - r(t)) = 0
n . (q - p - v*t) = 0
n . (q - p) = (n . v) * t
t = [ n . (q - p) ] / (n . v)

Then plug t back into the ray equation to find your point of intersection.
Member
Posts: 153
Joined: 2004.12
Post: #7
So for clarification in pseudo code:

T = [planeNormal.(pointOnPlane - rayOrigin)]/planeNormal.rayDirection;
pointInPlane = rayOrigin + (rayDirection * T);

Edit: Well that seems to be working, thanks a lot for the helpful response.

There was a long silence...
'I claim them all,' said the Savage at last.