iDevGames Forums
Ray/Plane Intersection Point - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Ray/Plane Intersection Point (/thread-5744.html)



Ray/Plane Intersection Point - hangt5 - Mar 21, 2005 12:52 AM

How can i find the point of intersection between a ray and a plane?


Ray/Plane Intersection Point - OneSadCookie - Mar 21, 2005 01:21 AM

http://mathworld.wolfram.com/
http://google.com/


Ray/Plane Intersection Point - hangt5 - Mar 21, 2005 01:59 AM

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.


Ray/Plane Intersection Point - OneSadCookie - Mar 21, 2005 02:13 AM

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?


Ray/Plane Intersection Point - hangt5 - Mar 21, 2005 02:39 AM

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);



Ray/Plane Intersection Point - belthaczar - Mar 21, 2005 02:42 AM

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.


Ray/Plane Intersection Point - hangt5 - Mar 21, 2005 03:05 AM

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.