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 Line_DoesIntersectPolyhedron() { //make a polyhedron Point bottom1 = Point.Origin; Point bottom2 = Point.MakePointWithInches(4, 0, 0); Point bottom3 = Point.MakePointWithInches(4, 12, 0); Point bottom4 = Point.MakePointWithInches(0, 12, 0); Point top1 = Point.MakePointWithInches(0, 0, 2); Point top2 = Point.MakePointWithInches(4, 0, 2); Point top3 = Point.MakePointWithInches(4, 12, 2); Point top4 = Point.MakePointWithInches(0, 12, 2); List<Polygon> faces = new List<Polygon>(); Polygon bottomFace = new Polygon(new List<Point> {bottom1, bottom2, bottom3, bottom4}); Polygon topFace = new Polygon(new List<Point> { top1, top2, top3, top4 }); Polygon frontFace = new Polygon(new List<Point> { bottom1, bottom2, top2, top1 }); Polygon rightFace = new Polygon(new List<Point> { bottom2, bottom3, top3, top2 }); Polygon backFace = new Polygon(new List<Point> { bottom3, bottom4, top4, top3 }); Polygon leftFace = new Polygon(new List<Point> { bottom4, bottom1, top1, top4 }); faces.Add(bottomFace); faces.Add(topFace); faces.Add(frontFace); faces.Add(rightFace); faces.Add(backFace); faces.Add(leftFace); Polyhedron testPolyhedron = new Polyhedron(faces); //now make some lines that will intersect it 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)); // Temporary frontFace.DoesIntersect(intersecting1).Should().BeTrue(); backFace.DoesIntersect(intersecting1).Should().BeTrue(); // Temporary intersecting1.DoesIntersect(testPolyhedron).Should().BeTrue(); intersecting2.DoesIntersect(testPolyhedron).Should().BeTrue(); intersectingAlongSide.DoesIntersect(testPolyhedron).Should().BeTrue(); noIntersect.DoesIntersect(testPolyhedron).Should().BeFalse(); }