Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Normal direction of faceNormals

Subject: Normal direction of faceNormals

From: Thomas Clark

Date: 22 Apr, 2010 12:49:08

Message: 1 of 8

Hi,

Just wondering if there is anyone out there with specific knowledge of the TriRep faceNormals class, as I have a couple of questions.

I'm using a triangulated surface, and looking to find the direction of the normals. However, it's important that the normals are in a consistent direction, i.e. all pointing outward or inward.

So:
1. Are the normal directions consistent across adjacent simplices?
2. How does faceNormals determine which direction they're in (inward or outward)?
3. Are they still consistent in cases where the surface is not a closed hull?

Thanks for any insight!

Tom Clark

Subject: Normal direction of faceNormals

From: Roger Stafford

Date: 22 Apr, 2010 17:39:23

Message: 2 of 8

"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <hqpgk4$l4v$1@fred.mathworks.com>...
> Hi,
>
> Just wondering if there is anyone out there with specific knowledge of the TriRep faceNormals class, as I have a couple of questions.
>
> I'm using a triangulated surface, and looking to find the direction of the normals. However, it's important that the normals are in a consistent direction, i.e. all pointing outward or inward.
>
> So:
> 1. Are the normal directions consistent across adjacent simplices?
> 2. How does faceNormals determine which direction they're in (inward or outward)?
> 3. Are they still consistent in cases where the surface is not a closed hull?
>
> Thanks for any insight!
>
> Tom Clark

  That is a good question, Tom. I would like to know the answer to that too. I would hazard the guess that there is a consistent orientation to the triangles' vertices produced by all the triangulation functions, delaunayTri, etc. Any two triangles sharing an edge should trace through that edge in opposite directions as determined by the vertex sequence given in the computed triangulation. If that is done, then it is easy to produce the consistency you are asking about.

  Unfortunately I cannot find any definite statement to that effect in Mathworks' documentation. The closest they appear to come is to show a plot in the TriRep.faceNormals section of their manual with all the normal "quivers" pointing outward from a sphere.

  I think this calls for a comment by someone in MathWorks.

Roger Stafford

Subject: Normal direction of faceNormals

From: Roger Stafford

Date: 22 Apr, 2010 18:58:19

Message: 3 of 8

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqq1kb$fv3$1@fred.mathworks.com>...
> "Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <hqpgk4$l4v$1@fred.mathworks.com>...
> > Hi,
> >
> > Just wondering if there is anyone out there with specific knowledge of the TriRep faceNormals class, as I have a couple of questions.
> >
> > I'm using a triangulated surface, and looking to find the direction of the normals. However, it's important that the normals are in a consistent direction, i.e. all pointing outward or inward.
> >
> > So:
> > 1. Are the normal directions consistent across adjacent simplices?
> > 2. How does faceNormals determine which direction they're in (inward or outward)?
> > 3. Are they still consistent in cases where the surface is not a closed hull?
> >
> > Thanks for any insight!
> >
> > Tom Clark
>
> That is a good question, Tom. I would like to know the answer to that too. I would hazard the guess that there is a consistent orientation to the triangles' vertices produced by all the triangulation functions, delaunayTri, etc. Any two triangles sharing an edge should trace through that edge in opposite directions as determined by the vertex sequence given in the computed triangulation. If that is done, then it is easy to produce the consistency you are asking about.
>
> Unfortunately I cannot find any definite statement to that effect in Mathworks' documentation. The closest they appear to come is to show a plot in the TriRep.faceNormals section of their manual with all the normal "quivers" pointing outward from a sphere.
>
> I think this calls for a comment by someone in MathWorks.
>
> Roger Stafford

  Come to think of it, I wonder how delaunayTri would handle a mobius strip which has only one side and one edge. Perhaps that is the reason edge constraints can be used with delaunayTri only for 2D cases.

Roger Stafford

Subject: Normal direction of faceNormals

From: Thomas Clark

Date: 22 Apr, 2010 22:29:07

Message: 4 of 8

Cheers, Roger. Shame there's no 2D Mobius strip!!

I thought that the direction might propagate through from the ordering of the vertices in the TRI arrays which are output by the delaunay triangulation. For example, you could say the order of the three vertices is given in the clockwise direction when facing outward - therefore defining the normal direction within the TRI matrix.

However, this isn't the case. I tried the example for faceNormals given in the MATLAB documentation (convex hull of random points on a sphere).
Result: It gives a consistently outward normal direction.
I repeated the experiment, having swapped the second and third columns of the second half of the input TRI matrix rows. I then recomputed the faceNormals. Half of the resultant normals should point inward.
2nd Result: Normal directions are still consistently outward pointing.
Conclusion: faceNormals must check and enforce consistent normal directions.

How it does this, and whether it's reliable for open or nonconvex hulls, I don't know. Any mathworkers in the building?? :)

Subject: Normal direction of faceNormals

From: Roger Stafford

Date: 22 Apr, 2010 23:22:26

Message: 5 of 8

