public void Polyhedron_MultiShiftReturnToOriginal() { Polyhedron polyhedron = new TestRectangularBox2(); //rotate 90 degrees towards z Angle zAngle = Angle.RightAngle; Rotation zRotation = new Rotation(Line.ZAxis, zAngle); Angle xAngle = Angle.RightAngle; //This is the X axis Rotation xRotation = new Rotation(Line.XAxis, xAngle); Shift ninetyShift = new Shift(new List<Rotation>() { zRotation, xRotation }); Polyhedron shifted = polyhedron.Shift(ninetyShift); //undo the previous shift Polyhedron s = new Polyhedron(shifted.Shift(ninetyShift.Inverse())); s.Should().Be(polyhedron); }
public void CoordinateSystem_RotationMatrix() { Point origin = Point.Origin; Angle angleX = new Angle(-46.775, Degrees); Angle angleY = new Angle(23.6, Degrees); Angle angleZ = new Angle(213, Degrees); CoordinateSystem testSystem = new CoordinateSystem(origin, angleX, angleY, angleZ); Matrix test1 = Matrix.RotationMatrixAboutZ(angleZ) * Matrix.RotationMatrixAboutY(angleY) * Matrix.RotationMatrixAboutX(angleX); List<Angle> results1 = test1.EulerAngles(); Matrix test2 = Matrix.RotationMatrixAboutX(angleX) * Matrix.RotationMatrixAboutY(angleY) * Matrix.RotationMatrixAboutZ(angleZ); List<Angle> results2 = test2.EulerAngles(); Matrix testMatrix = testSystem.RotationMatrixFromThisToWorld(); List<Angle> results = testMatrix.EulerAngles(); List<Rotation> resultRotations = new List<Rotation>(); resultRotations.Add(new Rotation(Line.XAxis, results[0])); resultRotations.Add(new Rotation(Line.YAxis, results[1])); resultRotations.Add(new Rotation(Line.ZAxis, results[2])); Shift resultShift = new Shift(resultRotations, origin); List<Rotation> resultRotations2 = new List<Rotation>(); resultRotations2.Add(new Rotation(Line.ZAxis, results[2])); resultRotations2.Add(new Rotation(Line.YAxis, results[1])); resultRotations2.Add(new Rotation(Line.XAxis, results[0])); Shift resultShift2 = new Shift(resultRotations2, origin); Point testPoint = Point.MakePointWithInches(3, -1, -20); Point expectedPoint = testPoint.Shift(testSystem.ShiftToThisFrom()); Point expectedPoint2 = testPoint.Shift(testSystem.ShiftFromThisTo()); Point resultPoint = testPoint.Shift(resultShift); Point resultPoint2 = testPoint.Shift(resultShift.Inverse()); Point resultPoint3 = testPoint.Shift(resultShift2); (results[0] == angleX.ProperAngle).Should().BeTrue(); (results[1] == angleY).Should().BeTrue(); (results[2] == angleZ).Should().BeTrue(); }
public void CoordinateSystem_Shift_FromAndTo() { CoordinateSystem test = new CoordinateSystem(Point.MakePointWithInches(1, -2, -3), new Angle(new Degree(), -45), new Angle(new Degree(), 23.6), new Angle(new Degree(), 243)); Shift resultFrom = test.ShiftFromThisTo(); Shift resultTo = test.ShiftToThisFrom(); List<Rotation> expectedRotations = new List<Rotation>(); expectedRotations.Add(new Rotation(Line.XAxis, new Angle(new Degree(), -45))); expectedRotations.Add(new Rotation(Line.YAxis, new Angle(new Degree(), 23.6))); expectedRotations.Add(new Rotation(Line.ZAxis, new Angle(new Degree(), 243))); Shift expected = new Shift(expectedRotations, Point.MakePointWithInches(1, -2, -3)); resultFrom.Should().Be(expected); //it ends up being what we inputted because it shift reflects the movement of the objects so it is by definition the negative of the //coordinate system. Therfore, whenever we want to revert it we are taking a "double negative" in implementation, giving us the origina resultTo.Should().Be(expected.Inverse()); }
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); }
public void Polyhedron_Shift_RotateAndTranslate_ThenReturnToOriginal() { Polyhedron polyhedron = new TestRectangularBox2(); //rotate 90 degrees toward z Angle xAngle = new Angle(new Degree(), 63); Rotation xRotation = new Rotation(Line.XAxis, xAngle); Point displacementPoint = Point.MakePointWithInches(0, 0, 1); Shift ninetyShift = new Shift(xRotation, displacementPoint); Polyhedron s = new Polyhedron(polyhedron.Shift(ninetyShift)); Polyhedron s2 = s.Shift(ninetyShift.Inverse()); s2.Should().Be(polyhedron); }