public void PlaneRegion_ShiftList()
        {
            List<ISurface> planes = new List<ISurface>();

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

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

            List<IEdge> nonPolygonEdges = new List<IEdge>();
            nonPolygonEdges.Add(new LineSegment(MakePointWithInches(1, 5, 3)));
            nonPolygonEdges.Add(new LineSegment(MakePointWithInches(1, 5, 3), MakePointWithInches(2, 3, 3)));
            Arc arcToadd = new Arc(Point.Origin, MakePointWithInches(2, 3, 3), Direction.Right);
            nonPolygonEdges.Add(arcToadd);
            PlaneRegion nonPolygon = new PlaneRegion(nonPolygonEdges);

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

            Shift shift = new Shift(MakePointWithInches(2, 0, 0));

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

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

            List<IEdge> nonPolygonExpectedEdges = new List<IEdge>();
            nonPolygonExpectedEdges.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(3, 5, 3)));
            nonPolygonExpectedEdges.Add(new LineSegment(MakePointWithInches(3, 5, 3), MakePointWithInches(4, 3, 3)));
            Arc arcExpected = new Arc(MakePointWithInches(2, 0, 0), MakePointWithInches(4, 3, 3), Direction.Right);
            nonPolygonExpectedEdges.Add(arcExpected);
            PlaneRegion nonPolygonExpected = new PlaneRegion(nonPolygonExpectedEdges);

            List<ISurface> resultPlanes = planes.Shift(shift);
            ((Polygon)resultPlanes[0] == polygonExpected).Should().BeTrue();
            ((Polygon)resultPlanes[1] == polygon2Expected).Should().BeTrue();
            ((PlaneRegion)resultPlanes[2] == nonPolygonExpected).Should().BeTrue();
        }  
        public static IEnumerable<PlaneRegion> Shift(this IEnumerable<PlaneRegion> passedPlaneRegions, Shift passedShift)
        {
            List<PlaneRegion> shiftedRegions = new List<PlaneRegion>();

            foreach (var region in passedPlaneRegions)
            {
                shiftedRegions.Add(region.Shift(passedShift));
            }

            return shiftedRegions;
        }
        public void Polyhedron_ShiftXY()
        {
            Polyhedron polyhedron = new TestRectangularBox2();

            //rotate 90 degrees towards x
            Shift ninetyShift = new Shift(new Rotation(Line.ZAxis, -1 * Angle.RightAngle), Point.MakePointWithInches(8, 0));
            Polyhedron result = polyhedron.Shift(ninetyShift);

            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(8, 0), Point.MakePointWithInches(16, 0))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(8, 0), Point.MakePointWithInches(8, -4))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(16, 0), Point.MakePointWithInches(16, -4))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(8, -4), Point.MakePointWithInches(16, -4))).Should().BeTrue();
        }
        public void Polyhedron_ShiftYZ()
        {
            Polyhedron polyhedron = new TestRectangularBox2();


            //rotate 90 degrees towards z
            Shift nintyShift = new Shift(new Rotation(Line.XAxis, Angle.RightAngle));
            Polyhedron result = polyhedron.Shift(nintyShift);

            result.LineSegments.Contains(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 0, 8))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.Origin, Point.MakePointWithInches(4, 0, 0))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(4, 0, 0), Point.MakePointWithInches(4, 0, 8))).Should().BeTrue();
            result.LineSegments.Contains(new LineSegment(Point.MakePointWithInches(4, 0, 8), Point.MakePointWithInches(0, 0, 8))).Should().BeTrue();
        }
        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 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(Point.MakePointWithInches(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 CoordinateSystem_Shift_MultipleAxisRotations()
        {
            CoordinateSystem testSystem1 = new CoordinateSystem(Point.MakePointWithInches(1, 2, 3), Angle.RightAngle, new Angle(new Degree(), 30), Angle.ZeroAngle);

            List<Rotation> testRotations1 = new List<Rotation>();
            testRotations1.Add(new Rotation(new Line(Direction.Out, testSystem1.TranslationToOrigin), -1 * Angle.RightAngle));
            testRotations1.Add(new Rotation(new Line(Direction.Right, testSystem1.TranslationToOrigin), new Angle(new Degree(), 30)));
            Shift testShift1 = new Shift(testRotations1, Point.MakePointWithInches(0, -2, 5));

            CoordinateSystem results1 = testSystem1.Shift(testShift1);
            CoordinateSystem expectedSystem1 = new CoordinateSystem(Point.MakePointWithInches(1, 0, 8), Angle.RightAngle, new Angle(new Degree(), 60), -1 * Angle.RightAngle);
            (results1 == expectedSystem1).Should().BeTrue();

            //now try another
            CoordinateSystem testSystem2 = new CoordinateSystem(Point.MakePointWithInches(-2, 0, 1), Angle.RightAngle / 2, -1 * Angle.RightAngle, new Angle(new Degree(), -30));

            List<Rotation> testRotations2 = new List<Rotation>();
            testRotations2.Add(new Rotation(new Line(Direction.Out, testSystem2.TranslationToOrigin), new Angle(new Degree(), -15)));
            testRotations2.Add(new Rotation(new Line(Direction.Right, testSystem2.TranslationToOrigin), Angle.RightAngle));
            testRotations2.Add(new Rotation(new Line(Direction.Out, testSystem2.TranslationToOrigin), Angle.RightAngle));
            testRotations2.Add(new Rotation(new Line(Direction.Right, testSystem2.TranslationToOrigin), -1 * Angle.RightAngle));
            Shift testShift2 = new Shift(testRotations2, Point.MakePointWithInches(2, 0, -1));

            CoordinateSystem results2 = testSystem2.Shift(testShift2);
            CoordinateSystem expectedSystem2 = new CoordinateSystem(Point.Origin, Angle.ZeroAngle, Angle.ZeroAngle, Angle.ZeroAngle);
            (results2 == expectedSystem2).Should().BeTrue();
        }
        public void CoordinateSystem_Shift_NonAxisRotation()
        {
            CoordinateSystem testSystem1 = new CoordinateSystem(Point.MakePointWithInches(1, 2, 3), Angle.RightAngle, Angle.ZeroAngle, Angle.RightAngle);
            Shift testShift1 = new Shift(new Rotation(new Line(new Direction(Angle.RightAngle / 2), testSystem1.TranslationToOrigin), Angle.RightAngle), Point.MakePointWithInches(-1, 1, 2));
            CoordinateSystem results1 = testSystem1.Shift(testShift1);
            CoordinateSystem expectedSystem1 = new CoordinateSystem(Point.MakePointWithInches(0, 3, 5), Angle.StraightAngle, new Angle(new Degree(), -45), Angle.RightAngle / 2);
            (results1 == expectedSystem1).Should().BeTrue();

            //now try another
            CoordinateSystem testSystem2 = new CoordinateSystem(Point.MakePointWithInches(1, 2, 3), Angle.RightAngle, Angle.RightAngle / 2, -1 * Angle.RightAngle);
            Shift testShift2 = new Shift(new Rotation(new Line(new Direction(-1 * Angle.RightAngle, Angle.RightAngle / 2), testSystem2.TranslationToOrigin), -1 * Angle.RightAngle), Point.MakePointWithInches(2, -1, -1));
            CoordinateSystem results2 = testSystem2.Shift(testShift2);
            CoordinateSystem expectedSystem2 = new CoordinateSystem(Point.MakePointWithInches(3, 1, 2), Angle.RightAngle / 2, Angle.ZeroAngle, Angle.StraightAngle);
            (results2 == expectedSystem2).Should().BeTrue();
        }
 /// <summary>
 /// Shifts this PlaneRegion by generically shifting each edge in the PlaneRegion
 /// </summary>
 public new PlaneRegion Shift(Shift shift)
 {
     return new PlaneRegion(this._Edges.Select(e => e.Shift(shift)).ToList());
 }
        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);
        }
 public static List<ISurface> Shift(this List<ISurface> surfaces, Shift shift)
 {
     return surfaces.Select(s => s.Shift(shift)).ToList();
 }
 public static List<Point> Shift(this List<Point> pointList, Shift shift)
 {
     return pointList.Select(p => p.Shift(shift)).ToList();
 }
 /// <summary>
 /// Creates a local coordinate system that is only translated from the World Coordinates.
 /// </summary>
 public CoordinateSystem(Point passedTranslationToOrigin)
 {
     this.ShiftFromThisToWorld = new Shift(passedTranslationToOrigin);
 }
        public void CoordinateSystem_Demo_ShiftingCoordinateSystems()
        {
            //This test demonstrates how you would shift a coordinate system and the difference between a Shift and a RelativeShift as well as giving examples of when each would be used.

            //set up pur lego set and our lego blocks
            LegoSet testSet = new LegoSet();
            CoordinateSystem LegoSetSystem = new CoordinateSystem(Point.MakePointWithInches(3, -2, -2), Angle.ZeroAngle, Angle.ZeroAngle, Angle.RightAngle / 2);
            testSet.SetSystem = LegoSetSystem;

            CURRENT_COORDINATE_SYSTEM = new CoordinateSystem(LegoSetSystem);

            //make block1 on top of block 2
            CoordinateSystem block1SystemRelativeToLegoSet = new CoordinateSystem(Point.MakePointWithInches(-2, 1, 2), Angle.ZeroAngle, Angle.ZeroAngle, -1 * Angle.RightAngle);
            CoordinateSystem block2SystemRelativeToLegoSet = new CoordinateSystem(Point.MakePointWithInches(-2, 1, 1), Angle.ZeroAngle, Angle.ZeroAngle, -1 * Angle.RightAngle);
            LegoBlock block1 = createBlockInGivenCoordinateSystem(new Distance(new Inch(), 4), new Distance(new Inch(), 2), new Distance(new Inch(), 1), block1SystemRelativeToLegoSet);
            LegoBlock block2 = createBlockInGivenCoordinateSystem(new Distance(new Inch(), 4), new Distance(new Inch(), 2), new Distance(new Inch(), 1), block2SystemRelativeToLegoSet);

            testSet.Blocks = new List<LegoBlock>() { block1, block2 };

            //Show how RelativeShift works
            //RelativeShift should be used when the shift is created for the current system and not for the world system and if you want to shif the object in the current system
            //lets say we want to rotate the block2 -90 degrees z in the sets system(CURRENT_SYSTEM) and its origin point
            Shift shiftBlocks90 = new Shift(new Rotation(new Line(Direction.Out, Point.MakePointWithInches(-2, 1, 1)), -1 * Angle.RightAngle));

            //shift only the ones we want to in the list of blocks
            block2.Geometry = block2.Geometry.Shift(shiftBlocks90);
            block2.BlockSystem = block2.BlockSystem.RelativeShift(shiftBlocks90, CURRENT_COORDINATE_SYSTEM);

            //show its where we want relatvie to the set
            (block2.Geometry == _makeExpectedBlock2Shifted90InSetSystem()).Should().BeTrue();

            //now check that the coordinate system places it where it should be by shifting the block to its home coords
            Polyhedron shiftedBlock2ToHome = block2.Geometry.Shift(block2.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM)); //this shows the coordinate systme was shifted right
            (shiftedBlock2ToHome == _makeExpectedBlockInLocal()).Should().BeTrue();

            //now we desicded we want block2 on top of block1 and have it so the 2 length dimensions overlap(move in block1s local y)
            //This is how we would do that (note: we dont edit the coordinate systems when changing current coordinates)
            block1.Geometry = block1.Geometry.Shift(block1.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM));
            block2.Geometry = block2.Geometry.Shift(block1.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM));
            CURRENT_COORDINATE_SYSTEM = block1.BlockSystem;

            //now make the shift in the block1 coordinates to apply to block 2
            Shift shiftBlock2OnTop = new Shift(Point.MakePointWithInches(0, 2, 2));
            block2.Geometry = block2.Geometry.Shift(shiftBlock2OnTop);
            block2.BlockSystem = block2.BlockSystem.RelativeShift(shiftBlock2OnTop, CURRENT_COORDINATE_SYSTEM);

            //show its where we want in the the set system
            (block2.Geometry.Shift(CURRENT_COORDINATE_SYSTEM.ShiftFromThisTo(LegoSetSystem)) == _makeExpectedBlock2ShiftedOnBlock1InSetSystem()).Should().BeTrue();

            //now check its geometry in local again
            shiftedBlock2ToHome = block2.Geometry.Shift(block2.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM)); //this shows the coordinate systme was shifted right
            (shiftedBlock2ToHome == _makeExpectedBlockInLocal()).Should().BeTrue();


            //Now what if we want to move the whole set 2 in the x and rotate it so its at 45 degees z around the setSystem origin?
            //note: this is the same effect as RealtiveShift(shift, WorldCoordinateSystem)

            //Switch the coordinate systems to world
            //note: we dont edit the coordinate systems when changing current coordinates
            block1.Geometry = block1.Geometry.Shift(CoordinateSystem.WorldCoordinateSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM));
            block2.Geometry = block2.Geometry.Shift(CoordinateSystem.WorldCoordinateSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM));
            CURRENT_COORDINATE_SYSTEM = CoordinateSystem.WorldCoordinateSystem;

            //These Shifts will only work correctly when they are in the CURRENT_COORDINATE_SYSTEM
            //(presumabley in the legoSet.Shift() function)
            Shift shiftWholeSet = new Shift(new Rotation(new Line(Direction.Out, testSet.SetSystem.TranslationToOrigin), Angle.RightAngle / 2), Point.MakePointWithInches(2, 0, 0));
            testSet.SetSystem = testSet.SetSystem.Shift(shiftWholeSet);

            //check the coords because we dont hav a geomtry for this - its a collection
            (testSet.SetSystem == new CoordinateSystem(Point.MakePointWithInches(5, -2, -2), Angle.ZeroAngle, Angle.ZeroAngle, Angle.RightAngle)).Should().BeTrue();

            //shift the pieces in the collection (also presumably in the LegoSet.Shift() method)
            block1.Geometry = block1.Geometry.Shift(shiftWholeSet);
            block1.BlockSystem = block1.BlockSystem.Shift(shiftWholeSet);
            block2.Geometry = block2.Geometry.Shift(shiftWholeSet);
            block2.BlockSystem = block2.BlockSystem.Shift(shiftWholeSet);

            //show its where we want in the world
            Polyhedron block1InWorld = block1.Geometry.Shift(CURRENT_COORDINATE_SYSTEM.ShiftFromThisTo());
            Polyhedron block2InWorld = block2.Geometry.Shift(CURRENT_COORDINATE_SYSTEM.ShiftFromThisTo());
            (block1InWorld == _makeExpectedBlock1ShiftedInWorld()).Should().BeTrue();
            (block2InWorld == _makeExpectedBlock2ShiftedInWorld()).Should().BeTrue();

            //now check that the coordinate system places it where it should be by shifting the blocks to their home coords
            Polyhedron shiftedBlock1ToHome = block1.Geometry.Shift(block1.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM)); //this shows the coordinate systme was shifted right
            (shiftedBlock1ToHome == _makeExpectedBlockInLocal()).Should().BeTrue();
            shiftedBlock2ToHome = block2.Geometry.Shift(block2.BlockSystem.ShiftToThisFrom(CURRENT_COORDINATE_SYSTEM)); //this shows the coordinate systme was shifted right
            (shiftedBlock2ToHome == _makeExpectedBlockInLocal()).Should().BeTrue();

        }
 /// <summary>
 /// Shifts this system which is based on the world system with a shift that is relative to (in terms of) the passed system.
 /// This shifts this system relative to the world system with the equivalent of the shift in terms of the world system.
 /// ".Shift()" can be viewed as a special case of this relative shift where the system the shift is in terms of happens to be the world system
 /// </summary>
 /// <param name="passedShift">The shift that is based on the passed system to apply to this system</param>
 /// <param name="systemShiftIsRelativeTo">The system the shift is based in/ in terms of/ relative to</param>
 /// <returns>Returns a new CoordinateSystem that is based on the world system and has been shifted with the equivalent of the passed shift put in terms of world system</returns>
 public CoordinateSystem RelativeShift(Shift passedShift, CoordinateSystem systemShiftIsRelativeTo)
 {
     if (systemShiftIsRelativeTo == null)
     {
         systemShiftIsRelativeTo = WorldCoordinateSystem;
     }
     //change the coordinate system so that it is in terms of the current system so we can shift it relative to that system and 
     //then we need to shift it so its back on the worldCoordinates
     CoordinateSystem inCurrent = this.Shift(systemShiftIsRelativeTo.ShiftFromThisToWorld.Inverse());
     CoordinateSystem shiftedInCurrent = inCurrent.Shift(passedShift);
     //now put it back in terms of the world and return it
     return shiftedInCurrent.Shift(WorldCoordinateSystem.ShiftToThisFrom(systemShiftIsRelativeTo));
 }
 public CoordinateSystem(Shift shift)
 {
     this.ShiftFromThisToWorld = shift;
 }
 /// <summary>
 /// This shifts the coordinate system relative to the world system with the given shift
 /// </summary>
 public CoordinateSystem Shift(Shift passedShift)
 {
    return new CoordinateSystem(passedShift.Compose(this.ShiftFromThisToWorld));
 }
 /// <summary>
 /// Creates a copy of the given coordinate system
 /// </summary>
 /// <param name="toCopy">the Coordinate System to copy</param>
 public CoordinateSystem(CoordinateSystem toCopy)
 {
     this.ShiftFromThisToWorld = new Shift(toCopy.ShiftFromThisToWorld);
 }
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="passedOrigin">The origin point of this coordinate system in reference to the world coordinate system</param>
        //public CoordinateSystem(Plane planeContainingTwoOfTheAxes, Vector axisInPassedPlaneToUseAsBase,
        //    Enums.Axis whichAxisIsPassed = Enums.Axis.X, Enums.AxisPlanes whichAxisPlaneIsPassed = Enums.AxisPlanes.XYPlane)
        //{

        //    //make sure the passed vector is in our plane
        //    if (!planeContainingTwoOfTheAxes.Contains(axisInPassedPlaneToUseAsBase))
        //    {
        //        throw new ArgumentOutOfRangeException("the passed axis was not in the plane");
        //    }

        //    Vector xAxis = new Vector(Point.Origin);
        //    Vector yAxis = new Vector(Point.Origin);
        //    Vector zAxis = new Vector(Point.Origin);

        //    //Vector normalAxis = new Vector(axisInPassedPlaneToUseAsBase.BasePoint, planeContainingTwoOfTheAxes.NormalVector.Direction, new Distance(new Inch(), 1));

        //    //Vector otherAxis;

        //    switch (whichAxisPlaneIsPassed)
        //    {
        //        case Enums.AxisPlanes.XYPlane:
        //            zAxis = new Vector(axisInPassedPlaneToUseAsBase.BasePoint, planeContainingTwoOfTheAxes.NormalVector.Direction, new Distance(new Inch(), 1));
        //            switch (whichAxisIsPassed)
        //            {
        //                //if its the x we were given the one we calculate is the y, so we want it 90 degrees (to the left)
        //                case Enums.Axis.X:
        //                    xAxis = axisInPassedPlaneToUseAsBase;
        //                    yAxis = zAxis.CrossProduct(xAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, Angle.RightAngle);
        //                    break;
        //                //if its the y we were the the y axis and we need to calculate the x which will be -90 degrees (to the right)
        //                case Enums.Axis.Y:
        //                    yAxis = axisInPassedPlaneToUseAsBase;
        //                    xAxis = yAxis.CrossProduct(zAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, -1 * Angle.RightAngle);
        //                    break;
        //                //the axis must be in the plane we were passed
        //                case Axis.Z:
        //                    throw new ArgumentOutOfRangeException("the passed axis type was not in the plane type");
        //            }
        //            break;
        //        case Enums.AxisPlanes.XZPlane:
        //            yAxis = new Vector(axisInPassedPlaneToUseAsBase.BasePoint, planeContainingTwoOfTheAxes.NormalVector.Direction, new Distance(new Inch(), 1));
        //            switch (whichAxisIsPassed)
        //            {
        //                //if its the x we were passed then we need to calculate z, which will be -90 degrees (to the right)
        //                case Enums.Axis.X:
        //                    xAxis = axisInPassedPlaneToUseAsBase;
        //                    zAxis = xAxis.CrossProduct(yAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, -1 * Angle.RightAngle);
        //                    break;
        //                //the axis must be in the plane we were passed
        //                case Enums.Axis.Y:
        //                    throw new ArgumentOutOfRangeException("the passed axis type was not in the plane type");
        //                //if its the z we were passed then we need to calculate x, which will be 90 degrees (to the left)
        //                case Axis.Z:
        //                    zAxis = axisInPassedPlaneToUseAsBase;
        //                    xAxis = yAxis.CrossProduct(zAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, Angle.RightAngle);
        //                    break;
        //            }
        //            break;
        //        case Enums.AxisPlanes.YZPlane:
        //            xAxis = new Vector(axisInPassedPlaneToUseAsBase.BasePoint, planeContainingTwoOfTheAxes.NormalVector.Direction, new Distance(new Inch(), 1));
        //            switch (whichAxisIsPassed)
        //            {
        //                //the axis must be in the plane we were passed
        //                case Enums.Axis.X:
        //                    throw new ArgumentOutOfRangeException("the passed axis type was not in the plane type");
        //                //if it is the Y axis then we need to find the z, which is 90 degrees (to the left)
        //                case Enums.Axis.Y:
        //                    yAxis = axisInPassedPlaneToUseAsBase;
        //                    zAxis = xAxis.CrossProduct(yAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, Angle.RightAngle);
        //                    break;
        //                //if it is the Z axis then we need to find the y, which is -90 degrees (to the right)
        //                case Axis.Z:
        //                    zAxis = axisInPassedPlaneToUseAsBase;
        //                    yAxis = zAxis.CrossProduct(xAxis);
        //                    //otherAxis = axisInPassedPlaneToUseAsBase.Rotate(new Rotation(planeContainingTwoOfTheAxes.NormalVector, -1 * Angle.RightAngle);
        //                    break;
        //            }
        //            break;
        //    }

        //    //we found our axes, now we can determine the angles from them
        //    //Since we rotate in the order Z, X, then Y, we must find the angles in the reverse order
        //    //i.e. y first, then x then z

        //    //if we find line up the z axis in the YZ plane with the y rotation, then we can rotate it around the x axis to make the z axes line up
        //    //and then we can z rotate to make the x and y coincide with the origins

        //    //first make them into unitvectors to simplify the calculations
        //    xAxis = xAxis.Direction*Inch;
        //    yAxis = yAxis.Direction*Inch;
        //    zAxis = zAxis.Direction*Inch;

        //    //now first find out the amount we need to rotate around the y axis to line up z in the yz plane

        //    //First project the z axis onto the xz plane
        //    Line projectedZAxis = ((Line)zAxis).ProjectOntoPlane(new Plane(Line.XAxis, Line.ZAxis));

        //    //then use the projected Line to find out how far we need to rotate in the Y direction to line up the z axes in the YZplane
        //    Angle angleBetweenCurrentZAndYZPlane = projectedZAxis.Direction.Theta;

        //    //if the projection is in the negative x direction we need to rotate negitively(clockwise) instead of positivly
        //    if (projectedZAxis.Direction.XComponent > 0)
        //    {
        //        angleBetweenCurrentZAndYZPlane = angleBetweenCurrentZAndYZPlane.Negate();
        //    }

        //    //http://www.vitutor.com/geometry/distance/line_plane.html
        //    //we can simplify the equation as this since it is unit vectors
        //    //sin(angle to plane) = z * planeNormal (which is the x axis by definition)
        //    //Distance dotProductOfZAndNormal = zAxis * Line.XAxis.UnitVector(new Inch());
        //    //Angle angleBetweenCurrentZAndYZPlane = new Angle(new Radian(), Math.Asin(dotProductOfZAndNormal.ValueInInches));

        //    //now rotate the axis (we only need to do z and x since we are done with y now)
        //    xAxis = xAxis.Rotate(new Rotation(Line.YAxis, angleBetweenCurrentZAndYZPlane));
        //    zAxis = zAxis.Rotate(new Rotation(Line.YAxis, angleBetweenCurrentZAndYZPlane));

        //    //now find out how much we need to rotate it in the x direction to line up z in the xz plane (meaning now z will be aligned with the world z)
        //    Angle angleBetweenZAndZAxis = zAxis.Direction.Theta;

        //    //now we need to rotate the x axis so we can line it up (the y and z we are done with)
        //    //if its negative we need to rotate it clockwise (negative) instead of ccw (positive)
        //    if (zAxis.Direction.YComponent < 0)
        //    {
        //        angleBetweenZAndZAxis = angleBetweenZAndZAxis.Negate();
        //    }

        //    //finally find out the z rotation needed to line up the x axis with the xz plane (this also forces the y to be lined up)
        //    xAxis = xAxis.Rotate(new Rotation(Line.XAxis, angleBetweenZAndZAxis));
        //    Angle angleBetweenXAndXAxis = xAxis.Direction.Phi;

        //    //now we know all our angles, but we have to take the negative of them because we were transforming back to
        //    //the origin and we store the tranform from the origin
        //    var _xAxisRotationAngle = angleBetweenZAndZAxis.Negate();
        //    var _yAxisRotationAngle = angleBetweenCurrentZAndYZPlane.Negate();
        //    var _zAxisRotationAngle = angleBetweenXAndXAxis.Negate();

        //    var rotationX = new Rotation(Line.XAxis, _xAxisRotationAngle);
        //    var rotationY = new Rotation(Line.YAxis, _yAxisRotationAngle);
        //    var rotationZ = new Rotation(Line.ZAxis, _zAxisRotationAngle);
        //    this.ShiftFromThisToWorld = new Shift(new List<Rotation>() { rotationX, rotationY, rotationZ }, axisInPassedPlaneToUseAsBase.BasePoint);
        //}

        /// <summary>
        /// Creates a new coordinate system with the given origin point and with the given rotations.
        /// The inputs are extrinsic angle, i.e. about the global axes
        /// </summary>
        /// <param name="passedTranslationToOrigin">The origin point of this coordinate system in reference to the world coordinate system</param>
        /// <param name="passedXAxisRotation">The rotation around the world coordinate system's X axis to rotate around to get to this
        /// coordinate system</param>
        /// <param name="passedYAxisRotation">The rotation around the world coordinate system's Y axis to rotate around to get to this
        /// coordinate system</param>
        /// <param name="passedZAxisRotation">The rotation around the world coordinate system's Z axis to rotate around to get to this
        /// coordinate system</param>
        public CoordinateSystem(Point translationToOrigin, Angle xAxisRotationAngle,
            Angle yAxisRotationAngle, Angle zAxisRotationAngle)
        {
            var rotationX = new Rotation(Line.XAxis, xAxisRotationAngle);
            var rotationY = new Rotation(Line.YAxis, yAxisRotationAngle);
            var rotationZ = new Rotation(Line.ZAxis, zAxisRotationAngle);
            this.ShiftFromThisToWorld = new Shift(new List<Rotation>() { rotationX, rotationY, rotationZ }, translationToOrigin);
        }
        public void CoordinateSystem_Shift_NotThroughOrigin()
        {
            CoordinateSystem testSystem1 = new CoordinateSystem(Point.MakePointWithInches(1, 2, 3), Angle.RightAngle, Angle.ZeroAngle, Angle.ZeroAngle);
            Shift testShift1 = new Shift(new Rotation(new Line(new Direction(Direction.Out), Point.MakePointWithInches(1, 4, 0)), Angle.StraightAngle));
            CoordinateSystem results1 = testSystem1.Shift(testShift1);
            CoordinateSystem expectedSystem1 = new CoordinateSystem(Point.MakePointWithInches(1, 6, 3), Angle.RightAngle, Angle.ZeroAngle, Angle.StraightAngle);
            (results1 == expectedSystem1).Should().BeTrue();

            //now try another
            CoordinateSystem testSystem2 = new CoordinateSystem(Point.MakePointWithInches(-1, 0, 2), Angle.ZeroAngle, Angle.ZeroAngle, Angle.RightAngle / 2);
            Shift testShift2 = new Shift(new Rotation(new Line(new Direction(Direction.Up), Point.MakePointWithInches(0, 0, 2)), Angle.RightAngle), Point.MakePointWithInches(2, -1, -1));
            CoordinateSystem results2 = testSystem2.Shift(testShift2);
            CoordinateSystem expectedSystem2 = new CoordinateSystem(Point.MakePointWithInches(2, -1, 2), Angle.RightAngle, Angle.RightAngle / 2, Angle.RightAngle);
            (results2 == expectedSystem2).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();

        }
        public void CoordinateSystem_RelativeShift()
        {
            //a nice simple test
            CoordinateSystem testOriginalCoords = CoordinateSystem.WorldCoordinateSystem;
            CoordinateSystem testCurrentSystem = new CoordinateSystem(Point.MakePointWithInches(1, 0, -1), Angle.ZeroAngle, Angle.ZeroAngle, new Angle(Angle.RightAngle/2));

            //now shift it a bit
            CoordinateSystem shifted = testOriginalCoords.RelativeShift(new Shift(Point.MakePointWithInches(2, 0, 1)), testCurrentSystem);
            CoordinateSystem expected = new CoordinateSystem(Point.MakePointWithInches(1.4, 1.4, 1));
            (shifted == expected).Should().BeTrue();

            //now do one with more complicated shifts
            CoordinateSystem secondTest = new CoordinateSystem(Point.MakePointWithInches(2, -3, 3), Angle.RightAngle, Angle.ZeroAngle, Angle.ZeroAngle);
            CoordinateSystem testCurrentSystem2 = new CoordinateSystem(Point.MakePointWithInches(1, 0, -1), Angle.ZeroAngle, Angle.ZeroAngle, Angle.RightAngle);

            Shift secondShift = new Shift(new Rotation(Line.XAxis, Angle.RightAngle), Point.MakePointWithInches(2, -2, -2));
            CoordinateSystem shifted2 = secondTest.RelativeShift(secondShift, testCurrentSystem2);

            CoordinateSystem expected2 = new CoordinateSystem(Point.MakePointWithInches(7, -1, -4), Angle.RightAngle, Angle.RightAngle, Angle.ZeroAngle);
            (shifted2 == expected2).Should().BeTrue();
        }
 private static Shift GetRotation(Direction normal)
 {
     if (normal.IsParallelTo(Direction.Out))
     {
         return Rotation.Identity;
     }
     var angle = normal.AngleBetween(Direction.Out);
     var axis = new Line(normal.CrossProduct(Direction.Out));
     var rotation = new Shift(new Rotation(axis, angle));
     return rotation;
 }
        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());
        }
 /// <summary>
 /// Shifts the List of LineSegments with the given shift
 /// </summary>
 /// <param name="lineSegments">The List of Line Segments to Shift</param>
 /// <param name="passedShift">the Shift to apply to the List of LineSegmnets</param>
 /// <returns>a new List of LineSegmnets that have been shifted with the given shift</returns>
 public static List<LineSegment> Shift(this IEnumerable<LineSegment> lineSegments, Shift shift)
 {
     return lineSegments.Select(s => s.Shift(shift)).ToList();
 }
