public static bool MightIntersect_BB(List <xyz> main1, List <xyz> main2) { BoundingBox3d bb1 = BoundingBox3d.FromArrayOfPoints(main1); BoundingBox3d bb2 = BoundingBox3d.FromArrayOfPoints(main2); return(BoundingBox3d.intersect(bb1, bb2)); }
public void test_bb3d() { BoundingBox3d bb = BoundingBox3d.FromArrayOfPoints(ut.MakePoly(new xyz(0, 0, 0), new xyz(5, 5, 5))); Assert.IsTrue(bb.PointInside(new xyz(3, 3, 3))); Assert.IsTrue(bb.PointInside(new xyz(0, 0, 0))); Assert.IsTrue(bb.PointInside(new xyz(5, 5, 5))); Assert.IsTrue(bb.PointInside(new xyz(5, 0, 5))); Assert.IsTrue(bb.PointInside(new xyz(0, 0, 5))); Assert.IsTrue(bb.PointInside(new xyz(0, 4, 0))); Assert.IsFalse(bb.PointInside(new xyz(0, 6, 0))); Assert.IsFalse(bb.PointInside(new xyz(0, 0, -1))); Assert.IsFalse(bb.PointInside(new xyz(7, 6, 0))); Assert.IsFalse(bb.PointInside(new xyz(7, 7, 7))); BoundingBox3d bb2 = BoundingBox3d.FromArrayOfPoints(ut.MakePoly(new xyz(8, 8, 8), new xyz(9, 9, 9))); bb = bb + bb2; Assert.IsTrue(bb.PointInside(new xyz(3, 3, 3))); Assert.IsTrue(bb.PointInside(new xyz(0, 0, 0))); Assert.IsTrue(bb.PointInside(new xyz(5, 5, 5))); Assert.IsTrue(bb.PointInside(new xyz(5, 0, 5))); Assert.IsTrue(bb.PointInside(new xyz(0, 0, 5))); Assert.IsTrue(bb.PointInside(new xyz(0, 4, 0))); Assert.IsTrue(bb.PointInside(new xyz(8, 8, 8))); Assert.IsTrue(bb.PointInside(new xyz(7, 7, 7))); }
public void test_cube() { Solid s1 = Builtin_Solids.CreateCube("s1", 5); bsp3d bsp = new bsp3d(s1); BoundingBox3d bb = BoundingBox3d.FromArrayOfPoints(s1.Vertices); foreach (xyz v in s1.Vertices) { Assert.AreEqual(PointInPoly.Coincident, bsp.PointInPolyhedron(v)); Assert.IsTrue(bb.PointInside(v)); } foreach (Face f in s1.Faces) { xyz v = f.GetCenter(); xyz n = f.UnitNormal(); Assert.AreEqual(PointInPoly.Coincident, bsp.PointInPolyhedron(v)); Assert.AreEqual(PointInPoly.Outside, bsp.PointInPolyhedron(v + n)); Assert.AreEqual(PointInPoly.Inside, bsp.PointInPolyhedron(v - n)); Assert.IsTrue(bb.PointInside(v)); Assert.IsFalse(bb.PointInside(v + n)); Assert.IsTrue(bb.PointInside(v - n)); } foreach (Face f in s1.Faces) { foreach (HalfEdge h in f.MainLoop) { xyz v = h.Center(); xyz n = h.GetInwardNormal(); Assert.IsTrue(bb.PointInside(v)); Assert.IsTrue(bb.PointInside(v + n)); Assert.IsFalse(bb.PointInside(v - n)); Assert.AreEqual(PointInPoly.Coincident, bsp.PointInPolyhedron(v)); Assert.AreEqual(PointInPoly.Coincident, bsp.PointInPolyhedron(v + n)); Assert.AreEqual(PointInPoly.Outside, bsp.PointInPolyhedron(v - n)); } } Assert.AreEqual(PointInPoly.Inside, bsp.PointInPolyhedron(s1.GetCenter())); Assert.IsTrue(bb.PointInside(s1.GetCenter())); }