示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }