concave / convex test

This commit is contained in:
James E McClure
2018-09-12 21:00:34 -04:00
parent 927e8d9d67
commit 5b4f724979

View File

@@ -360,12 +360,25 @@ Point DECL::TriNormal(int edge)
double DECL::EdgeAngle(int edge)
{
double angle;
Point U,V; // triangle normal vectors
point P,Q,R; // triangle corners
Point U,V,W; // triangle normal vectors
U = TriNormal(edge);
V = TriNormal(halfedge.twin(edge));
double dotprod=U.x*V.x + U.y*V.y + U.z*V.z;
if (dotprod > 1.f) dotprod=1.f;
angle = acos(dotprod);
// triangle corners
P=halfedge.v1(edge);
Q=halfedge.v2(edge);
R=halfedge.v2(halfedge.next(edge));
// determine if angle is concave or convex based on edge normal
W = 0.5*(P+Q)-R; // vector that lies in plane of triangle
double hypotenuse = sqrt(W.x*V.x+W.y*V.y+W.z*V.z); // hypotenuse of right triangle
double length = sqrt((W.x+V.x)*(W.x+V.x) + (W.y+V.y)*(W.y+V.y) + (W.z+V.z)*(W.z+V.z));
if (length > hypotenuse){
// concave
angle = -angle;
}
if (!(edge<0)) angle *= 0.5; // half edge value
//1.570796326794897
//printf(" %f, %f: U={%f, %f, %f}, V={%f, %f, %f}\n",angle,dotprod,U.y,U.z,V.x,V.y,V.z);