Cuts the polyhedron at the plane. If the polyhedron is entirely above or below the plane, one of the returned polyhedra will be empty.
259 above.face.resize(0);
260 below.face.resize(0);
262 Array<DirectedEdge> edge;
269 int numAbove = 0, numIn = 0, numBelow = 0;
270 bool ruledOut =
false;
273 plane.getEquation(abc, d);
277 const float eps = 0.005f;
278 for (f =
face.length() - 1; (f >= 0) && (!ruledOut); f--) {
279 const ConvexPolygon& poly =
face[f];
280 for (
int v = poly._vertex.length() - 1; (v >= 0) && (!ruledOut); v--) {
281 double r = abc.dot(poly._vertex[v]) + d;
284 }
else if (r < -eps) {
290 ruledOut = (numAbove != 0) && (numBelow !=0);
297 }
else if (numAbove == 0) {
304 for (f =
face.length() - 1; f >= 0; f--) {
307 face[f].cut(plane, a, b, e);
309 bool aEmpty = a.isEmpty();
310 bool bEmpty = b.isEmpty();
315 above.face.append(a);
320 below.face.append(b);
323 if (! aEmpty && ! bEmpty) {
333 const Array<Vector3>& _vertex = (aEmpty ? b._vertex : a._vertex);
334 int L = _vertex.length();
336 for (
int v = 0; v < L; ++v) {
337 if (plane.fuzzyContains(_vertex[v]) && plane.fuzzyContains(_vertex[(v + 1) % L])) {
338 e.start = _vertex[v];
339 e.stop = _vertex[(v + 1) % L];
350 if (above.face.length() == 1) {
353 below.face.append(above.face[0]);
354 above.face.resize(0);
355 }
else if (below.face.length() == 1) {
358 above.face.append(below.face[0]);
359 below.face.resize(0);
362 if ((above.face.length() > 0) && (below.face.length() > 0)) {
367 int numVertices = edge.length();
379 Vector3 last_vertex = edge.last().stop;
380 cap._vertex.append(last_vertex);
385 for (
int v = numVertices - 1; v >= 0; v--) {
388 int num = edge.length();
389 double distance = (edge[index].start - last_vertex).squaredMagnitude();
390 for (
int e = 1; e < num; ++e) {
391 double d = (edge[e].start - last_vertex).squaredMagnitude();
401 debugAssertM(distance < 0.02,
"Edge missing while closing polygon.");
403 last_vertex = edge[index].stop;
404 cap._vertex.append(last_vertex);
409 above.face.append(cap);
410 below.face.append(cap.inverse());
414 debugAssert((above.face.length() == 0) || (above.face.length() >= 4));
415 debugAssert((below.face.length() == 0) || (below.face.length() >= 4));
Array< ConvexPolygon > face
Definition: ConvexPolyhedron.h:118
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
double distance(double x, double y)
Definition: g3dmath.h:731
#define debugAssert(exp)
Definition: debugAssert.h:160
double eps(double a, double b)
Definition: g3dmath.h:824