Sign in to follow this  

Collision Detection Problems

Recommended Posts

ok, I've been tryign really hard to firgure this junk out but it feels like I just keep runnign at a brick wall at full speed, so here I am askign for help...outside the chatroom. Alright, this is the basics of it that im not getting: Say I have a line that goes from (6, 5, 7) to (3, 1, 2), its components being (3, 4, 5), the line is roughly 7 units long. How do I represent this line as a vector. Also if I normalize it, do I divide all the components by 7? (I should hope the answer is yes otherwise I'm worse off than I thought). How do I find a 3D angle? Any help would be great, Im understanding the ideas of teh collision detection but im so friggin lost when I try to code it. Any help would be great right about now, I've really been workin hard to understand this stuff. Thx, Matt.

Share this post

Link to post
Share on other sites
You can get the vector by subtracting the two endpoints. The order of subtraction determines the direction of the vector. Normalizing would require you to divide all the components by the length of the vector. In your example, (3,2,5) is the vector representing the line. If by find a 3D angle, you mean the angle between two vectors, you can do this in severals ways, with the cross product, or the dot product. Say you have vectors u and v, and |x| is the magnitude of a vector, where x is any vector. The magnitude of a cross product is defined as |u||v|sin(angle) = |u cross v|. Doing a little math gets you: angle = arcsin(|u cross v|/ (|u||v|)). The dot product is defined similarly as (u dot v) = |u||v|cos(angle), which turns into angle = arccos((u dot v)/(|u||v|)).

Share this post

Link to post
Share on other sites
Well, you could ask a more specific question about collision detection, if that's your problem...

But regarding the question you did ask. First, a few things. The line that goes from (6,5,7) to (3,1,2) is actually (-3,-4,-5). In general:

Vector = To - From
= (3,1,2) - (6,5,7)
= (-3,-4,-5)

And any point along that line can be represented by:

for some value 0 <= t <= 1
P = From + t(To - From)

or equivalently:

P = t*To + (1-t)*From

P = (6,5,7) + t*(-3,-4,-5)
P = t*(3,1,2) + (1-t)*(6,5,7)

They're the same thing

Any value of t not between 0 and 1 is still on the line as it goes out toward positive and negative infinity.

In the case of normalizing the vector, (as you said, dividing by roughly 7) that gives you the *direction* of the vector. It's useful in many cases, and not useful in others... it depends on your collision detection scheme.

Share this post

Link to post
Share on other sites
if you're troubled by vectors, you should really learn how to use them, from the ground up.

the vector norms, operators, 'special' operators (cross / dot product), relation with trigonometry (cos, sine, angles, ect...).

Then after that, coll det should be a lot easier to grasp.

Share this post

Link to post
Share on other sites
Alright, thx for teh help. I read everythign down to matricies on that article oliii but I did get confused at the end with planes.

The only thing I cant figure out is how you represent the angle in a 3D space between 2 vectors with only one angle and have it mean anythign to anyone. When theress a z-axis you can say the vectors are 30 degrees apart but that could be in a crazy direction. It seems like a better way would be to compare the x and y components then the x and z components so you could say "Vector A is 7 units long with angle: X 30degrees Y 60degrees Z", this would be representign a vector that goes out from the screen 60degrees and 30degrees up, I can't picture it any other way. Mabye thats because we described them differently in physics class than you do in code. Either way even though I understand vectors I think Im still looks at them the wrong way slightly, if from my mumbling anyone can figure out what Im not seeing thatd be great.

Im sure Ill be posting here again within the next 20 minutes or so about collision detection again.

Thx again, Matt

Share this post

Link to post
Share on other sites
The way you describe is the way euler angles work. To put it in a short version, euler angles are nothing more than 3 angles along the the x, y, and Z axis respectively.

For the angle between two vectors in 3D, the axis of rotation (the 'crazy' direction), is given by the cross product of both vectors, while the angle that separates then is given by the dot product. Simple as that. This is an example on how useful it it to understanding those operators.

similarly, the normal of a triangle is the cross product of two edges, which basically represent the vector perpendicular to both edges. Hence, it's the same as finding out the axis of rotation. The axis of rotation between two vectors is the axis perpendicular to both.

planes (called hyperplanes sometimes) are simple. A plane is a collection of points that are at a similar distance (let's call it D) from the origin, along a given direction (the normal of the plane). Basically, in maths forms, it means that point P is on the plane if P.Dot(Normal) = D;

Any point satisfying that equation is on the plane [N, D].

The formal equation of a plane is

ax + by + cz + d = 0;

this can be equaled to

N.x * x + N.y * y + N.z * z + (-D) = 0;

Fancy things aside, this is useful to find for example, if a point P is 'behind' or 'in front' of a plane.

if P.Dot(N) > D, then the point is 'in front'.
if P.Dot(N) < D, then the point is 'behind'.

also, to find if a ray is intersecting a plane.

a point P is on the plane of P.N = D;

but also, P is on the ray if O + t.L = P (O being the origin of the ray, and L the direction, t being the paranetric variable).

so, to find where a ray intersects a plane, we need 't' and we just have to solve a system of two linear equations

(1) P.N = D
(2) P = O + t*L

replace P in the first equation by the second equation, and you get

(O + t*L) . N = D

=> (O.N) + t * (L.N) = D
=> t = (D - O.N) / (L.N)

and there you have it. you find the parameter 't'.

to find the point of intersection, simply substitute 't' into the second equation (Pinter = O + t * L).

That's just an example of using vector maths and parametric equations.

Share this post

Link to post
Share on other sites
Sorry it took me so long to reply I was having trouble with the forums. Anyway, after reading the first 3 paragraphs about 20 times I think I understand about the whole "making your own axis" thing, making your own 2D kinda. Im still tryign to figure out about the planes, but I understand hwo to use all the equations now, I don't think I'd know how to use them in a program on the first try but I guess that just comes with practice.
Yet again I thank you for you help oliii.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this