@@ -116,22 +116,23 @@ static double computeEdgeEdgeCosAngleInTri(Mesh* m, MeshEntity* tri,
116116 return t1*t2;
117117}
118118
119- static Vector3 computeFaceNormalAtEdge (Mesh* m, /* MeshEntity* tet,*/
119+ Vector3 computeFaceNormalAtEdgeInTet (Mesh* m, MeshEntity* tet,
120120 MeshEntity* face, MeshEntity* edge, Matrix3x3 Q)
121121{
122+ PCU_ALWAYS_ASSERT (m->getType (tet) == Mesh::TET);
122123 PCU_ALWAYS_ASSERT (m->getType (face) == Mesh::TRIANGLE);
123124 PCU_ALWAYS_ASSERT (m->getType (edge) == Mesh::EDGE);
124125
125- MeshEntity* fe[ 3 ];
126- m->getDownward (face , 1 , fe );
126+ MeshEntity* te[ 6 ];
127+ m->getDownward (tet , 1 , te );
127128 int index = -1 ;
128- for (int i = 0 ; i < 3 ; i++)
129- if (fe [i] == edge) {
129+ for (int i = 0 ; i < 6 ; i++)
130+ if (te [i] == edge) {
130131 index = i;
131132 break ;
132133 }
133- PCU_ALWAYS_ASSERT (index > -1 && index < 3 );
134- Vector3 xi; // corresponding parametric coord in tri of the mid-edge point
134+ PCU_ALWAYS_ASSERT (index > -1 && index < 6 );
135+ Vector3 xi; // corresponding parametric coord in tet for the mid-edge point
135136 switch (index) {
136137 case 0 :
137138 xi = Vector3 (0.5 , 0.0 , 0.0 );
@@ -142,17 +143,44 @@ static Vector3 computeFaceNormalAtEdge(Mesh* m, /*MeshEntity* tet,*/
142143 case 2 :
143144 xi = Vector3 (0.0 , 0.5 , 0.0 );
144145 break ;
146+ case 3 :
147+ xi = Vector3 (0.0 , 0.0 , 0.5 );
148+ break ;
149+ case 4 :
150+ xi = Vector3 (0.5 , 0.0 , 0.5 );
151+ break ;
152+ case 5 :
153+ xi = Vector3 (0.0 , 0.5 , 0.5 );
154+ break ;
145155 default :
146156 break ;
147157 }
148- MeshElement* faceElem = createMeshElement (m, face );
158+ MeshElement* tetElem = createMeshElement (m, tet );
149159 Matrix3x3 J;
150- getJacobian (faceElem, xi, J);
151- destroyMeshElement (faceElem);
160+ getJacobian (tetElem, xi, J);
161+ destroyMeshElement (tetElem);
162+
163+ // get the two columns of Jacobian corresponding to face tangents
164+ MeshEntity* tf[4 ];
165+ m->getDownward (tet, 2 , tf);
166+ index = -1 ;
167+ for (int i = 0 ; i < 4 ; i++)
168+ if (tf[i] == face) {
169+ index = i;
170+ break ;
171+ }
172+ PCU_ALWAYS_ASSERT (index > -1 && index < 4 );
152173
153174 // transform Jacobian into Metric space
154175 J = getJacobianInMetric (J, Q);
155- return cross (J[0 ], J[1 ]).normalize ();
176+ if (index == 0 )
177+ return cross (J[0 ], J[1 ]).normalize ();
178+ else if (index == 1 )
179+ return cross (J[2 ], J[0 ]).normalize ();
180+ else if (index == 2 )
181+ return cross (J[2 ]-J[0 ], J[1 ]-J[0 ]).normalize ();
182+ else
183+ return cross (J[1 ], J[2 ]).normalize ();
156184}
157185
158186
@@ -180,8 +208,8 @@ static double computeFaceFaceCosAngleInTet(Mesh* m, MeshEntity* tet,
180208 }
181209
182210 PCU_ALWAYS_ASSERT (sharedEdge);
183- Vector3 f1n = computeFaceNormalAtEdge (m, /* tet,*/ face1, sharedEdge, Q);
184- Vector3 f2n = computeFaceNormalAtEdge (m, /* tet,*/ face2, sharedEdge, Q);
211+ Vector3 f1n = computeFaceNormalAtEdgeInTet (m, tet, face1, sharedEdge, Q);
212+ Vector3 f2n = computeFaceNormalAtEdgeInTet (m, tet, face2, sharedEdge, Q);
185213 // turn f2n so you get the inside angle
186214 f2n = Vector3 (0.0 , 0.0 , 0.0 ) - f2n;
187215 return f1n * f2n;
0 commit comments