Cross product for triangles doubt

Started by
7 comments, last by GPxz 16 years, 6 months ago
I am in the start of implementig plane-line collision detection, and as so, the first step, I want to generate the triangle normals from my heightmap for further collision detection Use cross product between two points, ok.. But is two points enough? I think the other vertex is relevant too, as depending on the position of the last point would totally change the triangle normal vector Also i am using his pure values, already scaled and translated, like CrossProduct(tri1x, tri1y, tri1z, tri2x, tri2y, tri2z) Also, i am not using right-handed nor left-handed (Z for depth, X and Y as usual, a left handed with Z and Y swap) Should i swap Z and Y in the cross product equation? Plus should i normalize the normal for the further plane-line equation? Or should leave untouched? More questions later
My MSN: gerunbaum@hotmail.com
Advertisement
To generate a normal for a triangle ABC you generally do (A - B) X (A - C), switching order or signs depending on the winding for the triangle.
The cross-product is not suitable for position vectors but for direction vectors. If you have 3 vertex positions, e.g. { V1, V2, V3 }, then you can compute 2 direction vectors, e.g.
v12 := V2 - V1
v13 := V3 - V1
from them. Then you have to compute the cross-product with these 2 vectors.

[EDIT: As SiCrane already told.]
Thanks, you're right, i got it

I am still new for dot/cross stuff as you can see

How should i deal with Cross Product if i am using a different orientation from left and right handed? May i swap the axis in the cross equation?

[Edited by - GPxz on September 29, 2007 12:13:24 PM]
My MSN: gerunbaum@hotmail.com
The cross product should give you vectors in the same space as whatever the vectors you put in were. You shouldn't have to make any modifications to the crossproduct if you reversed the direction of an axis or swapped 2 axis.
Quote:Original post by Alrecenk
The cross product should give you vectors in the same space as whatever the vectors you put in were. You shouldn't have to make any modifications to the crossproduct if you reversed the direction of an axis or swapped 2 axis.


I think my cross product is okay then

Now for the plane equation

n.I = D

R = (D - n.p) / n.v


What is bugging me here is that he says to calcute D, use any of the plane position, but if n.I is the dot product, isn't it always going to be zero since a plane position will always be perpendicular to the plane normal?

If so, then i have

dist=-DotProduct(tri[n].normalx, tri[n].normaly, tri[n].normalz, startx, starty, startz)/DotProduct(tri[n].normalx, tri[n].normaly, tri[n].normalz, directionx, directiony, directionz)

Is it right?

I know the possible conditions

n.v=0, vector parallel to plane
dist<0, plane behind

But there is a condition that line doesnt intersect with plane (and is not parallel) ?

[Edited by - GPxz on September 29, 2007 3:11:38 PM]
My MSN: gerunbaum@hotmail.com
Nobody?

I guess i am going to discover by my own
My MSN: gerunbaum@hotmail.com
You got the answer in the first 2 posts, nearly.

If a, b and c are the triangle points then calculate

n = (a-b)X(a-c)

but they forgot to say you need to normalise n after doing the cross product.

All triangles must be wound the same (i.e. all points either clockwise or anticlockwise, you can't mix the winding).

If the normal points the wrong way just negate it.

EDIT: You moved onto the plane equation I notice.

n.I isn't zero unless the plane passes through the origin. It is the signed distance from the origin of the plane, assuming I is normalised.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Quote:Original post by Paradigm Shifter
You got the answer in the first 2 posts, nearly.

If a, b and c are the triangle points then calculate

n = (a-b)X(a-c)

but they forgot to say you need to normalise n after doing the cross product.

All triangles must be wound the same (i.e. all points either clockwise or anticlockwise, you can't mix the winding).

If the normal points the wrong way just negate it.

EDIT: You moved onto the plane equation I notice.

n.I isn't zero unless the plane passes through the origin. It is the signed distance from the origin of the plane, assuming I is normalised.


I think i got it working now

Forget about the "others" condition

I had forgotten that a infinite plane and a infite line will always touch each other unless they are parallel

Now to the triangle-point test
My MSN: gerunbaum@hotmail.com

This topic is closed to new replies.

Advertisement