public void Direction_Equality_Tests()
        {
            Direction direction2 = new Direction(33 * Degrees);
            Direction direction4 = new Direction(33 * Degrees, RightAngle);

            (direction2 == direction4).Should().BeTrue();

            //Error margin of 0.1 degrees
            var       testVector             = FreeVector.MakeWithInches(0.002, 0.001, -1.5);
            Direction testErrorHandling      = new Direction(testVector);
            Direction expectedErrorDirection = Direction.NegativeZ;

            (testErrorHandling == expectedErrorDirection).Should().BeTrue();

            //now try the reverse Direction too
            var       testVector0    = FreeVector.MakeWithInches(0.002, 0.001, 1.5);
            Direction testDirection1 = new Direction(testVector0);
            Direction expected       = Direction.PositiveZ;

            (testDirection1 == expected).Should().BeTrue();

            var       testVector2    = FreeVector.MakeWithInches(0.003, 0.002, 1.5);
            Direction testDirection2 = new Direction(testVector2);

            //Just barely more than a 0.1 degree angle between them
            (testDirection2 == expected).Should().BeFalse();
        }
Example #2
0
        public void Plane_PointOnSameSideAs()
        {
            Point  testPoint        = Point.MakePointWithInches(1, 3, -1);
            Point  testPoint2       = Point.MakePointWithInches(-1, -2, 5);
            Point  testPoint3       = Point.MakePointWithInches(0, 1, 0);
            Point  referencePoint   = Point.MakePointWithInches(1, 2, 1);
            Point  referencePoint2  = Point.MakePointWithInches(0, 2, 1);
            Vector testNormalVector = new Vector(FreeVector.MakeWithInches(1, 0, 0));

            Plane testPlane = new Plane(testNormalVector);

            testPlane.PointIsOnSameSideAs(testPoint, referencePoint).Should().BeTrue();   //test one on the same side
            testPlane.PointIsOnSameSideAs(testPoint2, referencePoint).Should().BeFalse(); //test one on the opposite side
            testPlane.PointIsOnSameSideAs(testPoint3, referencePoint).Should().BeFalse(); //test one on the plane
            testPlane.PointIsOnSameSideAs(testPoint, referencePoint2).Should().BeFalse(); //test a reference point on the plane


            Point  testPointOffOrigin      = Point.MakePointWithInches(5, 4, 0);
            Point  testPointOffOrigin2     = Point.MakePointWithInches(5, -2, 0);
            Point  referencePointOffOrigin = Point.MakePointWithInches(1, 2, 3);
            Point  planeBase = Point.MakePointWithInches(1, -4, 2);
            Vector testNormalVectorOffOrigin = new Vector(FreeVector.MakeWithInches(-1, 2, 1));

            Plane testPlaneOffOrigin = new Plane(testNormalVectorOffOrigin.Direction, planeBase);

            testPlaneOffOrigin.PointIsOnSameSideAs(testPointOffOrigin, referencePointOffOrigin).Should().BeTrue();
            testPlaneOffOrigin.PointIsOnSameSideAs(testPointOffOrigin2, referencePointOffOrigin).Should().BeFalse();
            testPlaneOffOrigin.PointIsOnSameSideAs(planeBase, referencePointOffOrigin).Should().BeFalse();
        }
        public void Vector_ProjectOntoPlane()
        {
            Vector testSegment = new Vector(FreeVector.MakeWithInches(2, 5, 3));
            Plane  projectOnto = new Plane(Line.ZAxis);

            Vector result = testSegment.ProjectOntoPlane(projectOnto);

            Vector expected = new Vector(FreeVector.MakeWithInches(2, 5));

            result.Should().Be(expected);
        }
Example #4
0
        public void Point_Rotate3DTest_AxisNotThroughOrigin()
        {
            Point pointToRotate = Point.MakePointWithInches(4, -2, 2);
            Line  axis          = new Line(new Direction(FreeVector.MakeWithInches(-1, -5, -3)), Point.MakePointWithInches(2, -2, -3));

            Angle rotationAngle = 322 * Degrees;

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

            newPoint.Should().Be(Point.MakePointWithInches(6.2806322893240427, -1.3811031899761135, 0.20829455351884096));
        }
