Ejemplo n.º 1
0
        public void It_Returns_A_Vector_Rotated_By_An_Angle()
        {
            // Arrange
            Vector3 vector          = new Vector3(-7, 10, -5);
            double  rotationAngle1  = GSharkMath.ToRadians(-0.0000125);
            Vector3 expectedResult1 = new Vector3(-7.0, 10.0, -5.0);
            double  rotationAngle2  = GSharkMath.ToRadians(0.0);
            Vector3 expectedResult2 = new Vector3(-7.0, 10.0, -5.0);
            double  rotationAngle3  = GSharkMath.ToRadians(12.5);
            Vector3 expectedResult3 = new Vector3(-7.454672, 10.649531, -2.239498);
            double  rotationAngle4  = GSharkMath.ToRadians(450);
            Vector3 expectedResult4 = new Vector3(-2.867312, 4.09616, 12.206556);

            Vector3 axis = new Vector3(10, 7, 0);

            // Act
            Vector3 result1 = vector.Rotate(axis, rotationAngle1);
            Vector3 result2 = vector.Rotate(axis, rotationAngle2);
            Vector3 result3 = vector.Rotate(axis, rotationAngle3);
            Vector3 result4 = vector.Rotate(axis, rotationAngle4);

            // Assert
            result1.EpsilonEquals(expectedResult1, 1e-6).Should().Be(true);
            result2.EpsilonEquals(expectedResult2, 1e-6).Should().Be(true);
            result3.EpsilonEquals(expectedResult3, 1e-6).Should().Be(true);
            result4.EpsilonEquals(expectedResult4, 1e-6).Should().Be(true);
        }
