コード例 #1
0
ファイル: DCELFace2D.cs プロジェクト: LeafScar/DCEL-Project
        /// <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);
        }
コード例 #2
0
ファイル: DCELVertex2D.cs プロジェクト: LeafScar/DCEL-Project
        /// <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);
        }