Example #1
0
        public void ComputeNormal()
        {
            foreach (var face in this.faces)
            {
                face.Normal = TetMeshUtil.ComputeNormal(face);
            }

            Vector3D[] vn = TetMeshUtil.ComputeNormalUniformWeight(this);
            foreach (var v in this.vertices)
            {
                v.Normal = vn[v.Index];
            }
        }
Example #2
0
        public static Vector3D ComputeNormal(TetFace face)
        {
            if (face.OnBoundary)
            {
                return(TetMeshUtil.ComputeNormal(face));
            }
            Tetrahedron selected = CheckBoundary(face);

            if (selected == null)
            {
                return(Vector3D.Zero);
            }

            Vector3D[] v = new Vector3D[3];
            for (int i = 0; i < 3; i++)
            {
                v[i] = face.Vertices[i].Pos;
            }
            Vector3D n = (v[1] - v[0]).Cross(v[0] - v[2]).Normalize();

            foreach (var vt in selected.Vertices)
            {
                bool top = true;
                foreach (var vf in face.Vertices)
                {
                    if (vt == vf)
                    {
                        top = false;
                        break;
                    }
                }
                if (top && n.Dot(vt.Pos - v[0]) > 0)
                {
                    n = -n;
                    TetVertex temp = face.Vertices[0];
                    face.Vertices[0] = face.Vertices[2];
                    face.Vertices[2] = temp;
                    break;
                }
            }

            return(n);
        }