public DCELHalfEdge(DCELVertex origin, DCELFace face, DCELHalfEdge twin, DCELHalfEdge next) { Origin = origin; Face = face; Twin = twin; Next = next; }
/// <summary> /// Verifica se la faccia è convessa. Un poligono semplice è strettamente convesso se ogni /// angolo interno è strettamente inferiore a 180 gradi. /// </summary> /// <returns>True se la faccia è convessa, false altrimenti.</returns> public bool IsConvex() { DCELHalfEdge he = this.Edge; DCELHalfEdge prev = he.Previous(); DCELVertex first = he.Origin; do { Vector3D v1 = new Vector3D( prev.Origin.Coordinates.X - he.Origin.Coordinates.X, prev.Origin.Coordinates.Y - he.Origin.Coordinates.Y, prev.Origin.Coordinates.Z - he.Origin.Coordinates.Z); Vector3D v2 = new Vector3D( he.Next.Origin.Coordinates.X - he.Origin.Coordinates.X, he.Next.Origin.Coordinates.Y - he.Origin.Coordinates.Y, he.Next.Origin.Coordinates.Z - he.Origin.Coordinates.Z); double dotProduct = (v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z); double norm1 = Math.Sqrt(Math.Pow(v1.X, 2) + Math.Pow(v1.Y, 2) + Math.Pow(v1.Z, 2)); double norm2 = Math.Sqrt(Math.Pow(v2.X, 2) + Math.Pow(v2.Y, 2) + Math.Pow(v2.Z, 2)); double angle = (Math.Acos(dotProduct / (norm1 * norm2)) * 180) / Math.PI; if (angle > 180) { return(false); } prev = he; he = he.Next; }while (he.Origin != first); //returns true if every internal angle is less than or equal to 180 degrees return(true); }
public bool AddHalfEdge(DCELHalfEdge edge) { edgeList.Add(edge); edgeCount++; return(true); }
public bool RemoveHalfEdge(DCELHalfEdge edge) { if (edgeList.Remove(edge)) { edgeCount--; return(true); } return(false); }
/// <summary> /// Restituisce l'HalfEdge precedente. /// </summary> /// <returns>DCELHalfEdge.</returns> public DCELHalfEdge Previous() { DCELHalfEdge he = this; do { he = he.Next; }while (he.Next.Origin != this.Origin); return(he); }
/// <summary> /// Restituisce i lati della faccia. /// </summary> /// <returns>DCELHalfEdge collection.</returns> public IEnumerable <DCELHalfEdge> Sides() { DCELHalfEdge he = this.Edge; DCELVertex first = he.Origin; do { yield return(he); he = he.Next; }while (he.Origin != first); }
/// <summary> /// Restituisce tutte le facce confinanti. /// </summary> /// <returns>DCELFace collection.</returns> public IEnumerable <DCELFace> Neighbours() { DCELHalfEdge he = this.Edge; DCELVertex first = he.Origin; do { if (!he.Twin.Face.IsInfinite()) { yield return(he.Twin.Face); } he = he.Next; }while (he.Origin != first); }
/// <summary> /// Restituisce tutti gli HalfEdge che partono da questo vertice. /// </summary> /// <returns>DCELHalfEdge collection.</returns> public IEnumerable <DCELHalfEdge> LeavingEdges() { if (this.Leaving == null) { yield break; } DCELHalfEdge he = this.Leaving; do { yield return(he); he = he.Previous().Twin; }while (he != this.Leaving); }
/// <summary> /// /// </summary> /// <param name="mesh"></param> /// <returns></returns> public static MeshGeometry3D GetMeshGeometry(DCELMesh mesh) { MeshGeometry3D mesh3d = new MeshGeometry3D(); Hashtable vIndexes = new Hashtable(); int n = 0; mesh.Triangulate(); foreach (var point3d in mesh.VertexList) { mesh3d.Positions.Add(point3d.Coordinates); mesh3d.Normals.Add(point3d.Normal); vIndexes.Add(point3d, n++); } foreach (var face in mesh.FaceList) { DCELHalfEdge he = face.Edge; DCELVertex first = he.Origin; do { mesh3d.TriangleIndices.Add((int)vIndexes[he.Origin]); he = he.Next; }while (he.Origin != first); } /* * foreach (var face in mesh.FaceList) * { * DCELHalfEdge he = face.Edge; * DCELVertex first = he.Origin; * * do * { * mesh3d.Positions.Add(he.Origin.Coordinates); * mesh3d.Normals.Add(he.Origin.Normal); * mesh3d.TriangleIndices.Add(n++); * he = he.Next; * } * while (he.Origin != first); * } */ return(mesh3d); }
public DCELVertex(Point3D coordinates, DCELHalfEdge leaving, Vector3D normal) { Coordinates = coordinates; Leaving = leaving; Normal = normal; }
public DCELVertex(Point3D coordinates, DCELHalfEdge leaving) { Coordinates = coordinates; Leaving = leaving; }
public DCELVertex(double x, double y, double z, DCELHalfEdge leaving, Vector3D normal) { Coordinates = new Point3D(x, y, z); Leaving = leaving; Normal = normal; }
public DCELVertex(double x, double y, double z, DCELHalfEdge leaving) { Coordinates = new Point3D(x, y, z); Leaving = leaving; }
/// <summary> /// Crea una nuova istanza di DCELFace non infinita. /// </summary> /// <param name="edge">Un singolo HalfEdge che ha questa faccia come sua faccia.</param> /// <param name="normal">La normale della faccia.</param> public DCELFace(DCELHalfEdge edge, Vector3D normal) : this() { this.edge = edge; this.normal = normal; }
public bool Contains(DCELHalfEdge edge) { return(edgeList.Contains(edge)); }