Пример #27
0
        public void Arc_Shift()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(3, 3, 4.24264);
            Direction directionAtStart = new Direction(Point.MakePointWithInches(1, 1, 0));

            Arc testArc = new Arc(basePoint, endPoint, directionAtStart);

            Shift testShift = new Shift(new Rotation(Line.ZAxis, Angle.RightAngle / 2), Point.MakePointWithInches(-3, 0.25, -2));
            Arc results = testArc.Shift(testShift);

            Arc expected = new Arc(Point.MakePointWithInches(-3, 0.25, -2), Point.MakePointWithInches(0 - 3, 4.24264 + 0.25, 4.24264 - 2), Direction.Up);

            (results == expected).Should().BeTrue();
        }
        /// <summary>
        /// Translate the List of Plane Regions with the given translation
        /// </summary>
        //public static List<PlaneRegion> Translate(this IList<PlaneRegion> planeRegions, Point translation)
        //{
        //    return planeRegions.Select(p => p.Translate(translation)).ToList();
        //}

        /// <summary>
        /// Shifts the list of plane regions with the given Shift
        /// </summary>
        public static List<PlaneRegion> Shift(this List<PlaneRegion> planeRegions, Shift shift)
        {
            return planeRegions.Select(p => p.Shift(shift)).ToList();
        }
        public void LineSegment_Shift_ShouldShiftAsVector()
        {
            LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1));
            Shift shift1 = new Shift(new Vector(Point.MakePointWithInches(0, 1, 0)));
            Shift shift2 = new Shift(new Vector(Point.MakePointWithInches(2, 0, 3)));

            Shift shift3 = Shift.Compose(shift1, shift2);

            lineSegment.Shift(shift3).Should().Be(new LineSegment(Point.MakePointWithInches(2, 1, 3), Point.MakePointWithInches(3, 2, 4)));
        }
        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);
        }