public void Plane_ContainsLineOnOrigin()
        {
            Plane testPlane = new Plane(Point.Origin, Point.MakePointWithInches(1, 3, 0), Point.MakePointWithInches(-3, -1, 0));
            Line testLine = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0));

            bool result = testPlane.Contains(testLine);

            result.Should().BeTrue();
        }
 public void Rotation_Inverse()
 {
     Line axis = new Line(Point.MakePointWithInches(-2, 7, 0), Point.MakePointWithInches(0, 1, 1));
     Rotation rotation = new Rotation(axis, new Angle(new Degree(), 42));
     Point point = Point.MakePointWithInches(1, 1, 1);
     
     Point rotated = point.Rotate3D(rotation);
     Point unrotated = rotated.Rotate3D(rotation.Inverse());
    
     (point == unrotated).Should().BeTrue();
 }
        public void Plane_ContainsLine()
        {
            Plane testPlane = new Plane(Point.Origin, Point.MakePointWithInches(1, 3, 0), Point.MakePointWithInches(4, -2, 0));
            Line testLine = new Line(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(0, -1, 0));
            Line testFalseLine = new Line(Point.MakePointWithInches(1, 2, -2), Point.MakePointWithInches(2, 4, 3));

            bool result = testPlane.Contains(testLine);
            bool result2 = testPlane.Contains(testFalseLine);

            result.Should().BeTrue();
            result2.Should().BeFalse();
        }
        public void Rotation_EqualityTests()
        {
            Line axis1 = new Line(Point.MakePointWithInches(-2, 7, 0), Point.MakePointWithInches(0, 1, 1));
            Rotation rotation1 = new Rotation(axis1, new Angle(new Degree(), 42));

            Line axis2 = new Line(Point.MakePointWithInches(-2, 7, 0), Point.MakePointWithInches(0, 1, 1));
            Rotation rotation2 = new Rotation(axis2, new Angle(new Degree(), 42));

            Line axis3 = new Line(Point.MakePointWithInches(-3, 7, 0), Point.MakePointWithInches(0, 1, 1));
            Rotation rotation3 = new Rotation(axis3, new Angle(new Degree(), 42));

            Line axis4 = new Line(Point.MakePointWithInches(-3, 7, 0), Point.MakePointWithInches(0, 1, 1));
            Rotation rotation4 = new Rotation(axis4, new Angle(new Degree(), 63));

            (rotation1 == rotation2).Should().BeTrue();
            (rotation1 != rotation2).Should().BeFalse();
            (rotation1 == rotation3).Should().BeFalse();
            (rotation1 == rotation4).Should().BeFalse();
            (rotation3 != rotation4).Should().BeTrue();
        }
        public void Plane_RotateTest()
        {
            Point testBasePoint = Point.MakePointWithInches(1, 1, -1);            
            Vector testNormalVector = new Vector(Point.MakePointWithInches(0, 2, 3), Point.MakePointWithInches(-3, -2, 0));

            Plane testPlane = new Plane(testNormalVector.Direction, testBasePoint);

            Line rotationAxis = new Line(new Direction(Point.MakePointWithInches(1, 1, 1)), Point.MakePointWithInches(1, -1, -1));
            Angle rotationAngle = new Angle(new Degree(), 212);

            Plane actualResult = testPlane.Rotate(new Rotation(rotationAxis, rotationAngle));

            Point expectedPoint = Point.MakePointWithInches(2.8439301238119032, -1.4640641282085687, -0.37986599560333495);
            Vector expectedVector = new Vector(Point.MakePointWithInches(5.23819525861547, 1.681697053112619, -1.91989231172809), Point.MakePointWithInches(1.3162301967095191, -1.0862708827830958, -5.2299593139264218));
            Plane expectedResult = new Plane(expectedVector.Direction, expectedPoint);

            bool test = expectedPoint == actualResult.BasePoint;
            bool test2 = expectedVector == actualResult.NormalVector;

            (actualResult == expectedResult).Should().BeTrue();
        }
        public void LineList_SmallestXInterceptIn2D()
        {
            Line line1 = new Line(Point.MakePointWithInches(3, 2, 5), Point.MakePointWithInches(5, 3, 7)); //intersects at -1
            Line line2 = new Line(Point.MakePointWithInches(6, 0, 0), Point.MakePointWithInches(-5, 3, -1)); //intersects at 6
            Line line3 = new Line(Point.MakePointWithInches(1, 1, 5), Point.MakePointWithInches(2, 2, 4)); //intersects at 0
            Line line4 = new Line(Point.MakePointWithInches(4, 10, 1), Point.MakePointWithInches(4, 5, 2)); //intersects at 4
            Line line5 = new Line(Point.MakePointWithInches(4, 2, 2), Point.MakePointWithInches(4, 2, 1)); //doesnt intersect

            List<Line> lines = new List<Line> { line4, line2, line1, line5, line3 };

            Line result = lines.LineWithLowestXInterceptIn2D();

            result.Should().Be(line1);

            //check it can handle a null intersect in the first spot
            List<Line> lines2 = new List<Line> { line5, line2, line1, line4, line3 };

            Line result2 = lines2.LineWithLowestXInterceptIn2D();

            result2.Should().Be(line1);
        }
        public void Plane_ParallelLineTest()
        {
            Line plane1Line1 = new Line(Point.MakePointWithInches(1, 1, 0));
            Line plane1Line2 = new Line(Point.MakePointWithInches(2, 0, -1), Point.MakePointWithInches(3, 1, -1));
            Plane testPlane1 = new Plane(plane1Line1, plane1Line2);

            Line plane2Line1 = new Line(Point.MakePointWithInches(-3, 2, -2));
            Line plane2Line2 = new Line(Point.MakePointWithInches(1, -2, -1), Point.MakePointWithInches(-2, 0, -3));
            Plane testPlane2 = new Plane(plane2Line1, plane2Line2);

            Line parallel1 = new Line(Point.MakePointWithInches(1, -2, 1), Point.MakePointWithInches(2, -1, 1));
            Line parallel2 = new Line(Point.MakePointWithInches(-6, 4, -4));

            testPlane1.IsParallelTo(parallel1).Should().BeTrue();
            testPlane1.IsParallelTo(parallel2).Should().BeFalse();

            testPlane2.IsParallelTo(parallel1).Should().BeFalse();
            testPlane2.IsParallelTo(parallel2).Should().BeTrue();
        }
        public void Plane_IntersectionWithPlane_IdenticalPlane()
        {
            Plane testPlane = new Plane(new Direction(2, -1, 1), Point.MakePointWithInches(2, 1, 2));

            Line found = (testPlane.IntersectWithPlane(testPlane));
            Line expected = new Line(new Direction(-1, 0, 2), Point.MakePointWithInches(2, 1, 2));

            testPlane.Contains(found).Should().BeTrue();
            (found == expected).Should().BeTrue();
        }
        public void Plane_IntersectionWithPlane()
        {
            Plane testPlane1 = new Plane(new Direction(Point.MakePointWithInches(2, -1, 1)), Point.MakePointWithInches(2, 1, 2));
            Plane testPlane2 = new Plane(new Direction(Point.MakePointWithInches(1, 1, -1)), Point.MakePointWithInches(1, 3, 3));

            Line test12Intersect = testPlane1.IntersectWithPlane(testPlane2);
            Line test21Intersect = testPlane2.IntersectWithPlane(testPlane1);

            Line expectedLine = new Line(new Direction(Point.MakePointWithInches(0, 3, 3)), Point.MakePointWithInches(2, -1, 0));

            Assert.IsTrue(test12Intersect.Equals(test21Intersect));
            Assert.IsTrue(test21Intersect.Equals(expectedLine));
        }
