public DCELHalfEdge2D(DCELVertex2D origin, DCELFace2D face, DCELHalfEdge2D twin, DCELHalfEdge2D 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() { DCELHalfEdge2D he = this.Edge; DCELHalfEdge2D prev = he.Previous(); DCELVertex2D first = he.Origin; do { Vector v1 = new Vector( prev.Origin.Coordinates.X - he.Origin.Coordinates.X, prev.Origin.Coordinates.Y - he.Origin.Coordinates.Y); Vector v2 = new Vector( he.Next.Origin.Coordinates.X - he.Origin.Coordinates.X, he.Next.Origin.Coordinates.Y - he.Origin.Coordinates.Y); double dotProduct = (v1.X * v2.X + v1.Y * v2.Y); double norm1 = Math.Sqrt(Math.Pow(v1.X, 2) + Math.Pow(v1.Y, 2)); double norm2 = Math.Sqrt(Math.Pow(v2.X, 2) + Math.Pow(v2.Y, 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(DCELHalfEdge2D edge) { edgeList.Add(edge); edgeCount++; return(true); }
public bool RemoveHalfEdge(DCELHalfEdge2D edge) { if (edgeList.Remove(edge)) { edgeCount--; return(true); } return(false); }
/// <summary> /// Restituisce l'HalfEdge precedente. /// </summary> /// <returns>DCELHalfEdge.</returns> public DCELHalfEdge2D Previous() { DCELHalfEdge2D 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 <DCELHalfEdge2D> Sides() { DCELHalfEdge2D he = this.Edge; DCELVertex2D 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 <DCELFace2D> Neighbours() { DCELHalfEdge2D he = this.Edge; DCELVertex2D first = he.Origin; do { if (he.Twin != null) { 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 <DCELHalfEdge2D> LeavingEdges() { if (this.Leaving == null) { yield break; } DCELHalfEdge2D he = this.Leaving; do { yield return(he); he = he.Previous().Twin; if (he == null) { yield break; } }while (he != this.Leaving); }
public DCELVertex2D(Point coordinates, DCELHalfEdge2D leaving) { Coordinates = coordinates; Leaving = leaving; }
public DCELVertex2D(double x, double y, DCELHalfEdge2D leaving) { Coordinates = new Point(x, y); 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 DCELFace2D(DCELHalfEdge2D edge) : this() { this.edge = edge; }
public bool Contains(DCELHalfEdge2D edge) { return(edgeList.Contains(edge)); }