From: Thomas Clark on
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
From: Steven Lord on

"Thomas Clark" <t.clark(a)remove.spamcantab.net> wrote in message
news:hqqijj$4l8$1(a)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(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Roger Stafford on
"Thomas Clark" <t.clark(a)remove.spamcantab.net> wrote in message <hqqijj$4l8$1(a)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