Ejemplo n.º 10
0
        public void Point_Rotate3DTest_AxisNotThroughOrigin_PointIsOrigin()
        {
            Point originPoint = Point.Origin;
            Line axis = new Line(Point.MakePointWithInches(1, -1, 0), Point.MakePointWithInches(1, 1, 0));
            Angle rotationAngle = new Angle(new Degree(), 212);

            Point newPoint = originPoint.Rotate3D(new Rotation(axis, rotationAngle));

            newPoint.Should().Be(Point.MakePointWithInches(1.8480480961564261, 0, -0.52991926423320479));
        }
Ejemplo n.º 11
0
        public void Point_MirrorAcrossTest_ZAxis()
        {
            Point pointToRotate = Point.MakePointWithInches(3, 1, 2);

            Line axisLine = new Line(Point.Origin, Point.MakePointWithInches(0, 0, 1));
            Point actualResult = pointToRotate.MirrorAcross(axisLine);

            Point expectedResult = Point.MakePointWithInches(-3, -1, 2);

            actualResult.Should().Be(expectedResult);
        }
Ejemplo n.º 12
0
        public void Point_IsOnLineStandardTest()
        {
            Point testBasePoint = Point.MakePointWithInches(1, 0, 2);
            Line testLine = new Line(testBasePoint, Point.MakePointWithInches(2, 3, 1));
            Point pointOnLine = Point.MakePointWithInches(3, 6, 0);

            Point testBase = Point.MakePointWithInches(0, 0);
            Line testLine2 = new Line(testBase, Point.MakePointWithInches(5, 0));
            Point pointOnLine2 = Point.MakePointWithInches(3, 0);

            bool result = pointOnLine.IsOnLine(testLine);
            bool result2 = pointOnLine2.IsOnLine(testLine2);
            bool result3 = testBasePoint.IsOnLine(testLine2);

            result.Should().BeTrue();
            result2.Should().BeTrue();
            result3.Should().BeFalse();
        }