Example #5
0
        public void Point_IsOnLineWithComponentOfDirectionEqualToZeroTest()
        {
            Point     testBasePoint = Point.MakePointWithInches(1, 0, 2);
            Direction testDirection = new Direction(FreeVector.MakeWithInches(0, 3, 1));

            Line testLine = new Line(testDirection, testBasePoint);

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

            pointOnLine.IsOnLine(testLine).Should().BeTrue();
        }
        public void Shift_ShiftToCoordinateSystem()
        {
            Shift system = new Shift(FreeVector.MakeWithInches(1, -2, -4), RightAngle, -45 * Degrees, ZeroAngle);

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

            Point shifted = testPoint.Shift(system.Inverse());

            Point expected = Point.MakePointWithInches(2.12132034356, 3.53553391, -5);

            shifted.Should().Be(expected);
        }
Example #7
0
        public void Point_TranslateTest()
        {
            Point pointToTranslate = Point.MakePointWithInches(1, 2, 3);
            //Direction directionToTranslate = new Direction(Point.MakePointWithInches(-1, 5, 4));
            //Distance displacementOfPoint = 12.9614814 * Unit.Inches;
            var testDisplacement = FreeVector.MakeWithInches(-2, 10, 8);

            Point actualResult = pointToTranslate.Translate(testDisplacement);

            Point expectedResult = Point.MakePointWithInches(-1, 12, 11);

            actualResult.Should().Be(expectedResult);
        }
