iDevGames Forums
Unclear explanations of maths - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Unclear explanations of maths (/thread-7924.html)



Unclear explanations of maths - mikey - Jul 29, 2010 12:52 PM

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?


RE: Unclear explanations of maths - Skorche - Jul 29, 2010 02:16 PM

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.


RE: Unclear explanations of maths - mikey - Jul 30, 2010 05:07 AM

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?


RE: Unclear explanations of maths - Skorche - Jul 30, 2010 06:10 AM

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.


RE: Unclear explanations of maths - mikey - Jul 30, 2010 06:54 AM

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?


RE: Unclear explanations of maths - Skorche - Jul 30, 2010 07:31 AM

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.

To answer your second question:
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.


RE: Unclear explanations of maths - mikey - Jul 30, 2010 07:35 AM

Ah right thanks for that, I'll try it now.
That works perfectly. Thankyou very much.


RE: Unclear explanations of maths - Applewood - Oct 9, 2010 03:36 PM

You should think about buying this book.

imo every game programmer should have it. It handles collisions for all primitive types to all primitive types along with many other things. Full source is supplied in easily useable chunks.