Ejemplo n.º 13
0
        public void Plane_IntersectLineOnPlane()
        {
            Plane testPlane = new Plane(Direction.Out);
            Line lineOnPlane = new Line(Point.MakePointWithInches(2, 1, 0));

            testPlane.IntersectWithLine(lineOnPlane).Should().Be(Point.Origin);
        }
Ejemplo n.º 14
0
        public void Plane_IntersectLine_PrecisionCheck()
        {
            Point point1 = Point.MakePointWithInches(-2.5, 73, 3.5);
            Point point2 = Point.MakePointWithInches(1, 1, 2);
            Point point3 = Point.MakePointWithInches(0, 0, 2);
            
            Plane testPlane = new Plane(Direction.Out, point3);
            Line line = new Line(point1, point2);

            Point actualIntersection = testPlane.IntersectWithLine(line);
            Point expectedIntersection = point2;

            (actualIntersection == expectedIntersection).Should().BeTrue();
        }
        public void LineList_OnlyLinesParallelTo()
        {
            Line referenceLine = new Line(Point.MakePointWithInches(0, 2, 1), Point.MakePointWithInches(2, -1, 0));

            Line parallel1 = new Line(Point.MakePointWithInches(1, 2, 1), Point.MakePointWithInches(3, -1, 0));
            Line parallel2 = new Line(Point.MakePointWithInches(2, 0.5, .5), Point.MakePointWithInches(3, -1, 0));
            Line parallel3 = new Line(Point.MakePointWithInches(-1, -1, -2), Point.MakePointWithInches(1, -4, -3));
            Line parallel4 = new Line(Point.MakePointWithInches(6, -2, 0), Point.MakePointWithInches(2, 4, 2));
            Line notParallel1 = new Line(Point.MakePointWithInches(0, 2, 1), Point.MakePointWithInches(3, -1, 0));
            Line notParallel2 = new Line(Point.MakePointWithInches(-2, 1, 1), Point.MakePointWithInches(0, 1, 0));
            Line notParallel3 = new Line(Point.MakePointWithInches(0.75, 1.5, 0.5), Point.MakePointWithInches(-0.25, 2.25, 0.75));

            List<Line> lines = new List<Line>() { parallel1, notParallel1, parallel2, parallel3, notParallel2, parallel4, notParallel3, notParallel1 };

            List<Line> resultsParallel = lines.OnlyLinesParallelTo(referenceLine);

            List<Line> expectedParallel = new List<Line>() { parallel1, parallel2, parallel3, parallel4 };

            resultsParallel.Should().Contain(expectedParallel);
        }
        public void LineList_LineWithYInterceptIn2DFarthestFrom()
        {
            Line line1 = new Line(Point.MakePointWithInches(2, 2, 2), Point.MakePointWithInches(4, 3, 7)); //intersects at 1
            Line line2 = new Line(Point.MakePointWithInches(6, 0, 0), Point.MakePointWithInches(-6, 3, -1)); //intersects at 1.5
            Line line3 = new Line(Point.MakePointWithInches(1, 1, 5), Point.MakePointWithInches(2, 2, 4)); //intersects at 0
            Line line4 = new Line(Point.MakePointWithInches(2, 1, 1), Point.MakePointWithInches(3, 2, 2)); //intersects at -1
            Line line5 = new Line(Point.MakePointWithInches(4, 2, 2), Point.MakePointWithInches(4, 2, 1)); //doesnt intersect

            List<Line> lines = new List<Line> { line4, line2, line1, line5, line3 };

            Line result = lines.LineWithYInterceptIn2DFarthestFrom(new Distance(new Inch(), 1.3));

            result.Should().Be(line4);

            //check it can handle a null intersect in the first spot
            List<Line> lines2 = new List<Line> { line5, line2, line1, line4, line3 };

            Line result2 = lines2.LineWithYInterceptIn2DFarthestFrom(new Distance(new Inch(), -0.25));

            result2.Should().Be(line2);
        }
        public void LineList_LineWithXInterceptIn2DFarthestFrom()
        {
            Line line1 = new Line(Point.MakePointWithInches(3, 2, 5), Point.MakePointWithInches(5, 3, 7)); //intersects at -1
            Line line2 = new Line(Point.MakePointWithInches(6, 0, 0), Point.MakePointWithInches(-5, 3, -1)); //intersects at 6
            Line line3 = new Line(Point.MakePointWithInches(1, 1, 5), Point.MakePointWithInches(2, 2, 4)); //intersects at 0
            Line line4 = new Line(Point.MakePointWithInches(4, 10, 1), Point.MakePointWithInches(4, 5, 2)); //intersects at 4
            Line line5 = new Line(Point.MakePointWithInches(4, 2, 2), Point.MakePointWithInches(4, 2, 1)); //doesnt intersect

            List<Line> lines = new List<Line> { line4, line2, line1, line5, line3 };

            Line result = lines.LineWithXInterceptIn2DFarthestFrom(new Distance(new Inch(), 3));

            result.Should().Be(line1);

            //check it can handle a null intersect in the first spot
            List<Line> lines2 = new List<Line> { line5, line2, line1, line4, line3 };

            Line result2 = lines2.LineWithXInterceptIn2DFarthestFrom(Distance.ZeroDistance);

            (result2 == line2).Should().BeTrue();
        }
 /// <summary>
 /// Finds all the polygons in this list that intersect the given line and returns a list of those Polygons
 /// </summary>
 public static List<Polygon> FindPolygonsThatAreIntersectedByLine(this List<Polygon> polygonList, Line intersectingLine)
 {
     return polygonList.Where(p => p.DoesIntersect(intersectingLine)).ToList();
 }
