I really need a maths forum. Ray -> Plane intersection

K.I.L.E.R

Retarded moron
Veteran
I read all about it on Google and in my book.
I'm just confirming that this works(tests seem to return plausible results) but I need mathematical opinion:

I have to check P0.Normal != 0.0 or I will get the impossible (Div by 0) which is impossible and thus no intersection can take place if you divide by zero. I used common sense to work this out myself. :D

p0 = ray's initial point
ray = vector
0.0 <= alphaScaleFactor <= 1.0

-(p0.Normal / ray.Normal) = alphaScaleFactor
Intersection = p0 + alphaScaleFactor * ray

Also what is the stupid variable that randomly pops up which is known as C or D?
I read that it was the displacement of the plane from the 'origin'.
I never used the variable it.

WHAT ORIGIN?
The ray's origin or the world coordinate origin(this is what I assumed)?

Code:
public Vector3f intersects(Vector3f point, Vector3f rayDirection, Vector3f intersectionData) {
        float pointDOTnormal = 0.0f;
        float directionDOTnormal = Vector3f.dot(rayDirection, normal);
        float alphaScale = 0.0f;
        
        if(directionDOTnormal == 0.0f)
            return null;
        
        pointDOTnormal = Vector3f.dot(normal, rayDirection);
        alphaScale = -(pointDOTnormal / directionDOTnormal);
        
        intersectionData.x = point.x + alphaScale * rayDirection.x;
        intersectionData.y = point.y + alphaScale * rayDirection.y;
        intersectionData.z = point.z + alphaScale * rayDirection.z;
        
        if(pointDOTnormal > 0.0) {
            normal.x = -normal.x;
            normal.y = -normal.y;
            normal.z = -normal.z;    
        }
        
        return intersectionData;
    }
 
Also what is the stupid variable that randomly pops up which is known as C or D?
I read that it was the displacement of the plane from the 'origin'.
I never used the variable it.

WHAT ORIGIN?
The ray's origin or the world coordinate origin(this is what I assumed)?
The world coordinate origin. The idea is that you can think of any point as a vector from the world origin. So if you take the dot product of this vector with the normal to the plane, you get a length of projection of that vector onto the direction of the normal.

if <x,y,z> is the normal, and <a, b, c> is a point, then the dot product between them is --
ax+by+cz = d;

The thing is that if you use the ray origin as well, this will be some other distance from the world origin along the direction of the normal. Your function is missing a little something -- you need both a point that lies on the plane as well as the origin of the ray.

normal . pointOnPlane = d
normal . rayOrigin = d'

These two distances are likely not to be equal, so it's the difference between these that determines how far the ray needs to go.

(d' - d) / (rayDirection . normal) = t
rayOrigin + t * rayDirection = intersectionPoint;

If you omit the "d' - d" part, and just use d' (which was normal . rayOrigin), the intersection point you'll get is the same as if the world origin was a point on the plane.

Code:
        float pointDOTnormal = 0.0f;
        float directionDOTnormal = Vector3f.dot(rayDirection, normal);
        float alphaScale = 0.0f;
        
        if(directionDOTnormal == 0.0f)
            return null;
        
        pointDOTnormal = Vector3f.dot(normal, rayDirection);
        alphaScale = -(pointDOTnormal / directionDOTnormal);
I don't see how this can give you plausible results. directionDOTnormal and pointDOTnormal are the same value. alphaScale will always be -1.
 
Update:
I've proven to myself the I'm the world's biggest dickhead. :LOL:

I can't understand any of this until I am able to prove it, and so that's exactly what I did.

I went through all the substitutions and the like and ended up with almost the same answer.
I am able to tell where the equation comes from and so forth.

There is one problem, I managed to get a '3' in my equation.

I had p0 + D = -AaV - BaV - CaV

So what I did was:

p0 + D / 3(aV) = -A - B - C(This is the same form as my normal)
p0 + D / 3(aV) = N
p0 + D / 3VN = a

How did that happen? :LOL:
 
Kruno,
Good luck when you move on to constraining the intersection to be with a polygon on the plane or try ray-sphere intersections :p
 
There is one problem, I managed to get a '3' in my equation.

I had p0 + D = -AaV - BaV - CaV

So what I did was:

p0 + D / 3(aV) = -A - B - C(This is the same form as my normal)
p0 + D / 3(aV) = N
p0 + D / 3VN = a

How did that happen?
I'm guessing you went through a thought process something like this --
p0 + D = -AaV - BaV - CaV
p0 + D = -A(aV) - B(aV) - C(aV)
p0 + D / aV = -A - B(aV) - C(aV)
p0 + D / 2aV = -A - B - C(aV)
p0 + D / 3aV = -A - B - C

as opposed to the correct form which is that aV can be factored out of the whole right side

p0 + D = -AaV - BaV - CaV
p0 + D = aV(-A - B - C)
(p0 + D) / aV = -A - B - C
assuming <A,B,C> is your normal vector, that would mean
(p0 + D) / aV = -N

I'm not entirely sure how you're getting down to the derivation from this as I don't know what your terms are, but where is this (p0 + D) coming from? The definition of a plane is usually p0 . N +/- d = 0, where p0 is a point anywhere on the plane and N is the normal, presumably unit length, and d is some scalar value denoting distance along the direction of N. Alternatively, there's the definition of a ray, which would be some p0 + tD, where p0 is the origin, D is the vector direction of the ray, and t is an arbitrary scalar value (ideally positive, but depending on the application, you may not care...). In a ray-plane intersection, given that

P . N = some specific value d, for all points in the plane,
and p0 + tD defines all the points on the ray,

you're wanting to solve for t such that

(p0 + tD) . N = the same value of d

the dot product is distributive, so
p0 . N + tD . N = d
t(D . N) = d - (p0 . N)
t = (d - (p0 . N)) / (D . N)

Pretty simple.
 
Back
Top