Ejemplo n.º 2
0
        public void It_Returns_A_Rotated_Plane()
        {
            // Arrange
            Plane plane = BasePlaneByPoints;

            // Act
            Plane rotatedPlane = plane.Rotate(GSharkMath.ToRadians(30));

            // Assert
            rotatedPlane.XAxis.EpsilonEquals(new Vector3(-0.965926, -0.258819, 0), GSharkMath.MaxTolerance).Should().BeTrue();
            rotatedPlane.YAxis.EpsilonEquals(new Vector3(-0.258819, 0.965926, 0), GSharkMath.MaxTolerance).Should().BeTrue();
            rotatedPlane.ZAxis.EpsilonEquals(new Vector3(0, 0, -1), GSharkMath.MaxTolerance).Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void It_Creates_An_Aligned_BoundingBox()
        {
            // Arrange
            Plane orientedPlane = Plane.PlaneXY.Rotate(GSharkMath.ToRadians(30));
            var   expectedMin   = new Point3(45.662928, 59.230957, -4.22451);
            var   expectedMax   = new Point3(77.622297, 78.520011, 3.812853);

            // Act
            var bBox = new BoundingBox(BoundingBoxCollection.BoundingBox3D(), orientedPlane);

            // Assert
            _testOutput.WriteLine(bBox.ToString());
            bBox.Should().NotBeNull();
            bBox.Min.DistanceTo(expectedMin).Should().BeLessThan(GSharkMath.MaxTolerance);
            bBox.Max.DistanceTo(expectedMax).Should().BeLessThan(GSharkMath.MaxTolerance);
        }
Ejemplo n.º 4
0
        public ArcTests(ITestOutputHelper testOutput)
        {
            _testOutput = testOutput;

            #region example
            // Initializes an arc by plane, radius and angle.
            double angle = GSharkMath.ToRadians(40);
            _exampleArc2D = new Arc(Plane.PlaneXY, 15, angle);

            // Initializes an arc by 3 points.
            Point3 pt1 = new Point3(74.264416, 36.39316, -1.884313);
            Point3 pt2 = new Point3(97.679126, 13.940616, 3.812853);
            Point3 pt3 = new Point3(100.92443, 30.599893, -0.585116);
            _exampleArc3D = new Arc(pt1, pt2, pt3);
            #endregion
        }
Ejemplo n.º 5
0
        public void It_Returns_A_Rotated_Transformed_Matrix()
        {
            // Arrange
            var    center         = new Point3(5, 5, 0);
            double angleInRadians = GSharkMath.ToRadians(30);

            // Act
            Transform transform = Transform.Rotation(angleInRadians, center);

            // Getting the angles.
            Dictionary <string, double> angles = Transform.GetYawPitchRoll(transform);
            // Getting the direction.
            var axis = Transform.GetRotationAxis(transform);

            // Assert
            GSharkMath.ToDegrees(angles["Yaw"]).Should().BeApproximately(30, GSharkMath.Epsilon);
            axis.Should().BeEquivalentTo(Vector3.ZAxis);
        }
Ejemplo n.º 6
0
        public void It_Returns_The_BoundingBox_Of_The_Arc()
        {
            // Arrange
            double angle = GSharkMath.ToRadians(40);
            Arc    arc2D = new Arc(Plane.PlaneXY, 15, angle);
            Arc    arc3D = _exampleArc3D;

            // Act
            BoundingBox bBox2D = arc2D.BoundingBox();
            BoundingBox bBox3D = arc3D.BoundingBox();

            // Assert
            bBox2D.Min.EpsilonEquals(new Vector3(11.490667, 0, 0), 6).Should().BeTrue();
            bBox2D.Max.EpsilonEquals(new Vector3(15, 9.641814, 0), 6).Should().BeTrue();

            bBox3D.Min.EpsilonEquals(new Vector3(69.115079, 8.858347, -1.884313), 6).Should().BeTrue();
            bBox3D.Max.EpsilonEquals(new Vector3(102.068402, 36.39316, 5.246477), 6).Should().BeTrue();
        }
Ejemplo n.º 7
0
        public void It_Returns_A_Arc_Based_On_A_Start_And_An_End_Point_And_A_Direction()
        {
            // Arrange
            Point3  startPt        = new Point3(5, 5, 5);
            Point3  endPt          = new Point3(10, 15, 10);
            Vector3 dir            = new Vector3(3, 3, 0);
            double  radiusExpected = 12.247449;
            double  angleExpected  = GSharkMath.ToRadians(60);
            Point3  centerExpected = new Point3(0, 10, 15);

            // Act
            Arc arc = Arc.ByStartEndDirection(startPt, endPt, dir);

            // Assert
            arc.Angle.Should().BeApproximately(angleExpected, 1e-6);
            arc.Radius.Should().BeApproximately(radiusExpected, 1e-6);
            arc.Plane.Origin.EpsilonEquals(centerExpected, 1e-6).Should().BeTrue();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Evaluates a point at the specif length.
        /// </summary>
        /// <param name="length">The length where to evaluate the point.</param>
        /// <returns>The point at the length.</returns>
        public override Point3 PointAtLength(double length)
        {
            if (length <= 0.0)
            {
                return(StartPoint);
            }

            if (length >= Length)
            {
                return(EndPoint);
            }

            double theta = GSharkMath.ToRadians((length * 360) / (Math.PI * 2 * Radius));

            Vector3 xDir = Plane.XAxis * Math.Cos(theta) * Radius;
            Vector3 yDir = Plane.YAxis * Math.Sin(theta) * Radius;

            return(Plane.Origin + xDir + yDir);
        }
Ejemplo n.º 9
0
        public void It_Returns_A_Transformed_Plane()
        {
            // Arrange
            var       pt1            = new Point3(20, 20, 0);
            var       pt2            = new Point3(5, 5, 0);
            var       pt3            = new Point3(-5, 10, 0);
            Plane     plane          = new Plane(pt1, pt2, pt3);
            Transform translation    = Transform.Translation(new Point3(10, 15, 0));
            Transform rotation       = Transform.Rotation(GSharkMath.ToRadians(30), new Point3(0, 0, 0));
            var       expectedOrigin = new Point3(17.320508, 42.320508, 0);
            var       expectedZAxis  = new Vector3(0, 0, -1);

            // Act
            Transform combinedTransformations = translation.Combine(rotation);
            Plane     transformedPlane        = plane.Transform(combinedTransformations);

            // Assert
            transformedPlane.Origin.EpsilonEquals(expectedOrigin, GSharkMath.MaxTolerance).Should().BeTrue();
            transformedPlane.ZAxis.EpsilonEquals(expectedZAxis, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Ejemplo n.º 10
0
 public void It_Returns_The_Radians_From_Degree(double degree, double radiansExpected)
 {
     System.Math.Round(GSharkMath.ToRadians(degree), 6).Should().Be(radiansExpected);
 }