Ejemplo n.º 19
0
        public void Plane_PerpendicularLineTest()
        {
            Plane testPlane1 = new Plane(new Direction(Point.MakePointWithInches(2, -1, 1)), Point.MakePointWithInches(2, 1, 2));
            Plane testPlane2 = new Plane(new Direction(Point.MakePointWithInches(1, 1, -1)), Point.MakePointWithInches(1, 3, 3));

            Line perpindicular1 = new Line(Point.MakePointWithInches(2, -1, 1));
            Line perpindicular2 = new Line(Point.MakePointWithInches(3, 1, -3), Point.MakePointWithInches(4, 2, -4));

            testPlane1.IsPerpendicularTo(perpindicular1).Should().BeTrue();
            testPlane1.IsPerpendicularTo(perpindicular2).Should().BeFalse();

            testPlane2.IsPerpendicularTo(perpindicular1).Should().BeFalse();
            testPlane2.IsPerpendicularTo(perpindicular2).Should().BeTrue();
        }
Ejemplo n.º 20
0
        public void Point_Rotate3DTest_AxisNotThroughOrigin()
        {
            Point pointToRotate = Point.MakePointWithInches(4, -2, 2);
            Line axis = new Line(new Direction(Point.MakePointWithInches(-1, -5, -3)), Point.MakePointWithInches(2, -2, -3));

            Angle rotationAngle = new Angle(new Degree(), 322);

            Point newPoint = pointToRotate.Rotate3D(new Rotation(axis, rotationAngle));

            newPoint.Should().Be(Point.MakePointWithInches(6.2806322893240427, -1.3811031899761135, 0.20829455351884096));
        }
