/// <summary> /// Computes the angle defect at the given vertex. /// </summary> /// <param name="vertex">Vertex to compute angle defect.</param> /// <returns>Number representing the deviation of the current vertex from $2\PI$.</returns> public static double AngleDefect(MeshVertex vertex) { var angleSum = 0.0; foreach (var c in vertex.AdjacentCorners()) { angleSum += Angle(c); } // if (vertex.OnBoundary()) angleSum = Math.PI - angleSum; return(vertex.OnBoundary() ? Math.PI - angleSum : 2 * Math.PI - angleSum); }
/// <summary> /// Computes the sphere inscribed normal around the specified vertex. /// </summary> /// <returns>The normal vector at that vertex.</returns> /// <param name="vertex">Vertex.</param> public static Vector3d VertexNormalSphereInscribed(MeshVertex vertex) { var n = new Vector3d(); foreach (var c in vertex.AdjacentCorners()) { var u = Vector(c.HalfEdge.Prev); var v = -Vector(c.HalfEdge.Next); n += u.Cross(v) / (u.LengthSquared * v.LengthSquared); } return(n.Unit()); }
/// <summary> /// Computes the angle weighted normal around the specified vertex. /// </summary> /// <returns>The normal vector at that vertex.</returns> /// <param name="vertex">Vertex.</param> public static Vector3d VertexNormalAngleWeighted(MeshVertex vertex) { var n = new Vector3d(); foreach (var c in vertex.AdjacentCorners()) { var normal = FaceNormal(c.HalfEdge.Face); var angle = Angle(c); n += normal * angle; } return(n.Unit()); }