Example #8
0
        public void Point_MakePerpendicularLineSegmentTest2()
        {
            Point destinationLineBasePoint = Point.MakePointWithInches(2, 3, 4);
            Line  destinationLine          = new Line(new Direction(FreeVector.MakeWithInches(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);
        }
Example #9
0
        public void Plane_IntersectionWithPlane()
        {
            Plane testPlane1 = new Plane(new Direction(FreeVector.MakeWithInches(2, -1, 1)), Point.MakePointWithInches(2, 1, 2));
            Plane testPlane2 = new Plane(new Direction(FreeVector.MakeWithInches(1, 1, -1)), Point.MakePointWithInches(1, 3, 3));

            Line test12Intersect = testPlane1.IntersectWithPlane(testPlane2).As <Line>();
            Line test21Intersect = testPlane2.IntersectWithPlane(testPlane1).As <Line>();

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

            Assert.IsTrue(test12Intersect.Equals(test21Intersect));
            Assert.IsTrue(test21Intersect.Equals(expectedLine));
        }
Example #10
0
        public void Plane_PerpendicularLineTest()
        {
            Plane testPlane1 = new Plane(new Direction(FreeVector.MakeWithInches(2, -1, 1)), Point.MakePointWithInches(2, 1, 2));
            Plane testPlane2 = new Plane(new Direction(FreeVector.MakeWithInches(1, 1, -1)), Point.MakePointWithInches(1, 3, 3));

            Line perpindicular1 = new Line(Point.Origin, 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();
        }
Example #11
0
        public void Point_TranslateTest_OneComponent()
        {
            Point pointToTranslate = Point.MakePointWithInches(1, 1, 1);

            //Direction directionToTranslate = new Direction(Point.MakePointWithInches(1, 0, 0));
            //Distance displacementOfPoint = 4 * Unit.Inches;
            var testDisplacement = FreeVector.MakeWithInches(4, 0, 0);

            Point actualResult = pointToTranslate.Translate(testDisplacement);

            Point expectedResult = Point.MakePointWithInches(5, 1, 1);

            actualResult.Should().Be(expectedResult);
        }
        public void Line_Translate()
        {
            var line1 = new Line(Point.MakePointWithInches(1, 2, 3), Point.MakePointWithInches(-3, -2, 0));

            //Direction testDirection = new Direction(FreeVector.MakeWithInches(-1, 5, 4));
            //Distance testDisplacement = 12.9614814 * Unit.Inches;
            var testDisplacement = FreeVector.MakeWithInches(-2, 10, 8);

            var actualLine1 = line1.Translate((testDisplacement));

            var expectedLine1 = new Line(Point.MakePointWithInches(-1, 12, 11), Point.MakePointWithInches(-5, 8, 8));

            (actualLine1 == expectedLine1).Should().BeTrue();
        }
        public void Shift_CoordinateShiftTheUnShift()
        {
            Shift system = new Shift(FreeVector.MakeWithInches(-1, 2, 4), 123 * Degrees, -22 * Degrees, 78 * Degrees);

            List <LineSegment> bounds = new List <LineSegment>();

            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(4, 1, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(4, 3, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 0), Point.MakePointWithInches(4, 3, 0)));
            Polygon testPolygon = new Polygon(bounds);

            Polygon shifted  = testPolygon.Shift(system.Inverse());
            Polygon shifted2 = shifted.Shift(system);

            testPolygon.Should().Be(shifted2);
        }
        public void Line_Rotate_AboutZAxis()
        {
            var basePointLine1  = Point.MakePointWithInches(2, 1, 0);
            var otherPointLine1 = Point.MakePointWithInches(3, 3, 3);

            var line1    = new Line(basePointLine1, otherPointLine1);
            var axisLine = new Line(Point.Origin, Point.MakePointWithInches(0, 0, 1));

            var rotationAngle = 199 * Degrees;

            var actualResult = line1.Rotate(new Rotation(axisLine, rotationAngle));

            var expectedResultBasePoint = Point.MakePointWithInches(-1.5654689967414768, -1.5966548845136304, 0.0);
            var expectedDirection       = new Direction(FreeVector.MakeWithInches(-0.29438226668500322, -2.2166053056557904, 3.0));
            var expectedResult          = new Line(expectedDirection, expectedResultBasePoint);

            actualResult.Should().Be(expectedResult);
        }
        public void PolygonList_Shift()
        {
            List <Polygon> planes = new List <Polygon>();

            List <LineSegment> polygonLines = new List <LineSegment>();

            polygonLines.Add(new LineSegment(Point.MakePointWithInches(2, 3, 1)));
            polygonLines.Add(new LineSegment(Point.MakePointWithInches(0, 2, 5)));
            polygonLines.Add(new LineSegment(Point.MakePointWithInches(2, 3, 1), Point.MakePointWithInches(0, 2, 5)));
            Polygon polygon = new Polygon(polygonLines);


            List <LineSegment> polygon2Lines = new List <LineSegment>();

            polygon2Lines.Add(new LineSegment(Point.MakePointWithInches(-1, -5, 7)));
            polygon2Lines.Add(new LineSegment(Point.MakePointWithInches(2, 3, 2)));
            polygon2Lines.Add(new LineSegment(Point.MakePointWithInches(2, 3, 2), Point.MakePointWithInches(-1, -5, 7)));
            Polygon polygon2 = new Polygon(polygon2Lines);

            //add them to the generic list
            planes.Add(polygon);
            planes.Add(polygon2);

            Shift shift = new Shift(FreeVector.MakeWithInches(2, 0, 0));

            List <LineSegment> polygonExpectedLines = new List <LineSegment>();

            polygonExpectedLines.Add(new LineSegment(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(4, 3, 1)));
            polygonExpectedLines.Add(new LineSegment(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(2, 2, 5)));
            polygonExpectedLines.Add(new LineSegment(Point.MakePointWithInches(4, 3, 1), Point.MakePointWithInches(2, 2, 5)));
            Polygon polygonExpected = new Polygon(polygonExpectedLines);

            List <LineSegment> polygon2ExpectedLines = new List <LineSegment>();

            polygon2ExpectedLines.Add(new LineSegment(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(1, -5, 7)));
            polygon2ExpectedLines.Add(new LineSegment(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(4, 3, 2)));
            polygon2ExpectedLines.Add(new LineSegment(Point.MakePointWithInches(4, 3, 2), Point.MakePointWithInches(1, -5, 7)));
            Polygon polygon2Expected = new Polygon(polygon2ExpectedLines);

            List <Polygon> resultPlanes = planes.Shift(shift);

            (resultPlanes[0] == polygonExpected).Should().BeTrue();
            (resultPlanes[1] == polygon2Expected).Should().BeTrue();
        }
        public void Vector_AngleBetween()
        {
            Vector vector1 = new Vector(FreeVector.MakeWithInches(1, 2, 3));
            Vector vector2 = new Vector(FreeVector.MakeWithInches(-2, 1, 0));
            Vector vector3 = new Vector(FreeVector.MakeWithInches(-2, 1, 1));
            Vector vector4 = new Vector(FreeVector.MakeWithInches(1, 0));
            Vector vector5 = new Vector(FreeVector.MakeWithInches(1, Math.Sqrt(3)));

            Angle result1 = vector1.AngleBetween(vector2);
            Angle result2 = vector1.AngleBetween(vector3);
            Angle result3 = vector4.AngleBetween(vector5);

            Angle expectedAngle1 = 1.57079632679 * Unit.Radians;
            Angle expectedAngle2 = 1.23732315 * Unit.Radians;
            Angle expectedAngle3 = 60 * Unit.Degrees;

            (result1 == expectedAngle1).Should().BeTrue();
            (result2 == expectedAngle2).Should().BeTrue();
            (result3 == expectedAngle3).Should().BeTrue();
        }
Example #17
0
        public void Point_ShiftTest()
        {
            Point point1 = Point.MakePointWithInches(1, 1, 0);

            var displacement = FreeVector.MakeWithInches(1, -1, 1);

            Angle    angleAboutZAxis = RightAngle / 2;
            Rotation zRotation       = new Rotation(Line.ZAxis, angleAboutZAxis);
            Angle    angleAboutXAxis = 112 * Degrees;
            Rotation xRotation       = new Rotation(Line.XAxis, angleAboutXAxis);
            Shift    testShift       = new Shift(new List <Rotation>()
            {
                zRotation, xRotation
            }, displacement);

            Point actual1 = point1.Shift(testShift);

            Point expected1 = Point.MakePointWithInches(1 + 0, -1 + -0.5298, 1 + 1.3112);

            actual1.Should().Be(expected1);
        }
        public void Shift_ComposeRotationAndTranslation()
        {
            var angle       = -90 * Degrees;
            var axis        = new Line(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(1, 0, 1));
            var rotation    = new Rotation(axis, angle);
            var translation = FreeVector.MakeWithInches(-1, 2, 5);
            var shift       = new Shift(rotation, translation);

            shift
            .Matrix
            .ShouldEqualWithinTolerance
            (
                new double[, ]
            {
                { 0, 1, 0, 0 },
                { -1, 0, 0, 3 },
                { 0, 0, 1, 5 },
                { 0, 0, 0, 1 },
            }
            );
        }
Example #19
0
        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(FreeVector.MakeWithInches(1, 1, 1)), Point.MakePointWithInches(1, -1, -1));
            Angle rotationAngle = 212 * Degrees;

            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 Shift_TranslateUsingToCoordinateSystem()
        {
            Shift system = new Shift(FreeVector.MakeWithInches(1, -2, -4));

            List <LineSegment> bounds = new List <LineSegment>();

            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(4, 1, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(4, 3, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 0), Point.MakePointWithInches(4, 3, 0)));
            Polygon testPolygon = new Polygon(bounds);

            Polygon shifted = testPolygon.Shift(system.Inverse());

            List <LineSegment> expectedBounds = new List <LineSegment>();

            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(-1, 3, 4), Point.MakePointWithInches(-1, 5, 4)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(-1, 3, 4), Point.MakePointWithInches(3, 3, 4)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(-1, 5, 4), Point.MakePointWithInches(3, 5, 4)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(3, 3, 4), Point.MakePointWithInches(3, 5, 4)));
            Polygon expectedPolygon = new Polygon(expectedBounds);

            shifted.Should().Be(expectedPolygon);
        }
        public void Shift_ShiftPolygonFromCoordinateSystem()
        {
            Shift system = new Shift(FreeVector.MakeWithInches(0, 1, 0), RightAngle / 2, -45 * Degrees, ZeroAngle);

            List <LineSegment> bounds = new List <LineSegment>();

            bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0)));
            bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(4, 0, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(0, 2, 0), Point.MakePointWithInches(4, 2, 0)));
            bounds.Add(new LineSegment(Point.MakePointWithInches(4, 0, 0), Point.MakePointWithInches(4, 2, 0)));
            Polygon testPolygon = new Polygon(bounds);

            Polygon shifted = testPolygon.Shift(system);

            List <LineSegment> expectedBounds = new List <LineSegment>();

            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(-1, 2.41421356237, 1)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(2.82842712475, 1, 2.82842712475)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(-1, 2.41421356237, 1), Point.MakePointWithInches(1.82842712475, 2.41421356237, 3.82842712475)));
            expectedBounds.Add(new LineSegment(Point.MakePointWithInches(2.82842712475, 1, 2.82842712475), Point.MakePointWithInches(1.82842712475, 2.41421356237, 3.82842712475)));
            Polygon expectedPolygon = new Polygon(expectedBounds);

            shifted.Should().Be(expectedPolygon);
        }