# Cross product for triangles doubt

This topic is 4090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by AlrecenkThe 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]

##### Share on other sites
Nobody?

I guess i am going to discover by my own

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by Paradigm ShifterYou got the answer in the first 2 posts, nearly.If a, b and c are the triangle points then calculaten = (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

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

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013221
×