/// <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_PointOnSameSideAs() { Point testPoint = Point.MakePointWithInches(1, 3, -1); Point testPoint2 = Point.MakePointWithInches(-1, -2, 5); Point testPoint3 = Point.MakePointWithInches(0, 1, 0); Point referencePoint = Point.MakePointWithInches(1, 2, 1); Point referencePoint2 = Point.MakePointWithInches(0, 2, 1); Vector testNormalVector = new Vector(Point.MakePointWithInches(1, 0, 0)); Plane testPlane = new Plane(testNormalVector); testPlane.PointIsOnSameSideAs(testPoint, referencePoint).Should().BeTrue(); //test one on the same side testPlane.PointIsOnSameSideAs(testPoint2, referencePoint).Should().BeFalse(); //test one on the opposite side testPlane.PointIsOnSameSideAs(testPoint3, referencePoint).Should().BeFalse(); //test one on the plane testPlane.PointIsOnSameSideAs(testPoint, referencePoint2).Should().BeFalse(); //test a reference point on the plane Point testPointOffOrigin = Point.MakePointWithInches(5, 4, 0); Point testPointOffOrigin2 = Point.MakePointWithInches(5, -2, 0); Point referencePointOffOrigin = Point.MakePointWithInches(1, 2, 3); Point planeBase = Point.MakePointWithInches(1, -4, 2); Vector testNormalVectorOffOrigin = new Vector(Point.MakePointWithInches(-1, 2, 1)); Plane testPlaneOffOrigin = new Plane(testNormalVectorOffOrigin.Direction, planeBase); testPlaneOffOrigin.PointIsOnSameSideAs(testPointOffOrigin, referencePointOffOrigin).Should().BeTrue(); testPlaneOffOrigin.PointIsOnSameSideAs(testPointOffOrigin2, referencePointOffOrigin).Should().BeFalse(); testPlaneOffOrigin.PointIsOnSameSideAs(planeBase, referencePointOffOrigin).Should().BeFalse(); }