public void PlaneEdgeIntersection_Gives_Expected_Intersection_Points() { int size = 4; double tol = 1E-6; Vector3 vertex1 = new Vector3(0, 0, 0); Vector3 vertex2 = new Vector3(0, 1, 0.5); Vector3 planeNormal = new Vector3(0.301511, -0.904534, 0); Vector3[] pointsOnPlane = new Vector3[] { new Vector3(-0.2, 0.933333,0.2), new Vector3(-0.2, 0.2, 0.2), new Vector3(-0.2, -0.066667, 0.2), new Vector3(-0.2, -0.423389, 0.2), }; Vector3[] expectedResVct = { new Vector3(0, 1, 0.5), new Vector3(0, 0.266667, 0.133333), new Vector3(0, 0, 0), new Vector3(0, -0.356722, -0.178361), }; int[] expectedRes = new int[] { 2, 3, 1, -3 }; for (int i = 0; i < size; i++) { int res = ShellSecAlgorithms.PlaneEdgeIntersection(vertex1, vertex2, planeNormal, pointsOnPlane[i], tol, out var x); Assert.AreEqual(expectedResVct[i].X, x.X, tol); Assert.AreEqual(expectedResVct[i].Y, x.Y, tol); Assert.AreEqual(expectedResVct[i].Z, x.Z, tol); Assert.AreEqual(expectedRes[i], res); } }
public void AABBTreeRayIntersection_FindIntersection() { Vector3 projVect = new Vector3(0, 0, -1); var mesh = MakeMesh(); var aabbTree = MakeAABBTree(mesh); double tolerance = 1E-10; Point3[] inputPoints = { new Point3(0,1,0.5), //the vertex of the mesh 0.5 * new Point3(0, 1, 0.5) + 0.5 * new Point3(0, 0, 1), //point on mesh edge new Point3(0.4, 0.4, 0.4), //point inside mesh new Point3(1, 0, 2.5), //point above the vertex of the mesh //new Point3(1, 0.6, 0.6), //point outside mesh }; Point3[] expectedPoints = new Point3[] { new Point3(0, 1, 0.5), new Point3(0, 0.5, 0.25), new Point3(0.4, 0.4, 0.2), new Point3(1, 0, 0), }; Point3[] outputPoints = new Point3[4]; for (int i = 0; i < inputPoints.Count(); i++) { Intersection intersection = ShellSecAlgorithms.RayAABBTreeIntersections(inputPoints[i], projVect, aabbTree); var pt = intersection.Values.ToList()[0]; Assert.That(pt.Equals(expectedPoints[i], tolerance)); } }
public void AABBTreeRayIntersection_FindIntersection_NoValidIntersection() { Vector3 projVect = new Vector3(0, 0, -1); var mesh = MakeMesh(); var aabbTree = MakeAABBTree(mesh); var inputPoints = new Point3(1, 0.6, 0.6); //point outside mesh Intersection intersection = ShellSecAlgorithms.RayAABBTreeIntersections(inputPoints, projVect, aabbTree); Assert.That(intersection is null); }