## Unclear explanations of maths

Member
Posts: 281
Joined: 2009.04
Post: #1
I was looking for a ray-plane intersection function for my game, when I ran into this website:

http://www.tar.hu/gamealgorithms/ch22lev1sec2.html

That looks good at first, clear page, illustrations, but there are a few unclear points:

1. What's D?
2. What's T? It's obviously a result, but how do I know when it is or isn't intersecting?

My maths is basic but I'm familiar with vectors. I also don't understand when it states:
Quote:analyze the ray in its parametric form:

X = org.x + dir.x*t
Y = org.y + dir.y*t
Z = org.z + dir.z*t

What does this mean? What's X, Y and Z?

I'm finding this happening in a lot of sites, not just this one.

Can anyone help me? Are there any introductions to collisions or geometry used in these pages?

~ Bring a Pen ~
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
The usual equation for a parabola looks something like y = -x^2. If that was a projectile following a parabolic path, you could find the height (y) of the bullet if you knew the position (x). If you wanted to find out where the bullet was 3 seconds after firing, you would be out of luck.

The easiest way to think of parametric equations is to treat 't' like time. Taking the equation above, let's say that the bullet is traveling at 3 units/second. So you could express x like so:
x = 3*t
Now you how far the bullet has went when given the time (t). Putting the two equations together you have this:
x = 3*t
y = -x^2
Which is equivalent to the parametric form if you solve y in terms of t:
x = 3*t
y = -9*t^2

Parametric equations are just another tool to simplify the math. The ray/plane collision code uses it because it's very easy to solve for t when the ray is expressed as a parametric form. Once you solve for the t, it's very easy to find the x, y, and z of the collision.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Member
Posts: 281
Joined: 2009.04
Post: #3
X = org.x + dir.x*t
Y = org.y + dir.y*t
Z = org.z + dir.z*t

So in this case, t is the ray's length: as t increases the ray gets longer? Each 't' is checked against the plane?

~ Bring a Pen ~
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
Basically yes. At t=0 you will just get the origin point, and at t = infinity you will have a point that is infinitely far away in the direction of the ray.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Member
Posts: 281
Joined: 2009.04
Post: #5
Alright, I see. But what's D?

And if we solve the equation to find 't', if it's less than 0 the plane is going in the opposite direction, and if it's less than the length of the ray its a hit?

~ Bring a Pen ~
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Ah. Sorry, I missed that question.

D is the distance of the plane from the origin (0,0,0) in direction of the plane's normal:
D = (any point on the plane) • (the plane's normal)
Where '•' is the dot product.

Lines are infinite in both directions so t can be anywhere in the range [-infinity, infinity].
Rays are infinite in only one direction so t must be in the range [0, infinity].
Line segments are generally defined so that they cover the range [0, 1] by defining them as Segment(t) = p0 + (p1 - p0)*t

So after solving for t, just check that it falls in the correct range. It sounds like you are really after line segment collisions. Though as you can see, the math is pretty much identical.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Member
Posts: 281
Joined: 2009.04
Post: #7
Ah right thanks for that, I'll try it now.
That works perfectly. Thankyou very much.

~ Bring a Pen ~
Member
Posts: 54
Joined: 2010.10
Post: #8