public static Polygon Overlap(Polygon polygon1, Polygon polygon2) { if (polygon1.IsCoplanarTo(polygon2).Not()) { return null; } var normal = polygon1.NormalDirection; var rotation = GetRotation(normal); var rotated1 = polygon1.Vertices.Shift(rotation); var rotated2 = polygon2.Vertices.Shift(rotation); var overlapped = Overlap_In_XY_Plane(rotated1, rotated2); if (overlapped.IsNull()) { return null; } overlapped = RemovePointsTooCloseToEachOther(overlapped); var depth = rotated1[0].Z; var shiftBack = Shift.ComposeLeftToRight(depth*Direction.Out, rotation.Inverse()); return new Polygon(overlapped.Shift(shiftBack)); }
private static List<Polygon> _makeFaces() { Point basePoint1 = Point.MakePointWithInches(0, 0, -1); Point basePoint2 = Point.MakePointWithInches(2, 0, -1); Point basePoint3 = Point.MakePointWithInches(2, 2, -1); Point basePoint4 = Point.MakePointWithInches(0, 2, -1); Point basePoint5 = Point.MakePointWithInches(1, 1, -1); Point topPoint1 = Point.MakePointWithInches(0, 0, 5); Point topPoint2 = Point.MakePointWithInches(2, 0, 5); Point topPoint3 = Point.MakePointWithInches(2, 2, 5); Point topPoint4 = Point.MakePointWithInches(0, 2, 5); Point topPoint5 = Point.MakePointWithInches(1, 1, 5); Polygon bottomFace = new Polygon(new List<Point> { basePoint1, basePoint2, basePoint3, basePoint4, basePoint5 }); Polygon topFace = new Polygon(new List<Point> { topPoint1, topPoint2, topPoint3, topPoint4, topPoint5 }); Polygon sideFace1 = new Polygon(new List<Point> { basePoint1, basePoint2, topPoint2, topPoint1 }); Polygon sideFace2 = new Polygon(new List<Point> { basePoint2, basePoint3, topPoint3, topPoint2 }); Polygon sideFace3 = new Polygon(new List<Point> { basePoint3, basePoint4, topPoint4, topPoint3 }); Polygon sideFace4 = new Polygon(new List<Point> { basePoint4, basePoint5, topPoint5, topPoint4 }); Polygon sideFace5 = new Polygon(new List<Point> { basePoint5, basePoint1, topPoint1, topPoint5 }); List<Polygon> faces = new List<Polygon>(); faces.Add(bottomFace); faces.Add(topFace); faces.Add(sideFace1); faces.Add(sideFace2); faces.Add(sideFace3); faces.Add(sideFace4); faces.Add(sideFace5); return faces; }
public Member(Lumber lumberType, MemberType memberType, Polygon geometry, string name = "") { this.MemberType = memberType; this.Lumber = lumberType; this.Geometry = geometry; this.Name = name; }
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(); }
/// <summary> /// Returns whether or not the polygon has a common side with any of the polygons in this list /// </summary> /// <param name="polygonsList">The List of Polygons to check if the passed polygon shares a side with</param> /// <param name="polygonToCheckSidesOf">The polygon to see if any of the polygons in this list share a side with</param> /// <returns>Returns a bool of whether or not the Polyhedron has a common side with the polygon</returns> public static bool DoesShareSideWithPolygonInList(this List<Polygon> polygonsList, Polygon polygonToCheckSidesOf) { foreach (Polygon polygon in polygonsList) { if (polygonToCheckSidesOf.DoesShareExactSide(polygon)) { return true; } } return false; }
private static Polygon newConcavePentagon() { Point point1 = Point.MakePointWithInches(0, 0, -1); Point point2 = Point.MakePointWithInches(2, 0, -1); Point point3 = Point.MakePointWithInches(2, 2, -1); Point point4 = Point.MakePointWithInches(0, 2, -1); Point point5 = Point.MakePointWithInches(1, 1, -1); Polygon concavePentagon = new Polygon(new List<Point> { point1, point2, point3, point4, point5 }); return concavePentagon; }
public void Plane_ContainsPolygon() { Plane testPlane = new Plane(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(1, -3, 4), Point.MakePointWithInches(1, 2, 2)); Polygon testRegion = new Polygon(new List<Point> { Point.MakePointWithInches(1,1,1), Point.MakePointWithInches(1,2,1), Point.MakePointWithInches(1,2,2), Point.MakePointWithInches(1,1,2) }); bool result = testPlane.Contains(testRegion); result.Should().BeTrue(); }
public void Polygon_Constructor_NoSelfIntersections() { Point point1 = Point.MakePointWithInches(0, 0); Point point2 = Point.MakePointWithInches(1, 0); Point point3 = Point.MakePointWithInches(1, 1); Point point4 = Point.MakePointWithInches(0, 1); List<Point> verticesInCorrectOrder = new List<Point>() { point1, point2, point3, point4 }; List<Point> verticesInWrongOrder = new List<Point>() { point1, point2, point4, point3 }; Polygon correctPolygon = new Polygon(verticesInCorrectOrder); Area area = correctPolygon.Area; area.Should().Be(new Area(new SquareInch(), 1)); Assert.Throws<InvalidPolygonException>(() => new Polygon(verticesInWrongOrder)); }
public void Polygon_Extrude() { Point basePoint = Point.Origin; Point topLeftPoint = Point.MakePointWithInches(0, 4, 0); Point bottomRightPoint = Point.MakePointWithInches(8, 0, 0); Point topRightPoint = Point.MakePointWithInches(8, 4, 0); Point backbasepoint = Point.MakePointWithInches(0, 0, -4); Point backtopleftpoint = Point.MakePointWithInches(0, 4, -4); Point backbottomrightpoint = Point.MakePointWithInches(8, 0, -4); Point backtoprightpoint = Point.MakePointWithInches(8, 4, -4); LineSegment left = new LineSegment(basePoint, topLeftPoint); LineSegment right = new LineSegment(bottomRightPoint, topRightPoint); LineSegment top = new LineSegment(topLeftPoint, topRightPoint); LineSegment bottom = new LineSegment(basePoint, bottomRightPoint); LineSegment backLeft = new LineSegment(backbasepoint, backtopleftpoint); LineSegment backRight = new LineSegment(backbottomrightpoint, backtoprightpoint); LineSegment backTop = new LineSegment(backtopleftpoint, backtoprightpoint); LineSegment backBottom = new LineSegment(backbasepoint, backbottomrightpoint); LineSegment topleftConnector = new LineSegment(topLeftPoint, backtopleftpoint); LineSegment toprightConnector = new LineSegment(topRightPoint, backtoprightpoint); LineSegment baseConnector = new LineSegment(basePoint, backbasepoint); LineSegment bottomRightConnector = new LineSegment(bottomRightPoint, backbottomrightpoint); Polygon frontRegion = new Polygon(new List<LineSegment> { left, top, bottom, right }); Polygon backRegion = new Polygon(new List<LineSegment> { backLeft, backRight, backTop, backBottom }); Polygon topRegion = new Polygon(new List<LineSegment> { top, backTop, topleftConnector, toprightConnector }); Polygon bottomRegion = new Polygon(new List<LineSegment> { bottom, backBottom, baseConnector, bottomRightConnector }); Polygon leftRegion = new Polygon(new List<LineSegment> { left, backLeft, baseConnector, topleftConnector }); Polygon rightRegion = new Polygon(new List<LineSegment> { right, backRight, toprightConnector, bottomRightConnector }); Polyhedron extrudedResult = frontRegion.Extrude(new Vector(Point.MakePointWithInches(0, 0, -4))); extrudedResult.Polygons.Contains(frontRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(backRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(topRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(bottomRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(leftRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(rightRegion).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 Shift_TranslateUsingToCoordinateSystem() { CoordinateSystem system = new CoordinateSystem(Point.MakePointWithInches(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.ShiftToThisFrom()); 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() { 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); }
public void Polygon_RotateAndRoundTest_Orthogonal() { List<LineSegment> lineSegments = new List<LineSegment>(); lineSegments.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(8, 0, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(8, 0, 0), Point.MakePointWithInches(8, 4, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(8, 4, 0), Point.MakePointWithInches(0, 4, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(0, 4, 0), Point.Origin)); Polygon testPolygon = new Polygon(lineSegments); Line rotationAxis = new Line(Point.MakePointWithInches(1, 0, 0)); //This is the X axis Angle rotationAngle = Angle.RightAngle; Polygon actualPolygon = testPolygon.Rotate(new Rotation(rotationAxis, rotationAngle)); List<LineSegment> expectedLineSegments = new List<LineSegment>(); expectedLineSegments.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(8, 0, 0))); expectedLineSegments.Add(new LineSegment(Point.MakePointWithInches(8, 0, 0), Point.MakePointWithInches(8, 0, 4))); expectedLineSegments.Add(new LineSegment(Point.MakePointWithInches(8, 0, 4), Point.MakePointWithInches(0, 0, 4))); expectedLineSegments.Add(new LineSegment(Point.MakePointWithInches(0, 0, 4), Point.Origin)); Polygon expectedPolygon = new Polygon(expectedLineSegments); (actualPolygon == expectedPolygon).Should().BeTrue(); }
public void PolygonList_FindPolygonsTouchingPlane() { List<LineSegment> lineSegments1 = new List<LineSegment>(); lineSegments1.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0))); lineSegments1.Add(new LineSegment(Point.MakePointWithInches(0, 2, 4), Point.MakePointWithInches(0, 2, 0))); lineSegments1.Add(new LineSegment(Point.MakePointWithInches(0, 2, 4), Point.MakePointWithInches(0, 0, 4))); lineSegments1.Add(new LineSegment(Point.MakePointWithInches(0, 0, 4), Point.Origin)); Polygon testPolygon1 = new Polygon(lineSegments1); List<LineSegment> lineSegments2 = new List<LineSegment>(); lineSegments2.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0))); lineSegments2.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.MakePointWithInches(0, 2, 0))); lineSegments2.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.MakePointWithInches(-3, 0, 0))); lineSegments2.Add(new LineSegment(Point.MakePointWithInches(-3, 0, 0), Point.Origin)); Polygon testPolygon2 = new Polygon(lineSegments2); List<LineSegment> lineSegments3 = new List<LineSegment>(); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(0, 0, 4), Point.MakePointWithInches(0, 2, 4))); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 4), Point.MakePointWithInches(0, 2, 4))); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 4), Point.MakePointWithInches(-3, 0, 4))); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(-3, 0, 4), Point.MakePointWithInches(0, 0, 4))); Polygon testPolygon3 = new Polygon(lineSegments3); List<Polygon> testList = new List<Polygon>() { testPolygon1, testPolygon2, testPolygon3}; Plane planeToCheck = Plane.XY; List<Polygon> touchedInclusive = testList.FindPolygonsTouchingPlane(planeToCheck, true); (touchedInclusive.Count == 2).Should().BeTrue(); touchedInclusive.Contains(testPolygon1).Should().BeTrue(); touchedInclusive.Contains(testPolygon2).Should().BeTrue(); List<Polygon> touchedExclusive = testList.FindPolygonsTouchingPlane(planeToCheck, false); (touchedExclusive.Count == 1).Should().BeTrue(); touchedExclusive.Contains(testPolygon1).Should().BeTrue(); }
private static List<Polygon> _makeFaces() { Point bottomPoint1 = Point.Origin; Point bottomPoint2 = Point.MakePointWithInches(0, 4, 0); Point bottomPoint3 = Point.MakePointWithInches(4, 4, 0); Point bottomPoint4 = Point.MakePointWithInches(4, 0, 0); Point middlePoint1 = Point.MakePointWithInches(1, 1, 5); Point middlePoint2 = Point.MakePointWithInches(1, 3, 5); Point middlePoint3 = Point.MakePointWithInches(3, 3, 5); Point middlePoint4 = Point.MakePointWithInches(3, 1, 5); Point topPoint1 = Point.MakePointWithInches(0, 0, 10); Point topPoint2 = Point.MakePointWithInches(0, 4, 10); Point topPoint3 = Point.MakePointWithInches(4, 4, 10); Point topPoint4 = Point.MakePointWithInches(4, 0, 10); Polygon bottomFace = new Polygon(new List<Point>() { bottomPoint1, bottomPoint2, bottomPoint3, bottomPoint4 }); Polygon topFace = new Polygon(new List<Point>() { topPoint1, topPoint2, topPoint3, topPoint4 }); Polygon bottomSideFace1 = new Polygon(new List<Point>() { bottomPoint1, bottomPoint2, middlePoint2, middlePoint1 }); Polygon bottomSideFace2 = new Polygon(new List<Point>() { bottomPoint2, bottomPoint3, middlePoint3, middlePoint2 }); Polygon bottomSideFace3 = new Polygon(new List<Point>() { bottomPoint3, bottomPoint4, middlePoint4, middlePoint3 }); Polygon bottomSideFace4 = new Polygon(new List<Point>() { bottomPoint4, bottomPoint1, middlePoint1, middlePoint4 }); Polygon topSideFace1 = new Polygon(new List<Point>() { topPoint1, topPoint2, middlePoint2, middlePoint1 }); Polygon topSideFace2 = new Polygon(new List<Point>() { topPoint2, topPoint3, middlePoint3, middlePoint2 }); Polygon topSideFace3 = new Polygon(new List<Point>() { topPoint3, topPoint4, middlePoint4, middlePoint3 }); Polygon topSideFace4 = new Polygon(new List<Point>() { topPoint4, topPoint1, middlePoint1, middlePoint4 }); return new List<Polygon>(){ bottomFace, topFace, bottomSideFace1, bottomSideFace2, bottomSideFace3, bottomSideFace4, topSideFace1, topSideFace2, topSideFace3, topSideFace4 }; }
public void Polygon_Centroid() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(-1, 5, 0))); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(-4, 2, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(-4, 2, 0), Point.MakePointWithInches(-5, 5, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(-1, 5, 0), Point.MakePointWithInches(-5, 5, 0))); Polygon testPolygon = new Polygon(bounds); Point center = testPolygon.Centroid; Point expected = Point.MakePointWithInches(-2.33, 3, 0); center.Should().Be(expected); //make sure the centroid is in the region testPolygon.Contains(center).Should().BeTrue(); //Note: The Centroid is always contained within the region of a convex polygon. //However, for concave polygons this is not the case.... List<LineSegment> lineSegments = new List<LineSegment>(); lineSegments.Add(new LineSegment(Point.MakePointWithInches(0, 2, 3), Point.MakePointWithInches(-3, -2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, -2, 0), Point.MakePointWithInches(1, 1, -1))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(1, 1, -1), Point.MakePointWithInches(0, 2, 3))); Polygon testPolygon2 = new Polygon(lineSegments); Point center2 = testPolygon2.Centroid; Point expected2 = Point.MakePointWithInches(-0.6666667, 0.33333333, 0.66666667); center2.Should().Be(expected2); //make sure the centroid is in the region testPolygon2.Contains(center2).Should().BeTrue(); }
private string PolygonString(Polygon polygon) { return $"Polygon.CreateInXYPlane(Distance.Inches, {Coordinates(polygon)})"; }
private static string Coordinates(Polygon polygon) { return string.Join(", ", polygon.Vertices .SelectMany(point => new[] { point.X.ValueInInches, point.Y.ValueInInches }) .Select(d => d.ToString())); }
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); }
public void Polygon_RemovePolygons_VM_6b() { //this will be a test of the top plate from VM_6b var point1=new Point(41*Distance.Inches, 25.874*Distance.Inches); var point2 = new Point(45 * Distance.Inches, 25.874 * Distance.Inches); var point3 = new Point(45 * Distance.Inches, 29.874 * Distance.Inches); var point4 = new Point(41 * Distance.Inches, 29.874 * Distance.Inches); var point5 = new Point(41.25 * Distance.Inches, 25.874 * Distance.Inches); var point6 = new Point(44.75 * Distance.Inches, 25.874 * Distance.Inches); var point7 = new Point(44.75 * Distance.Inches, 26.562 * Distance.Inches); var point8 = new Point(43 * Distance.Inches, 27.875 * Distance.Inches); var point9 = new Point(41.25 * Distance.Inches, 26.562 * Distance.Inches); var point10 = new Point(41 * Distance.Inches, 26.375 * Distance.Inches); var point11 = new Point(45 * Distance.Inches, 26.375 * Distance.Inches); var point12 = new Point(43 * Distance.Inches, 29.874 * Distance.Inches); var platePoints =new List<Point>(); platePoints.Add(point1); platePoints.Add(point2); platePoints.Add(point3); platePoints.Add(point4); var area1Points = new List<Point>(); area1Points.Add(point5); area1Points.Add(point6); area1Points.Add(point7); area1Points.Add(point8); area1Points.Add(point9); var area2Points = new List<Point>(); area2Points.Add(point10); area2Points.Add(point8); area2Points.Add(point12); area2Points.Add(point4); var area3Points = new List<Point>(); area3Points.Add(point8); area3Points.Add(point11); area3Points.Add(point3); area3Points.Add(point12); var area1 = new Polygon(area1Points); var area2 =new Polygon(area2Points); var area3 = new Polygon(area3Points); var plate = new Polygon(platePoints); var polygons = new List<Polygon>(); var plates = new List<Polygon>(); polygons.Add(area2); polygons.Add(area3); polygons.Add(area1); plates.Add(plate); var results = plate.RemoveOverlappingPolygons(polygons); results.Count.Should().Be(2); var leftover1points = new List<Point>(); leftover1points.Add(point2); leftover1points.Add(point11); leftover1points.Add(point7); leftover1points.Add(point6); var leftover1 = new Polygon(leftover1points); leftover1.Should().Be(results[0]); var leftover2points = new List<Point>(); leftover2points.Add(point1); leftover2points.Add(point5); leftover2points.Add(point9); leftover2points.Add(point10); var leftover2 =new Polygon(leftover2points); leftover2.Should().Be(results[1]); }
public void Polygon_SliceACaseThatDidntWorkBefore() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 3.5, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3.5, 0), Point.MakePointWithInches(240, 3.5, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 3.5, 0), Point.MakePointWithInches(240, 0, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon testPolygon = new Polygon(bounds); Plane slicingPlane = new Plane(new Direction(new Angle(new Radian(), 5.6548667765)), Point.MakePointWithInches(122.8315595, 169.313137732, 0)); List<Polygon> results = testPolygon.Slice(slicingPlane); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 0.25, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0.25, 0), Point.MakePointWithInches(2.36126321602, 3.5, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(2.36126321602, 3.5, 0), Point.MakePointWithInches(240, 3.5, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 3.5, 0), Point.MakePointWithInches(240, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0.25, 0), Point.MakePointWithInches(0, 3.5, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3.5, 0), Point.MakePointWithInches(2.36126321602, 3.5, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(2.36126321602, 3.5, 0), Point.MakePointWithInches(0, 0.25, 0))); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected1).Should().BeTrue(); results.Contains(expected2).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }
public void Polygon_DoesIntersectNotCoplanar() { Point front1 = Point.Origin; Point front2 = Point.MakePointWithInches(4, 0, 0); Point front3 = Point.MakePointWithInches(4, 0, 2); Point front4 = Point.MakePointWithInches(0, 0, 2); Point back1 = Point.MakePointWithInches(0, 12, 0); Point back2 = Point.MakePointWithInches(4, 12, 0); Point back3 = Point.MakePointWithInches(4, 12, 2); Point back4 = Point.MakePointWithInches(0, 12, 2); Polygon frontFace = new Polygon(new List<Point> { front1, front2, front3, front4 }); Polygon backFace = new Polygon(new List<Point> { back1, back2, back3, back4 }); Line intersecting1 = new Line(Point.MakePointWithInches(2, 0, 1), Point.MakePointWithInches(2, 1, 1)); Line intersecting2 = new Line(Point.MakePointWithInches(2, 0, .5), Point.MakePointWithInches(5, 12, 1)); Line intersectingAlongSide = new Line(Point.Origin, Point.MakePointWithInches(0, 1, 0)); Line noIntersect = new Line(Point.MakePointWithInches(5, 0, 0), Point.MakePointWithInches(5, 1, 0)); frontFace.DoesIntersect(intersecting1).Should().BeTrue(); backFace.DoesIntersect(intersecting1).Should().BeTrue(); }
public void Polygon_SliceOnLineTest() { 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, 4))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(4, 3, 4))); bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 4), Point.MakePointWithInches(4, 3, 4))); Polygon testPolygon = new Polygon(bounds); Line slicingLine = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 1)); List<Polygon> results = testPolygon.Slice(slicingLine); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(1, 1, 1))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(3, 3, 3))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(3, 3, 3))); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(3, 3, 3))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(4, 1, 4))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(3, 3, 3), Point.MakePointWithInches(4, 3, 4))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 4), Point.MakePointWithInches(4, 3, 4))); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected2).Should().BeTrue(); results.Contains(expected1).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }
public void Polygon_IntersectWithLine() { List<LineSegment> lineSegments = new List<LineSegment>(); lineSegments.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.MakePointWithInches(0, 2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.Origin)); Polygon testPolygon = new Polygon(lineSegments); Line testIntersect = new Line(Point.MakePointWithInches(-1.5, 1, 0), Point.MakePointWithInches(-3, -2, 1)); Line testIntersectSide = new Line(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(2, -1, 1)); Line noIntersect = new Line(Point.MakePointWithInches(-4, 1, 0), Point.MakePointWithInches(-5, -2, 1)); Point intersect = testPolygon.IntersectWithLine(testIntersect); Point intersectSide = testPolygon.IntersectWithLine(testIntersectSide); Point none = testPolygon.IntersectWithLine(noIntersect); (intersect == Point.MakePointWithInches(-1.5, 1, 0)).Should().BeTrue(); (intersectSide == Point.MakePointWithInches(0, 1, 0)).Should().BeTrue(); (none == null).Should().BeTrue(); }
public void Polygon_DoesShareOrContainSide() { List<LineSegment> lineSegments = new List<LineSegment>(); lineSegments.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.MakePointWithInches(0, 2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, 2, 0), Point.Origin)); Polygon testPolygon = new Polygon(lineSegments); List<LineSegment> lineSegments2 = new List<LineSegment>(); lineSegments2.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 2, 0))); lineSegments2.Add(new LineSegment(Point.MakePointWithInches(-7, 1, 0), Point.MakePointWithInches(0, 2, 0))); lineSegments2.Add(new LineSegment(Point.MakePointWithInches(-7, 1, 0), Point.Origin)); Polygon testExactSide = new Polygon(lineSegments2); List<LineSegment> lineSegments3 = new List<LineSegment>(); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0))); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(1, -2, 0), Point.MakePointWithInches(0, 3, 0))); lineSegments3.Add(new LineSegment(Point.MakePointWithInches(1, -2, 0), Point.MakePointWithInches(0, 1, 0))); Polygon testOverlappingSide = new Polygon(lineSegments3); List<LineSegment> lineSegments4 = new List<LineSegment>(); lineSegments4.Add(new LineSegment(Point.MakePointWithInches(1, 1, 0), Point.MakePointWithInches(-1, 3, 0))); lineSegments4.Add(new LineSegment(Point.MakePointWithInches(2, -3, 0), Point.MakePointWithInches(-1, 3, 0))); lineSegments4.Add(new LineSegment(Point.MakePointWithInches(2, -3, 0), Point.MakePointWithInches(1, 1, 0))); Polygon testIntersecting = new Polygon(lineSegments4); bool resultsExact = testPolygon.DoesShareOrContainSide(testExactSide); bool resultsOverlapping = testPolygon.DoesShareOrContainSide(testOverlappingSide); bool resultsIntersecting = testPolygon.DoesShareOrContainSide(testIntersecting); resultsExact.Should().BeTrue(); resultsOverlapping.Should().BeFalse(); resultsIntersecting.Should().BeFalse(); }
public void Polygon_DoesContainPointAlongSides() { //think messes up due to percision error List<LineSegment> lineSegments = new List<LineSegment>(); lineSegments.Add(new LineSegment(Point.MakePointWithInches(0, 2, 3), Point.MakePointWithInches(-3, -2, 0))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(-3, -2, 0), Point.MakePointWithInches(1, 1, -1))); lineSegments.Add(new LineSegment(Point.MakePointWithInches(1, 1, -1), Point.MakePointWithInches(0, 2, 3))); Polygon testPolygon = new Polygon(lineSegments); Point pointOn = Point.MakePointWithInches(-1.5, 0, 1.5); Point anotherPointOn = Point.MakePointWithInches(.5, 1.5, 1); Point pointNotOn = Point.MakePointWithInches(-2, 0, 1.5); bool resultOn = testPolygon.DoesContainPointAlongSides(pointOn); bool resultAnotherOn = testPolygon.DoesContainPointAlongSides(anotherPointOn); bool resultNotOn = testPolygon.DoesContainPointAlongSides(pointNotOn); resultOn.Should().BeTrue(); resultAnotherOn.Should().BeTrue(); resultNotOn.Should().BeFalse(); }
public PlateConnector(Polygon geometry, string name = "") { this.Geometry = geometry; this.Name = name; }
public void Polygon_DoesContainLineSegment() { Point point1 = Point.MakePointWithInches(0, 0); Point point2 = Point.MakePointWithInches(2, 0); Point point3 = Point.MakePointWithInches(2, 1); Point point4 = Point.MakePointWithInches(1, 1); Point point5 = Point.MakePointWithInches(1, 2); Point point6 = Point.MakePointWithInches(2, 2); Point point7 = Point.MakePointWithInches(2, 3); Point point8 = Point.MakePointWithInches(0, 3); List<Point> vertices = new List<Point>(){point1, point2, point3, point4, point5, point6, point7, point8}; Polygon cShape = new Polygon(vertices); Point basePoint1 = Point.MakePointWithInches(1, 0); Point endPoint1 = Point.MakePointWithInches(1, 3); LineSegment segmentTouchesInsideEdge = new LineSegment(basePoint1, endPoint1); Point basePoint2 = Point.MakePointWithInches(0, 0); Point endPoint2 = Point.MakePointWithInches(2, 2); LineSegment segmentCutsThroughVertices = new LineSegment(basePoint2, endPoint2); Point basePoint3 = Point.MakePointWithInches(1.5, 0); Point endPoint3 = Point.MakePointWithInches(.5, 4); LineSegment segmentCutsThroughVertexAndEdge = new LineSegment(basePoint3, endPoint3); Point basePoint4 = Point.MakePointWithInches(1.5, 0); Point endPoint4 = Point.MakePointWithInches(1.5, 3); LineSegment segmentCutsThroughEdges = new LineSegment(basePoint4, endPoint4); Point basePoint5 = Point.MakePointWithInches(0.5, 0); Point endPoint5 = Point.MakePointWithInches(0.5, 3); LineSegment segmentIsChord = new LineSegment(basePoint5, endPoint5); cShape.Contains(segmentTouchesInsideEdge).Should().BeTrue(); cShape.Contains(segmentCutsThroughVertices).Should().BeFalse(); cShape.Contains(segmentCutsThroughVertexAndEdge).Should().BeFalse(); cShape.Contains(segmentIsChord).Should().BeTrue(); }
public void Polygon_SliceAnotherCaseThatDidntWorkBefore() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 0, 1.5))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0, 1.5), Point.MakePointWithInches(240, 0, 1.5))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 1.5), Point.MakePointWithInches(240, 0, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon testPolygon = new Polygon(bounds); Plane slicingPlane = new Plane(new Direction(new Angle(new Radian(), 5.6548667765)), Point.MakePointWithInches(122.8315595, 169.313137732, 0)); List<Polygon> results = testPolygon.Slice(slicingPlane); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(240, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.MakePointWithInches(240, 0, 1.5))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 1.5), Point.MakePointWithInches(0, 0, 1.5))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0, 1.5), Point.Origin)); Polygon expected1 = new Polygon(expected1Bounds); //should only return the original plane results.Count.Should().Be(1); (results[0] == testPolygon).Should().BeTrue(); }
public void Polygon_SliceWithLineTest() { //changed to inches because mm were gave results smaller than what we are considering equivalent List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(2, 1, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.MakePointWithInches(6, 1, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(6, 0, 0), Point.Origin)); bounds.Add(new LineSegment(Point.MakePointWithInches(6, 1, 0), Point.MakePointWithInches(6, 0, 0))); Polygon testPolygon = new Polygon(bounds); Line slicingLine = new Line(Point.MakePointWithInches(6, 5, 0), Point.MakePointWithInches(2, 1, 0)); List<Polygon> results = testPolygon.Slice(slicingLine); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(2, 1, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.MakePointWithInches(6, 1, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(6, 0, 0), Point.MakePointWithInches(1, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(6, 1, 0), Point.MakePointWithInches(6, 0, 0))); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(1, 0, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(2, 1, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.Origin)); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected2).Should().BeTrue(); results.Contains(expected1).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }