public void Plane_ContainsPoint() { Plane testPlane = new Plane(Point.MakePointWithInches(0,1,0), Point.MakePointWithInches(2,1,-3), Point.MakePointWithInches(-4,1,-1)); Point testPoint1 = Point.MakePointWithInches(0, 1, 5); Point testPoint2 = Point.MakePointWithInches(2, 2, 2); bool result1 = testPlane.Contains(testPoint1); bool result2 = testPlane.Contains(testPoint2); result1.Should().BeTrue(); result2.Should().BeFalse(); }
public void Plane_ContainsLine() { Plane testPlane = new Plane(Point.Origin, Point.MakePointWithInches(1, 3, 0), Point.MakePointWithInches(4, -2, 0)); Line testLine = new Line(Point.MakePointWithInches(2, 0, 0), Point.MakePointWithInches(0, -1, 0)); Line testFalseLine = new Line(Point.MakePointWithInches(1, 2, -2), Point.MakePointWithInches(2, 4, 3)); bool result = testPlane.Contains(testLine); bool result2 = testPlane.Contains(testFalseLine); result.Should().BeTrue(); result2.Should().BeFalse(); }
public void Plane_ContainsLineOnOrigin() { Plane testPlane = new Plane(Point.Origin, Point.MakePointWithInches(1, 3, 0), Point.MakePointWithInches(-3, -1, 0)); Line testLine = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0)); bool result = testPlane.Contains(testLine); result.Should().BeTrue(); }
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(); }
/// <summary> /// determines if the points in the list, all lie on the same side of the dividing plane. /// Points on the plane are disregarded /// </summary> /// <param name="plane"></param> /// <returns></returns> public static bool AllPointsAreOnTheSameSideOf(this List<Point> pointList, Plane plane) { int index = 0; //find a reference point for (int i = 0; i < pointList.Count; i++) { if (!plane.Contains(pointList[i])) { index = i; break; } } Point referencePoint = pointList[index]; //Now check the remaining points for (int i = index + 1; i < pointList.Count; i++) { if (!plane.Contains(pointList[i]) && !plane.PointIsOnSameSideAs(pointList[i], referencePoint)) { return false; } } return true; }
public void Plane_IntersectionWithPlane_IdenticalPlane() { Plane testPlane = new Plane(new Direction(2, -1, 1), Point.MakePointWithInches(2, 1, 2)); Line found = (testPlane.IntersectWithPlane(testPlane)); Line expected = new Line(new Direction(-1, 0, 2), Point.MakePointWithInches(2, 1, 2)); testPlane.Contains(found).Should().BeTrue(); (found == expected).Should().BeTrue(); }
/// <summary> /// Finds all the polygons in this list that touch the plane passed in. If the includeContained flag is false, it will not return any /// polygons contained by the the plane /// </summary> /// <param name="polygonList">The list of polygons to to see if they touch the planes</param> /// <param name="toSeeIfTouches">The plane to see if the polygons touch</param> /// <param name="includeContained">If true it will include any polygons in the list that are contained in the plane, false it will not</param> /// <returns>Returns the polygons that are touching this plane</returns> public static List<Polygon> FindPolygonsTouchingPlane(this List<Polygon> polygonList, Plane toSeeIfTouches, bool includeContained = false) { List<Polygon> touchingPolygons = new List<Polygon>(); foreach (Polygon polygon in polygonList) { //see if they intersect if (toSeeIfTouches.Intersects(polygon)) { touchingPolygons.Add(polygon); } //they will not intersect if the are coplanar so we check here if we want to include contained ones else if (includeContained && toSeeIfTouches.Contains(polygon)) { touchingPolygons.Add(polygon); } } return touchingPolygons; }