getting negative triangle normals
Started by broli86, Apr 18 2008 10:15 AM
11 replies to this topic
#1
Posted 18 April 2008 - 10:15 AM
hi, I'm trying to find out the normals for the triangles using cross product of two edges.The file from which I read the mesh had a triangle description as 3 indices into vertex list. For eg:
12 0 1
which means that 12th vertex, 0th vertex and 1st vertex form a triangle.
For normal I take the cross product of edge going from 12 to 0 and 0 to 1.
But anyway, I get negative normals for quite a few cases:
-0.246465 -0.416690 -0.875000
-0.390244 -0.390244 -0.833918
-0.510414 -0.360592 -0.780673
-0.606829 -0.330904 -0.722677
IS this considered to be wrong ?
12 0 1
which means that 12th vertex, 0th vertex and 1st vertex form a triangle.
For normal I take the cross product of edge going from 12 to 0 and 0 to 1.
But anyway, I get negative normals for quite a few cases:
-0.246465 -0.416690 -0.875000
-0.390244 -0.390244 -0.833918
-0.510414 -0.360592 -0.780673
-0.606829 -0.330904 -0.722677
IS this considered to be wrong ?
#2
Posted 18 April 2008 - 10:37 AM
If you reverse the order of your vertex indices the normal will point in the opposite direction. So the order matters. Where are you getting your indices from? Do you know if they are ordered or not wrt what is inside and outside?
#3
Posted 18 April 2008 - 11:50 AM
In case the ordering of triangles in your source data is not consistent, you can establish an order from just the points in the following way :
Pick the three vertices of the triangle (A, B ,C) and build a 2x2 matrix, that looks like this :
The sign of the determinant of the matrix det(M), indicates the orientation of the triangle. If you make sure that the sign of the determinants of all triangles is the same, you end up with triangles that all have the same winding order.
Pick the three vertices of the triangle (A, B ,C) and build a 2x2 matrix, that looks like this :
M =
{
{ B.x - A.x, C.x - A.x },
{ B.y - A.y, C.y - A.y }
}
The sign of the determinant of the matrix det(M), indicates the orientation of the triangle. If you make sure that the sign of the determinants of all triangles is the same, you end up with triangles that all have the same winding order.
If Prolog is the answer, what is the question ?
#4
Posted 18 April 2008 - 12:03 PM
anubis said:
The sign of the determinant of the matrix det(M), indicates a direction the triangle is pointing in. If you make sure that the sign for all triangles is the same, you end up with triangles that all have the same winding order.
Might be wrong here, but wouldn't that work only for convex objects? Seems to me it is impossible to determine if a triangle should be flipped or not without considering its connection to other triangles.
#5
Posted 18 April 2008 - 12:15 PM
The winding order of a triangle can be established from the points alone. Hence you can make sure that all triangles have the same winding order.
http://en.wikipedia....on_(mathematics)
http://en.wikipedia....on_(mathematics)
If Prolog is the answer, what is the question ?
#6
Posted 18 April 2008 - 12:16 PM
Or am I misunderstanding what you are saying ?
If Prolog is the answer, what is the question ?
#7
Posted 18 April 2008 - 02:14 PM
anubis said:
In case the ordering of triangles in your source data is not consistent, you can establish an order from just the points in the following way :
Pick the three vertices of the triangle (A, B ,C) and build a 2x2 matrix, that looks like this :
The sign of the determinant of the matrix det(M), indicates the orientation of the triangle. If you make sure that the sign of the determinants of all triangles is the same, you end up with triangles that all have the same winding order.
Pick the three vertices of the triangle (A, B ,C) and build a 2x2 matrix, that looks like this :
M =
{
{ B.x - A.x, C.x - A.x },
{ B.y - A.y, C.y - A.y }
}
The sign of the determinant of the matrix det(M), indicates the orientation of the triangle. If you make sure that the sign of the determinants of all triangles is the same, you end up with triangles that all have the same winding order.
i have a z coordinate too. should it be 3 X 2 matrix ?
M =
{
{ B.x - A.x, C.x - A.x },
{ B.y - A.y, C.y - A.y },
{ B.z - A.z, C.z - A.z }
}
#8
Posted 18 April 2008 - 03:13 PM
I'm sorry... My fault.. I was thinking about a triangle on a piece of paper. Of course you need to extend it to three dimensions.
Also z80 was right. You need at least on point that's inside the object, from the triangles point of view, which could be the center of the object for a convex object, though that will not suffice for concave objects. If you have such a point P you can determine on which side of the triangle the point is by finding the determinant det(M) with
The point P should be on the same side for all triangles, which again means, that all the signs of the determinants should be the same.
I'm sorry for misleading you before.
Also z80 was right. You need at least on point that's inside the object, from the triangles point of view, which could be the center of the object for a convex object, though that will not suffice for concave objects. If you have such a point P you can determine on which side of the triangle the point is by finding the determinant det(M) with
M =
{
{A.x, A.y, A.z, 1},
{B.x, B.y, B.z, 1},
{C.x, C.y, C.z, 1},
{P.x, P.y, P.z, 1},
}
The point P should be on the same side for all triangles, which again means, that all the signs of the determinants should be the same.
I'm sorry for misleading you before.
If Prolog is the answer, what is the question ?
#9
Posted 18 April 2008 - 04:10 PM
You probably have to define "wrong".. What are you gonna use your normals for? Do you expect them to point outwards wrt your surface? In this case its perfectly correct to have normals made up of negative numbers if your surface happens to be oriented that way.
#10
Posted 18 April 2008 - 04:30 PM
anubis said:
I'm sorry... My fault.. I was thinking about a triangle on a piece of paper. Of course you need to extend it to three dimensions.
Also z80 was right. You need at least on point that's inside the object, from the triangles point of view, which could be the center of the object for a convex object, though that will not suffice for concave objects. If you have such a point P you can determine on which side of the triangle the point is by finding the determinant det(M) with
The point P should be on the same side for all triangles, which again means, that all the signs of the determinants should be the same.
I'm sorry for misleading you before.
Also z80 was right. You need at least on point that's inside the object, from the triangles point of view, which could be the center of the object for a convex object, though that will not suffice for concave objects. If you have such a point P you can determine on which side of the triangle the point is by finding the determinant det(M) with
M =
{
{A.x, A.y, A.z, 1},
{B.x, B.y, B.z, 1},
{C.x, C.y, C.z, 1},
{P.x, P.y, P.z, 1},
}
The point P should be on the same side for all triangles, which again means, that all the signs of the determinants should be the same.
I'm sorry for misleading you before.
Can I use the center of a bounding sphere ? Btw the object that I am using is also a sphere converted to a triangular mesh.
#11
Posted 18 April 2008 - 04:32 PM
z80 said:
You probably have to define "wrong".. What are you gonna use your normals for? Do you expect them to point outwards wrt your surface? In this case its perfectly correct to have normals made up of negative numbers if your surface happens to be oriented that way.
Yes, outwards.
Isn't that how it is anyway ?
I'm using it for culling a few points which lie on backside of a surface.
For that you need to dot(direction vector, normal at the point). If its negative, then the point is not visible. But my problem is what decides what is "negative" and what is "positive" ? I think it is similar to problem with normals i am having.
#12
Posted 19 April 2008 - 07:39 PM
Quote
Can I use the center of a bounding sphere ? Btw the object that I am using is also a sphere converted to a triangular mesh.
With a convex object you can pick any point that is inside the object... so yes.
If Prolog is the answer, what is the question ?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












