MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / triBoxOverlap

Function triBoxOverlap

src/Misc/tribox3.h:119–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117 if(min>rad || max<-rad) return 0;
118
119int triBoxOverlap(const Float boxcenter[3],const Float boxhalfsize[3],const Float triverts[3][3])
120{
121
122 /* use separating axis theorem to test overlap between triangle and box */
123 /* need to test for overlap in these directions: */
124 /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
125 /* we do not even need to test these) */
126 /* 2) normal of the triangle */
127 /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
128 /* this gives 3x3=9 more tests */
129 Float v0[3],v1[3],v2[3];
130// Float axis[3];
131 Float min,max,p0,p1,p2,rad,fex,fey,fez; // -NJMP- "d" local variable removed
132 Float normal[3],e0[3],e1[3],e2[3];
133
134 /* This is the fastest branch on Sun */
135 /* move everything so that the boxcenter is in (0,0,0) */
136 SUB(v0,triverts[0],boxcenter);
137 SUB(v1,triverts[1],boxcenter);
138 SUB(v2,triverts[2],boxcenter);
139
140 /* compute triangle edges */
141 SUB(e0,v1,v0); /* tri edge 0 */
142 SUB(e1,v2,v1); /* tri edge 1 */
143 SUB(e2,v0,v2); /* tri edge 2 */
144
145 /* Bullet 3: */
146 /* test the 9 tests first (this was faster) */
147 fex = std::abs(e0[X]);
148 fey = std::abs(e0[Y]);
149 fez = std::abs(e0[Z]);
150 AXISTEST_X01(e0[Z], e0[Y], fez, fey);
151 AXISTEST_Y02(e0[Z], e0[X], fez, fex);
152 AXISTEST_Z12(e0[Y], e0[X], fey, fex);
153
154 fex = std::abs(e1[X]);
155 fey = std::abs(e1[Y]);
156 fez = std::abs(e1[Z]);
157 AXISTEST_X01(e1[Z], e1[Y], fez, fey);
158 AXISTEST_Y02(e1[Z], e1[X], fez, fex);
159 AXISTEST_Z0(e1[Y], e1[X], fey, fex);
160
161 fex = std::abs(e2[X]);
162 fey = std::abs(e2[Y]);
163 fez = std::abs(e2[Z]);
164 AXISTEST_X2(e2[Z], e2[Y], fez, fey);
165 AXISTEST_Y1(e2[Z], e2[X], fez, fex);
166 AXISTEST_Z12(e2[Y], e2[X], fey, fex);
167
168 /* Bullet 1: */
169 /* first test overlap in the {x,y,z}-directions */
170 /* find min, max of the triangle each direction, and test for overlap in */
171 /* that direction -- this is equivalent to testing a minimal AABB around */
172 /* the triangle against the AABB */
173
174 /* test in X-direction */
175 FINDMINMAX(v0[X],v1[X],v2[X],min,max);
176 if(min>boxhalfsize[X] || max<-boxhalfsize[X]) return 0;

Callers 2

bbox_checkFunction · 0.50
TEST_FFunction · 0.50

Calls 1

planeBoxOverlapFunction · 0.85

Tested by 1

TEST_FFunction · 0.40