Skip to main content
gamedev.net
🔒 Locked

ray intersection

Started by JasonL220 5 replies 700+ views
Original Post
JasonL220
JasonL220
hi, i've been read this article and have create a simple rectangle and then done through the calcs, but my t is negative what does taht mean coz i don't quite understand, does it still mean thers a collision? heres the piece on t: After plugging t back into R(t), we finally have the point at which the ray intersects with the plane. R(t) = (x0 + xd*t, y0 + yd*t, z0 + zd*t). Be sure to check if t is not negative. If t is negative, then the line that coincides with the ray intersects with the plane but not the ray itself. thanks jason
smitty1276
smitty1276
You need to clarify your question. You didn't show any calculations or anything.
JasonL220
JasonL220
well pick 4 points that make a rectangle( actually square )
p1 = ( 5, 4, 7 )
p2 = (10, 4, 5 )
p3 = (10, 1, 5 )
p4 = ( 5, 1, 7 )

then when trough the note and put those values into the equations and got t = -1.8561

hope that clears it up
smitty1276
smitty1276
Well, no offense, but most people would rather you post your own code than requiring us to go to some other page and hunt down whatever it is you are doing. I, for example, don't have time for that.

That said, if you are getting a negative number, it means that the ray is pointing away from the plane and will never intersect it.

EDIT: Look at this...
Plane              Ray|||t=-2      -1        0         1         2         3        4           |< -  -  -  -  -  -  X-------------------------------------->||


See... negative T goes behind the source of the ray (where the X is).
JasonL220
JasonL220
thanks, i see my mistake now. just one more thing thou how do i compute the norm of a vector, i'm find the maths site desicription very confusing.
could some show me how to ge the norm of this vector:
(5, 0, -12)

thanks
Wyzfen
Wyzfen
To normalise a vector, divide by its length. (the length of a normalised vector is one)
The length is the square root of the sum of the squares ...
sqrt((x * x) + (y * y) + (z * z))
so for (5, 0, -12) the length is sqrt(5 * 5 + 0 * 0 + (-12) * (-12)) = 13

and so the normalised vector is:
(5/13 0 -12/13)

I'd advise you get a book on geometry.

Wyzfen
JasonL220
JasonL220
thank, will do

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.