public ShiftFromThisTo ( |
||
systemToShiftTo | The CoordinateSystem to shift to from this CoordinateSystem. Defaults to the WorldCoordinateSystem if left out | |
리턴 |
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 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_UndoShift() { CoordinateSystem system = new CoordinateSystem(Point.MakePointWithInches(-1, 2, 4), new Angle(new Degree(), 123), new Angle(new Degree(), -22), new Angle(new Degree(), 78)); 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.ShiftToThisFrom()); Polygon shifted2 = shifted.Shift(system.ShiftFromThisTo()); testPolygon.Should().Be(shifted2); }
private LegoBlock createBlockInGivenCoordinateSystem(Distance xDimension, Distance yDimension, Distance zDimension, CoordinateSystem blocksCoordinateSystem) { LegoBlock toReturn = new LegoBlock(); //make our geometry Point basePoint = Point.Origin; Point topLeftPoint = new Point(Distance.ZeroDistance, yDimension, Distance.ZeroDistance); Point bottomRightPoint = new Point(xDimension, Distance.ZeroDistance, Distance.ZeroDistance); Point topRightPoint = new Point(xDimension, yDimension, Distance.ZeroDistance); Point backBasePoint = new Point(Distance.ZeroDistance, Distance.ZeroDistance, zDimension); Point backTopLeftPoint = new Point(Distance.ZeroDistance, yDimension, zDimension); Point backBottomRightPoint = new Point(xDimension, Distance.ZeroDistance, zDimension); Point backTopRightPoint = new Point(xDimension, yDimension, zDimension); List<Polygon> planes = new List<Polygon>(); planes.Add(new Polygon(new List<Point> { basePoint, topLeftPoint, topRightPoint, bottomRightPoint })); planes.Add(new Polygon(new List<Point> { backBasePoint, backTopLeftPoint, backTopRightPoint, backBottomRightPoint })); planes.Add(new Polygon(new List<Point> { topLeftPoint, topRightPoint, backTopRightPoint, backTopLeftPoint })); planes.Add(new Polygon(new List<Point> { basePoint, bottomRightPoint, backBottomRightPoint, backBasePoint })); planes.Add(new Polygon(new List<Point> { basePoint, topLeftPoint, backTopLeftPoint, backBasePoint })); planes.Add(new Polygon(new List<Point> { bottomRightPoint, topRightPoint, backTopRightPoint, backBottomRightPoint })); toReturn.Geometry = new Polyhedron(planes); //now figure out is base coordinate system relative to the world and store it toReturn.BlockSystem = blocksCoordinateSystem.FindThisSystemRelativeToWorldSystemCurrentlyRelativeToPassedSystem(CURRENT_COORDINATE_SYSTEM); //now move it so it is in ouur current coordinate system toReturn.Geometry = toReturn.Geometry.Shift(blocksCoordinateSystem.ShiftFromThisTo()); //then return it return toReturn; }
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(); }
public void Shift_ShiftPolygonFromCoordinateSystem() { CoordinateSystem system = new CoordinateSystem(Point.MakePointWithInches(0, 1, 0), Angle.RightAngle / 2, new Angle(new Degree(), -45), Angle.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.ShiftFromThisTo()); 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); }