Ejemplo n.º 21
0
        public void Plane_IntersectLine()
        {
            Plane testPlane1 = new Plane(new Direction(2, -1, 1), Point.MakePointWithInches(2, -1, 1));
            Plane testPlane2 = new Plane(new Direction(1, 2, -1), Point.MakePointWithInches(2, -1, 1));

            Line perpendicular1 = new Line(Point.MakePointWithInches(2, -1, 1));
            Line perpendicular2 = new Line(Point.MakePointWithInches(3, 1, -3), Point.MakePointWithInches(4, 3, -4)); //1, 2, -1

            Point intersection11 = testPlane1.IntersectWithLine(perpendicular1);
            Point intersection12 = testPlane1.IntersectWithLine(perpendicular2);
            Point intersection21 = testPlane2.IntersectWithLine(perpendicular1);
            Point intersection22 = testPlane2.IntersectWithLine(perpendicular2);

            intersection11.Should().Be(Point.MakePointWithInches(2, -1, 1));
            intersection21.Should().Be(Point.MakePointWithInches(2, -1, 1));
            intersection12.Should().Be(Point.MakePointWithInches(-1, -7, 1));
            intersection22.Should().Be(Point.MakePointWithInches(1.5, -2, -1.5));
        }
Ejemplo n.º 22
0
        public void Point_MakePerpendicularLineSegmentTest()
        {
            Point destinationLineBasePoint = Point.MakePointWithInches(1, 0, 0);
            Line destinationLine = new Line(destinationLineBasePoint, Point.MakePointWithInches(1, 1, 0));

            Point testPoint = Point.MakePointWithInches(1, 0.5, 0.5);

            LineSegment actualResult = testPoint.MakePerpendicularLineSegment(destinationLine);

            LineSegment expectedResult = new LineSegment(testPoint, Point.MakePointWithInches(1, .5, 0));

            (actualResult == expectedResult).Should().BeTrue();
        }
        public void Polyhedron_Shift_RotateNotThroughOriginAndTranslate()
        {
            Polyhedron polyhedron = new TestRectangularBox2();

            //rotate 90 degrees toward z
            Angle xAngle = new Angle(new Degree(), -90);
            Line testAxis = new Line(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(1, 0, 1));
            Rotation xRotation = new Rotation(testAxis, xAngle);
            Point displacementPoint = Point.MakePointWithInches(-1, 2, 5);
            Shift ninetyShift = new Shift(xRotation, displacementPoint);

            Polyhedron s = new Polyhedron(polyhedron.Shift(ninetyShift));

            s.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(0, 3, 5), Point.MakePointWithInches(8, 3, 5))).Should().BeTrue();
            s.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(8, 3, 5), Point.MakePointWithInches(8, -1, 5))).Should().BeTrue();
            s.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(8, -1, 5), Point.MakePointWithInches(0, -1, 5))).Should().BeTrue();
            s.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(0, -1, 5), Point.MakePointWithInches(0, 3, 5))).Should().BeTrue();

        }
Ejemplo n.º 24
0
        public void Point_MakePerpendicularLineSegmentTest2()
        {
            Point destinationLineBasePoint = Point.MakePointWithInches(2,3,4);
            Line destinationLine = new Line(new Direction(Point.MakePointWithInches(6,4,-6)), destinationLineBasePoint);

            Point testPoint = Point.MakePointWithInches(0,0,0);

            LineSegment actualResult = testPoint.MakePerpendicularLineSegment(destinationLine);

            LineSegment expectedResult = new LineSegment(testPoint, Point.MakePointWithInches(2, 3, 4));

            actualResult.Should().Be(expectedResult);
        }
        public void Polyhedron_Shift_RotateNotThroughOriginAndTranslate_ThenReturnToOriginal()
        {
            Polyhedron polyhedron = new TestRectangularBox2();

            //rotate 90 degrees toward z
            Angle xAngle = Angle.RightAngle;
            Line testAxis = new Line(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(1, 0, 1));
            Rotation xRotation = new Rotation(testAxis, xAngle);
            Point displacementPoint = Point.MakePointWithInches(1, 3, -4);
            Shift ninetyShift = new Shift(xRotation, displacementPoint);

            Polyhedron s = new Polyhedron(polyhedron.Shift(ninetyShift));

            Polyhedron s2 = s.Shift(ninetyShift.Inverse());

            s2.Should().Be(polyhedron);
        }
Ejemplo n.º 26
0
        public void Point_IsOnLineWithComponentOfDirectionEqualToZeroTest()
        {
            Point testBasePoint = Point.MakePointWithInches(1, 0, 2);
            Direction testDirection = new Direction(Point.MakePointWithInches(0, 3, 1));

            Line testLine = new Line(testDirection, testBasePoint);

            Point pointOnLine = Point.MakePointWithInches(1, 6, 4);

            pointOnLine.IsOnLine(testLine).Should().BeTrue();
        }