コード例 #1
0
        public static Wall2D GetWallBetweenTwoSegments(DirectionLineSegment segment1, DirectionLineSegment segment2)
        {
            DirectionLine line1Test   = new DirectionLine(segment1.BeginPoint, new Vector2d((int)(segment1.EndPoint.X - segment1.BeginPoint.X), (int)(segment1.EndPoint.Y - segment1.BeginPoint.Y)));
            DirectionLine line2Test   = new DirectionLine(segment2.BeginPoint, new Vector2d((int)(segment2.EndPoint.X - segment2.BeginPoint.X), (int)(segment2.EndPoint.Y - segment2.BeginPoint.Y)));
            List <double> line1Alphas = new List <double>();

            line1Alphas.Add(line1Test.AlphaProjection(segment1.BeginPoint));
            line1Alphas.Add(line1Test.AlphaProjection(segment1.EndPoint));
            line1Alphas.Add(line1Test.AlphaProjection(segment2.BeginPoint));
            line1Alphas.Add(line1Test.AlphaProjection(segment2.EndPoint));

            if (line1Alphas[0] > line1Alphas[1])
            {
                double aux = line1Alphas[0];
                line1Alphas[0] = line1Alphas[1];
                line1Alphas[1] = aux;
            }
            if (line1Alphas[2] > line1Alphas[1] && line1Alphas[3] > line1Alphas[1] ||
                line1Alphas[2] < line1Alphas[0] && line1Alphas[3] < line1Alphas[0])
            {
                return(null);
            }

            line1Alphas.Sort();

            Vector2d p1 = line1Test.GetPointByPosition(line1Alphas[0]);
            Vector2d p2 = line1Test.GetPointByPosition(line1Alphas[3]);
            Vector2d p3 = line2Test.GetPointProjection(p2);
            Vector2d p4 = line2Test.GetPointProjection(p1);

            return(new Wall2D(new Vector2d[] { p1, p2, p3, p4 }, DirectionLine.GetMiddle(line1Test, line2Test)));
        }
コード例 #2
0
        public static double GetDistanceBetweenLines(DirectionLine line1, DirectionLine line2)
        {
            Vector2d prim = line1.GetPointProjection(line2.Point);

            return((prim - line2.Point).Magnitude);
        }