Simple Math Question

Get answers to all your basic programming questions. No Ogre questions, please!
akaitora
Gnoblar
Posts: 16
Joined: Tue Jan 19, 2010 9:21 pm

Simple Math Question

Post by akaitora »

Hi guys. So yesterday, as a mental exercise, I derived a formula to determine the point at which a ray intersects a plane.
Essentially, I wanted to find the scalar t value which tells me how much I must scale a ray, assuming it would intersect the plane.

My formula goes like so

A Ray is defined by O + Dt where O is the origin vector. D is a normalized direction vector. t is a scalar.
A Plane is defined by Dot(P,N) = d where P is a point on the plane. N is the normal of the plane. d is a scalar that represents the distance from the plane to the origin.

1. (O+Dt) * N = d
2. O*N + Dt*N = d
3. Dt*N = d-O*N
4. t = (d-O*N)/(D*N)

So I made it to step 3 with no problem. However I got stuck around step 3 to 4 because while I new that normally I can divide out the left hand side to solve for some variable, I didn't know if I was allowed to do that with a dot product. After doing a few practice problems with the dot product, I found that I could indeed do that however I was wondering if there is a mathematical property for which if an operator meets, it is always allowed to divide it out. Does that make sense?

For example, lets say I have an imaginary operator like "?". ? does some operator on two scalars. Is there a property that "?" must be in order to do the following

3x ? 2 = 4

(3x ? 2)/ (3 ? 2) = 4 / ( 3 ? 2 )
x = 4 / (3 ? 2 )

I know this is probably a simple algebra lesson that I ignored way back in middle school but any enlightenment would be appreciated! Thanks!
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: Simple Math Question

Post by Daixiwen »

The only thing that matters is the type of the result of your operator. If the result of the operation (a ? b) is a scalar, you can divide by it, provided it isn't 0.
In your case Dt*N can be written t(D*N), and D*N is a scalar so you can divide by it, as long as it isn't 0. The case D*N = 0 would be when your ray and the plane are parallel, which means your problem wouldn't have any solution (if O is outside the plane) or an infinite number of solutions (if O is on the plane).
Hardware, n.: part of the computer you can kick