"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <hqqijj$4l8$1@fred.mathworks.com>...
> Cheers, Roger. Shame there's no 2D Mobius strip!!
>
> I thought that the direction might propagate through from the ordering of the vertices in the TRI arrays which are output by the delaunay triangulation. For example, you could say the order of the three vertices is given in the clockwise direction when facing outward - therefore defining the normal direction within the TRI matrix.
>
> However, this isn't the case. I tried the example for faceNormals given in the MATLAB documentation (convex hull of random points on a sphere).
> Result: It gives a consistently outward normal direction.
> I repeated the experiment, having swapped the second and third columns of the second half of the input TRI matrix rows. I then recomputed the faceNormals. Half of the resultant normals should point inward.
> 2nd Result: Normal directions are still consistently outward pointing.
> Conclusion: faceNormals must check and enforce consistent normal directions.
>
> How it does this, and whether it's reliable for open or nonconvex hulls, I don't know. Any mathworkers in the building?? :)
-------------------------
  If one could manufacture a valid triangulation for a Klein bottle, it would be interesting to see what 'facenormal' would do with it. It shouldn't be too awfully hard to rig one up. 'facenormal' is bound to fail since both directions for the normal point "outside" - there is no "inside".
  
Roger Stafford

Subject: Normal direction of faceNormals

From: Roger Stafford

Date: 23 Apr, 2010 04:01:36

Message: 6 of 8

"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <hqqijj$4l8$1@fred.mathworks.com>...
> ........
> Conclusion: faceNormals must check and enforce consistent normal directions.
>
> How it does this, and whether it's reliable for open or nonconvex hulls, I don't know. Any mathworkers in the building?? :)
-----------
  There is one way for "normal" (that is, klein bottle-like inter-surface crossing not allowed) closed, connected surfaces that have been triangulated to produce the result you observed with 'faceNormal', Thomas. It could first proceed to switch individual triangle orientations so as to ensure that, as I said earlier, each edge has opposite directions in the two triangles sharing that edge. Then if the sign of the total volume enclosed by the surface - a simple calculation based on each triangle's orientation - turns out to be negative, all triangle orientations could be reversed so as to all possess the correct outside orientation.

Roger Stafford

Subject: Normal direction of faceNormals

From: Steven Lord

Date: 23 Apr, 2010 19:29:11

Message: 7 of 8


"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message
news:hqqijj$4l8$1@fred.mathworks.com...
> Cheers, Roger. Shame there's no 2D Mobius strip!!
>
> I thought that the direction might propagate through from the ordering of
> the vertices in the TRI arrays which are output by the delaunay
> triangulation. For example, you could say the order of the three vertices
> is given in the clockwise direction when facing outward - therefore
> defining the normal direction within the TRI matrix.
> However, this isn't the case. I tried the example for faceNormals given
> in the MATLAB documentation (convex hull of random points on a sphere).
> Result: It gives a consistently outward normal direction. I repeated the
> experiment, having swapped the second and third columns of the second half
> of the input TRI matrix rows. I then recomputed the faceNormals. Half of
> the resultant normals should point inward.
> 2nd Result: Normal directions are still consistently outward pointing.
> Conclusion: faceNormals must check and enforce consistent normal
> directions.
>
> How it does this, and whether it's reliable for open or nonconvex hulls, I
> don't know. Any mathworkers in the building?? :)

I asked one of the developers about this, and here is what he said:


Did you remember to recreate the TriRep when you flipped the orientations of
half the TRI matrix?

The face normal are defined by the sequence of vertices that define each
triangle.

The face normals respect the Right Hand Rule; counterclockwise orientation
around the face produces an "outward" normal.

MATLAB does not modify the triangulation you provide to TriRep; you can
think of TriRep as a Query object it's read-only and it does not change your
data.



I will file an enhancement request to clarify the documentation.



% Run the faceNormals example



% Now flip some normals



col2 = tri(100:end, 2);

col3 = tri(100:end, 3);

tri(100:end, 2) = col3;

tri(100:end, 3) = col2;



% Recreate the TriRep and plot in a new figure

tr = TriRep(tri, Xb);

P = incenters(tr);

fn = faceNormals(tr);

figure

trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3),'FaceColor', 'cyan', 'faceAlpha', 0.8);

axis equal;

hold on;

quiver3(P(:,1),P(:,2),P(:,3),fn(:,1),fn(:,2),fn(:,3),0.5, 'color','r');

hold off;




--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Normal direction of faceNormals

From: Thomas Clark

Date: 23 Apr, 2010 20:20:21

Message: 8 of 8

Steven,

Great clarification, thankyou very much :)

I had atttempted to recreate the TriRep object, but clearly didn't do so correctly. I'll look back in my command history, and see whether I was being a doofus, or whether there was something in the documentation that misled me... No bets on the probability of doofusness, please ;)

Doofus or not, the example data used was constructed using delaunayTri, so the delaunayTri(blah) operation must determine the normal direction, to order the elements of the TRI matrix in the correct sense. I presume this is done by outward direction from the centroid of the convex hull?

Thanks for your help so far :)

Tom

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us