Esempio n. 1
0
        public Vector2D GetCenter()
        {
            Vector2D directionalVector = end.Difference(start);
            Vector2D center            = start.Add(directionalVector.Multiply(0.5));

            return(center);
        }
Esempio n. 2
0
        public static bool SegmentsLieOnTopOfEachOther(Segment2D firstSegment, Segment2D secondSegment)
        {
            bool onTop = false;

            Vector2D[] firstSegmentsVertices   = firstSegment.GetVertices();
            Vector2D   firstSegmentsStart_A    = firstSegmentsVertices[0];
            Vector2D   firstSegmentsEnd_B      = firstSegmentsVertices[1];
            Vector2D   firstSegmentsDirection  = firstSegmentsEnd_B.Difference(firstSegmentsStart_A);
            double     firstsegmentsLength     = firstSegmentsDirection.normalize();
            Vector2D   secondSegmentsStart_C   = secondSegment.GetVertices()[0];
            Vector2D   secondSegmentsEnd_D     = secondSegment.GetVertices()[1];
            Vector2D   secondSegmentsDirection = secondSegmentsEnd_D.Difference(secondSegmentsStart_C);
            double     secondSegmentsLength    = secondSegmentsDirection.normalize();

            Vector2D vectorAC = secondSegmentsStart_C.Difference(firstSegmentsStart_A);
            Vector2D vectorAD = secondSegmentsEnd_D.Difference(firstSegmentsStart_A);

            if (VectorsAreLinearDependent(vectorAC, vectorAD))
            {
                double cos = firstSegmentsDirection.Dot(secondSegmentsDirection) / (firstsegmentsLength * secondSegmentsLength);

                if (cos < 0)
                {
                    firstSegmentsStart_A = firstSegmentsVertices[1];
                    firstSegmentsEnd_B   = firstSegmentsVertices[0];
                }

                vectorAC = secondSegmentsStart_C.Difference(firstSegmentsStart_A);
                Vector2D vectorDB = firstSegmentsEnd_B.Difference(secondSegmentsEnd_D);

                cos = vectorAC.Dot(vectorDB) / (vectorAC.normalize() * vectorDB.normalize());

                if (cos > 0)
                {
                    onTop = true;
                }
            }

            return(onTop);
        }