8 template<
typename Real>
14 template<
typename Real>
20 template<
typename Real>
26 template<
typename Real>
32 template<
typename Real>
38 template<
typename Real>
45 template<
typename Real>
56 template<
typename Real>
70 template<
typename Real>
80 Real t = l.dot(dir) / dir.normSquared();
83 q = t < 0 ? segment.
v0 : q;
84 q = t > 1 ? segment.
v1 : q;
89 template<
typename Real>
99 template<
typename Real>
103 Coord3D e0 = triangle.
v[1] - triangle.
v[0];
104 Coord3D e1 = triangle.
v[2] - triangle.
v[0];
108 Real d = e0.dot(dir);
109 Real e = e1.dot(dir);
110 Real f = dir.dot(dir);
112 Real det = a * c - b * b;
113 Real s = b * e - c * d;
114 Real t = b * d - a * e;
120 Real g = (triangle.
v[2] - triangle.
v[1]).normSquared();
161 t = (e >= 0 ? 0 : (-e >= c ? 1 : -e / c));
173 s = (d >= 0 ? 0 : (-d >= a ? 1 : -d / a));
179 Real invDet = 1 / det;
208 Real numer = c + e - b - d;
213 Real denom = a - 2 * b + c;
214 s = (numer >= denom ? 1 : numer / denom);
222 template<
typename Real>
226 Real b0 = diff.dot(rectangle.
axis[0]);
235 template<
typename Real>
250 template<
typename Real>
259 template<
typename Real>
268 template<
typename Real>
273 for (
int i = 0; i < 4; i++)
288 template<
typename Real>
291 bool bInside = inside(abox);
302 if (offset0[0] < minDist)
305 minDist = offset0[0];
308 if (offset0[1] < minDist)
311 minDist = offset0[1];
314 if (offset0[2] < minDist)
316 q = Coord3D(origin[0], origin[1], abox.
v0[2]);
317 minDist = offset0[2];
322 if (offset1[0] < minDist)
325 minDist = offset1[0];
328 if (offset1[1] < minDist)
331 minDist = offset1[1];
334 if (offset1[2] < minDist)
336 q = Coord3D(origin[0], origin[1], abox.
v1[2]);
337 minDist = offset1[2];
340 return TPoint3D<Real>(q);
343 template<
typename Real>
347 Coord3D pPrime(offset.dot(obb.
u), offset.dot(obb.
v), offset.dot(obb.
w));
351 Coord3D q = obb.
center + qPrime[0] * obb.
u + qPrime[1] * obb.
v + qPrime[2] * obb.
w;
356 template<
typename Real>
362 bInside = cp.normSquared() >= sphere.
radius * sphere.
radius ? false :
true;
367 template<
typename Real>
373 bInside = dir.normSquared() < capsule.
radius * capsule.
radius ? true :
false;
377 template<
typename Real>
380 bInside = inside(tet);
384 for (
int i = 0; i < 4; i++)
398 template<
typename Real>
406 for (
int i = 0; i < 4; i++)
415 if (i == 0 || i == 3)
431 template<
typename Real>
434 bInside = inside(abox);
444 Coord3D offset0 =
abs(origin - abox.
v0);
445 if (offset0[0] < minDist)
447 q =
Coord3D(abox.
v0[0], origin[1], origin[2]);
448 minDist = offset0[0];
451 if (offset0[1] < minDist)
453 q = Coord3D(origin[0], abox.
v0[1], origin[2]);
454 minDist = offset0[1];
457 if (offset0[2] < minDist)
459 q = Coord3D(origin[0], origin[1], abox.
v0[2]);
460 minDist = offset0[2];
465 if (offset1[0] < minDist)
468 minDist = offset1[0];
471 if (offset1[1] < minDist)
473 q = Coord3D(origin[0], abox.
v1[1], origin[2]);
474 minDist = offset1[1];
477 if (offset1[2] < minDist)
479 q = Coord3D(origin[0], origin[1], abox.
v1[2]);
480 minDist = offset1[2];
486 template<
typename Real>
490 Coord3D pPrime(offset.dot(obb.
u), offset.dot(obb.
v), offset.dot(obb.
w));
494 Coord3D q = obb.
center + qPrime[0] * obb.
u + qPrime[1] * obb.
v + qPrime[2] * obb.
w;
499 template<
typename Real>
505 template<
typename Real>
508 return (origin - project(line).origin).norm();
511 template<
typename Real>
517 template<
typename Real>
523 template<
typename Real>
526 Coord3D q = project(plane).origin;
529 return sign * (origin - q).norm();
532 template<
typename Real>
535 Coord3D q = project(triangle).origin;
544 return sign * (origin - q).norm();
547 template<
typename Real>
553 return (
origin - q).norm();
556 template<
typename Real>
562 return (origin - q).norm();
565 template<
typename Real>
571 template<
typename Real>
576 return bInside ==
true ? -d : d;
579 template<
typename Real>
583 Real d = (origin - project(abox, bInside).origin).norm();
584 return bInside ==
true ? -d : d;
587 template<
typename Real>
591 Real d = (origin - project(obb, bInside).origin).norm();
592 return bInside ==
true ? -d : d;
595 template<
typename Real>
600 return bInside ==
true ? -d : d;
603 template<
typename Real>
606 return (origin - pt.
origin).normSquared();
609 template<
typename Real>
615 template<
typename Real>
621 template<
typename Real>
624 return (origin - project(segment).origin).normSquared();
627 template<
typename Real>
633 template<
typename Real>
639 template<
typename Real>
645 template<
typename Real>
648 return (origin - project(disk).origin).normSquared();
651 template<
typename Real>
654 return (origin - project(sphere).origin).normSquared();
657 template<
typename Real>
663 template<
typename Real>
669 template<
typename Real>
675 template<
typename Real>
681 template<
typename Real>
692 template<
typename Real>
706 template<
typename Real>
715 Coord3D offset = origin - segment.
startPoint();
716 Real t = offset.dot(dir) / dir.normSquared();
721 template<
typename Real>
732 template<
typename Real>
753 template<
typename Real>
766 return recParam.
u < rectangle.
extent[0] && recParam.
u > -rectangle.
extent[0] && recParam.
v < rectangle.
extent[1] && recParam.
v > -rectangle.
extent[1];
774 template<
typename Real>
786 template<
typename Real>
792 template<
typename Real>
798 template<
typename Real>
807 bInside &= (
origin - face.
v[0]).
dot(normal) * (tet.
v[0] - face.
v[0]).
dot(normal) > 0;
811 bInside &= (
origin - face.
v[0]).
dot(normal) * (tet.
v[1] - face.
v[0]).
dot(normal) > 0;
815 bInside &= (
origin - face.
v[0]).
dot(normal) * (tet.
v[2] - face.
v[0]).
dot(normal) > 0;
819 bInside &= (
origin - face.
v[0]).
dot(normal) * (tet.
v[3] - face.
v[0]).
dot(normal) > 0;
824 template<
typename Real>
828 Coord3D pPrime(offset.dot(obb.
u), offset.dot(obb.
v), offset.dot(obb.
w));
831 bInside &= pPrime[0] < obb.
extent[0] && pPrime[0] > -obb.
extent[0];
832 bInside &= pPrime[1] < obb.
extent[1] && pPrime[1] > -obb.
extent[1];
833 bInside &= pPrime[2] < obb.
extent[2] && pPrime[2] > -obb.
extent[2];
837 template<
typename Real>
844 bInside &= offset[0] < extent[0] && offset[0] >
Real(0);
845 bInside &= offset[1] < extent[1] && offset[1] >
Real(0);
846 bInside &= offset[2] < extent[2] && offset[2] >
Real(0);
851 template<
typename Real>
857 template<
typename Real>
864 template<
typename Real>
871 template<
typename Real>
878 template<
typename Real>
887 Real f = u.normSquared();
888 Real det = a * c - b * b;
897 Real invDet = 1 / det;
898 Real s = (b * e - c * d) * invDet;
899 Real t = (a * e - b * d) * invDet;
904 template<
typename Real>
913 Real det = a * c - b * b;
923 Real sNum = b * e - c * d;
924 Real tNum = a * e - b * d;
935 Real s = sNum / sDenom;
936 Real t = tNum / tDenom;
941 template<
typename Real>
948 Real c = dir1.dot(dir1);
950 Real e = u.dot(dir1);
951 Real det = a * c - b * b;
961 Real sNum = b * e - c * d;
962 Real tNum = a * e - b * d;
973 else if (tNum > tDenom) {
979 Real s = sNum / sDenom;
980 Real t = tNum / tDenom;
985 template<
typename Real>
988 Coord3D e0 = triangle.
v[1] - triangle.
v[0];
989 Coord3D e1 = triangle.
v[2] - triangle.
v[0];
1004 Real UdE0 = U.dot(e0);
1005 Real UdE1 = U.dot(e1);
1006 Real UdDiff = U.dot(diff);
1007 Real VdE0 =
V.dot(e0);
1008 Real VdE1 =
V.dot(e1);
1009 Real VdDiff =
V.dot(diff);
1010 Real invDet = ((
Real)1) / (UdE0 * VdE1 - UdE1 * VdE0);
1013 Real u = (VdE1 * UdDiff - UdE1 * VdDiff) * invDet;
1014 Real v = (UdE0 * VdDiff - VdE0 * UdDiff) * invDet;
1020 Real DdE0 = W.dot(e0);
1021 Real DdE1 = W.dot(e1);
1022 Real DdDiff = W.dot(diff);
1023 Real t = u * DdE0 + v * DdE1 - DdDiff;
1032 return p.
project(triangle) - p;
1062 template<
typename Real>
1076 Real UdD0 = U.dot(rectangle.
axis[0]);
1077 Real UdD1 = U.dot(rectangle.
axis[1]);
1078 Real UdPmC = U.dot(diff);
1081 Real VdPmC =
V.dot(diff);
1082 Real invDet = ((
Real)1) / (UdD0 * VdD1 - UdD1 * VdD0);
1085 Real s0 = (VdD1 * UdPmC - UdD1 * VdPmC) * invDet;
1086 Real s1 = (UdD0 * VdPmC - VdD0 * UdPmC) * invDet;
1094 Real t = s0 * DdD0 + s1 * DdD1 - DdDiff;
1103 for (
int i = 0; i < 4; i++)
1116 template<
typename Real>
1131 template<
typename Real>
1135 boxCenter = 0.5 * (box.
v0 + box.
v1);
1136 boxExtent = 0.5 * (box.
v1 - box.
v0);
1143 t = (extent[axis] - pt[axis]) / dir[axis];
1146 t = (-extent[axis] - pt[axis]) / dir[axis];
1147 pt[axis] = -extent[axis];
1150 pt[axis] = extent[axis];
1152 pt =
clamp(pt, -extent, extent);
1155 auto case0 = [](
Coord3D& pt,
Real& t,
const Coord3D dir,
const Coord3D extent,
const int i0,
const int i1,
const int i2) {
1156 Real PmE0 = pt[i0] - extent[i0];
1157 Real PmE1 = pt[i1] - extent[i1];
1158 Real prod0 = dir[i1] * PmE0;
1159 Real prod1 = dir[i0] * PmE1;
1164 pt[i0] = extent[i0];
1166 Real PpE1 = pt[i1] + extent[i1];
1167 Real delta = prod0 - dir[i0] * PpE1;
1168 if (delta >= (
Real)0)
1170 Real invLSqr = ((
Real)1) / (dir[i0] * dir[i0] + dir[i1] * dir[i1]);
1171 pt[i1] = -extent[i1];
1172 t = -(dir[i0] * PmE0 + dir[i1] * PpE1) * invLSqr;
1177 pt[i1] -= prod0 * inv;
1184 pt[i1] = extent[i1];
1186 Real PpE0 = pt[i0] + extent[i0];
1187 Real delta = prod1 - dir[i1] * PpE0;
1188 if (delta >= (
Real)0)
1190 Real invLSqr = ((
Real)1) / (dir[i0] * dir[i0] + dir[i1] * dir[i1]);
1191 pt[i0] = -extent[i0];
1192 t = -(dir[i0] * PpE0 + dir[i1] * PmE1) * invLSqr;
1197 pt[i0] -= prod1 * inv;
1202 if (pt[i2] < -extent[i2])
1204 pt[i2] = -extent[i2];
1206 else if (pt[i2] > extent[i2])
1208 pt[i2] = extent[i2];
1214 int i0,
int i1,
int i2)
1217 Real lenSqr, inv, tmp, param, t, delta;
1219 PpE[i1] = pnt[i1] + boxExtent[i1];
1220 PpE[i2] = pnt[i2] + boxExtent[i2];
1221 if (dir[i0] * PpE[i1] >= dir[i1] * PmE[i0])
1223 if (dir[i0] * PpE[i2] >= dir[i2] * PmE[i0])
1226 pnt[i0] = boxExtent[i0];
1227 inv = ((
Real)1) / dir[i0];
1228 pnt[i1] -= dir[i1] * PmE[i0] * inv;
1229 pnt[i2] -= dir[i2] * PmE[i0] * inv;
1230 final_t = -PmE[i0] * inv;
1235 lenSqr = dir[i0] * dir[i0] + dir[i2] * dir[i2];
1236 tmp = lenSqr * PpE[i1] - dir[i1] * (dir[i0] * PmE[i0] +
1238 if (tmp <= ((
Real)2) * lenSqr * boxExtent[i1])
1241 lenSqr += dir[i1] * dir[i1];
1243 delta = dir[i0] * PmE[i0] + dir[i1] * tmp + dir[i2] * PpE[i2];
1244 param = -delta / lenSqr;
1247 pnt[i0] = boxExtent[i0];
1248 pnt[i1] = t - boxExtent[i1];
1249 pnt[i2] = -boxExtent[i2];
1253 lenSqr += dir[i1] * dir[i1];
1254 delta = dir[i0] * PmE[i0] + dir[i1] * PmE[i1] + dir[i2] * PpE[i2];
1255 param = -delta / lenSqr;
1258 pnt[i0] = boxExtent[i0];
1259 pnt[i1] = boxExtent[i1];
1260 pnt[i2] = -boxExtent[i2];
1266 if (dir[i0] * PpE[i2] >= dir[i2] * PmE[i0])
1269 lenSqr = dir[i0] * dir[i0] + dir[i1] * dir[i1];
1270 tmp = lenSqr * PpE[i2] - dir[i2] * (dir[i0] * PmE[i0] +
1272 if (tmp <= ((
Real)2) * lenSqr * boxExtent[i2])
1275 lenSqr += dir[i2] * dir[i2];
1277 delta = dir[i0] * PmE[i0] + dir[i1] * PpE[i1] + dir[i2] * tmp;
1278 param = -delta / lenSqr;
1281 pnt[i0] = boxExtent[i0];
1282 pnt[i1] = -boxExtent[i1];
1283 pnt[i2] = t - boxExtent[i2];
1287 lenSqr += dir[i2] * dir[i2];
1288 delta = dir[i0] * PmE[i0] + dir[i1] * PpE[i1] + dir[i2] * PmE[i2];
1289 param = -delta / lenSqr;
1292 pnt[i0] = boxExtent[i0];
1293 pnt[i1] = -boxExtent[i1];
1294 pnt[i2] = boxExtent[i2];
1300 lenSqr = dir[i0] * dir[i0] + dir[i2] * dir[i2];
1301 tmp = lenSqr * PpE[i1] - dir[i1] * (dir[i0] * PmE[i0] +
1306 if (tmp <= ((
Real)2) * lenSqr * boxExtent[i1])
1309 lenSqr += dir[i1] * dir[i1];
1311 delta = dir[i0] * PmE[i0] + dir[i1] * tmp + dir[i2] * PpE[i2];
1312 param = -delta / lenSqr;
1315 pnt[i0] = boxExtent[i0];
1316 pnt[i1] = t - boxExtent[i1];
1317 pnt[i2] = -boxExtent[i2];
1321 lenSqr += dir[i1] * dir[i1];
1322 delta = dir[i0] * PmE[i0] + dir[i1] * PmE[i1]
1323 + dir[i2] * PpE[i2];
1324 param = -delta / lenSqr;
1327 pnt[i0] = boxExtent[i0];
1328 pnt[i1] = boxExtent[i1];
1329 pnt[i2] = -boxExtent[i2];
1334 lenSqr = dir[i0] * dir[i0] + dir[i1] * dir[i1];
1335 tmp = lenSqr * PpE[i2] - dir[i2] * (dir[i0] * PmE[i0] +
1340 if (tmp <= ((
Real)2) * lenSqr * boxExtent[i2])
1343 lenSqr += dir[i2] * dir[i2];
1345 delta = dir[i0] * PmE[i0] + dir[i1] * PpE[i1] + dir[i2] * tmp;
1346 param = -delta / lenSqr;
1349 pnt[i0] = boxExtent[i0];
1350 pnt[i1] = -boxExtent[i1];
1351 pnt[i2] = t - boxExtent[i2];
1355 lenSqr += dir[i2] * dir[i2];
1356 delta = dir[i0] * PmE[i0] + dir[i1] * PpE[i1]
1357 + dir[i2] * PmE[i2];
1358 param = -delta / lenSqr;
1361 pnt[i0] = boxExtent[i0];
1362 pnt[i1] = -boxExtent[i1];
1363 pnt[i2] = boxExtent[i2];
1369 lenSqr += dir[i2] * dir[i2];
1370 delta = dir[i0] * PmE[i0] + dir[i1] * PpE[i1] + dir[i2] * PpE[i2];
1371 param = -delta / lenSqr;
1374 pnt[i0] = boxExtent[i0];
1375 pnt[i1] = -boxExtent[i1];
1376 pnt[i2] = -boxExtent[i2];
1385 for (
int i = 0; i < 3; ++i)
1387 if (lineDir[i] < (
Real)0)
1389 point[i] = -point[i];
1390 lineDir[i] = -lineDir[i];
1406 Coord3D PmE = point - boxExtent;
1407 Real prodDxPy = lineDir[0] * PmE[1];
1408 Real prodDyPx = lineDir[1] * PmE[0];
1409 Real prodDzPx, prodDxPz, prodDzPy, prodDyPz;
1411 if (prodDyPx >= prodDxPy)
1413 prodDzPx = lineDir[2] * PmE[0];
1414 prodDxPz = lineDir[0] * PmE[2];
1415 if (prodDzPx >= prodDxPz)
1418 face(point, t, lineDir, PmE, boxExtent, 0, 1, 2);
1423 face(point, t, lineDir, PmE, boxExtent, 2, 0, 1);
1428 prodDzPy = lineDir[2] * PmE[1];
1429 prodDyPz = lineDir[1] * PmE[2];
1430 if (prodDzPy >= prodDyPz)
1433 face(point, t, lineDir, PmE, boxExtent, 1, 2, 0);
1438 face(point, t, lineDir, PmE, boxExtent, 2, 0, 1);
1445 case0(point, t, lineDir, boxExtent, 0, 1, 2);
1453 case0(point, t, lineDir, boxExtent, 0, 2, 1);
1458 case00(point, t, lineDir, boxExtent, 0);
1469 case0(point, t, lineDir, boxExtent, 1, 2, 0);
1474 case00(point, t, lineDir, boxExtent, 1);
1482 case00(point, t, lineDir, boxExtent, 2);
1486 point =
clamp(point, -boxExtent, boxExtent);
1493 for (
int i = 0; i < 3; ++i)
1497 point[i] = -point[i];
1504 template<
typename Real>
1518 Coord3D p = pPrime[0] * obb.
u + pPrime[1] * obb.
v + pPrime[2] * obb.
w;
1519 Coord3D q = qPrime[0] * obb.
u + qPrime[1] * obb.
v + qPrime[2] * obb.
w;
1529 template<
typename Real>
1535 template<
typename Real>
1541 template<
typename Real>
1547 template<
typename Real>
1553 template<
typename Real>
1559 template<
typename Real>
1565 template<
typename Real>
1571 template<
typename Real>
1597 template<
typename Real>
1603 template<
typename Real>
1606 return proximity(segment).lengthSquared();
1609 template<
typename Real>
1615 template<
typename Real>
1621 template<
typename Real>
1637 template<
typename Real>
1641 Coord3D e0 = triangle.
v[1] - triangle.
v[0];
1642 Coord3D e1 = triangle.
v[2] - triangle.
v[0];
1643 Coord3D normal = e0.cross(e1);
1662 if (DdQxE1 >= (
Real)0)
1665 if (DdE0xQ >= (
Real)0)
1667 if (DdQxE1 + DdE0xQ <= DdN)
1670 Real QdN = -
sign * diff.dot(normal);
1686 template<
typename Real>
1694 Real discr = a1 * a1 - a0;
1695 if (discr > (
Real)0)
1697 Real root = glm::sqrt(discr);
1702 else if (discr < (
Real)0)
1714 template<
typename Real>
1720 for (
int i = 0; i < 4; i++)
1739 template<
typename Real>
1754 if (numer > denom * t1)
1758 if (numer > denom * t0)
1766 if (numer > denom * t0)
1770 if (numer > denom * t1)
1787 lineDir.normalize();
1789 if (
clip(+lineDir[0], -offset[0] - boxExtent[0], t0, t1) &&
1790 clip(-lineDir[0], +offset[0] - boxExtent[0], t0, t1) &&
1791 clip(+lineDir[1], -offset[1] - boxExtent[1], t0, t1) &&
1792 clip(-lineDir[1], +offset[1] - boxExtent[1], t0, t1) &&
1793 clip(+lineDir[2], -offset[2] - boxExtent[2], t0, t1) &&
1794 clip(-lineDir[2], +offset[2] - boxExtent[2], t0, t1))
1798 interSeg.
v0 =
origin + t0 * lineDir;
1799 interSeg.
v1 =
origin + t1 * lineDir;
1804 interSeg.
v0 =
origin + t0 * lineDir;
1805 interSeg.
v1 = interSeg.
v0;
1813 template<
typename Real>
1828 if (numer > denom * t1)
1832 if (numer > denom * t0)
1840 if (numer > denom * t0)
1844 if (numer > denom * t1)
1861 lineDir.normalize();
1863 Real du = lineDir.dot(obb.
u);
1864 Real dv = lineDir.dot(obb.
v);
1865 Real dw = lineDir.dot(obb.
w);
1867 Real offset_u = offset.dot(obb.
u);
1868 Real offset_v = offset.dot(obb.
v);
1869 Real offset_w = offset.dot(obb.
w);
1871 if (
clip(+du, -offset_u - boxExtent[0], t0, t1) &&
1872 clip(-du, +offset_u - boxExtent[0], t0, t1) &&
1873 clip(+dv, -offset_v - boxExtent[1], t0, t1) &&
1874 clip(-dv, +offset_v - boxExtent[1], t0, t1) &&
1875 clip(+dw, -offset_w - boxExtent[2], t0, t1) &&
1876 clip(-dw, +offset_w - boxExtent[2], t0, t1))
1880 interSeg.
v0 =
origin + t0 * lineDir;
1881 interSeg.
v1 =
origin + t1 * lineDir;
1886 interSeg.
v0 =
origin + t0 * lineDir;
1887 interSeg.
v1 = interSeg.
v0;
1895 template<
typename Real>
1904 template<
typename Real>
1910 template<
typename Real>
1917 template<
typename Real>
1925 template<
typename Real>
1932 template<
typename Real>
1941 Real det = a * c - b * b;
1951 return (q0 - p0).lengthSquared() < (q1 - p1).lengthSquared() ? q0 - p0 : p1 - q1;
1954 Real sNum = b * e - c * d;
1955 Real tNum = a * e - b * d;
1977 Real s = sNum / sDenom;
1978 Real t = tNum / tDenom;
1983 template<
typename Real>
1992 Real det = a * c - b * b;
1999 return p0.
project(segment) - p0;
2009 return (p1 - q1).lengthSquared() < (p2 - q2).lengthSquared() ? (p1 - q1) : (p2 - q2);
2013 Real sNum = b * e - c * d;
2014 Real tNum = a * e - b * d;
2036 else if (tNum > tDenom) {
2047 Real s = sNum / sDenom;
2048 Real t = tNum / tDenom;
2053 template<
typename Real>
2069 template<
typename Real>
2085 template<
typename Real>
2101 template<
typename Real>
2117 template<
typename Real>
2123 template<
typename Real>
2129 template<
typename Real>
2135 template<
typename Real>
2141 template<
typename Real>
2144 return proximity(segment).lengthSquared();
2147 template<
typename Real>
2150 return proximity(triangle).lengthSquared();
2153 template<
typename Real>
2175 template<
typename Real>
2179 Coord3D e0 = triangle.
v[1] - triangle.
v[0];
2180 Coord3D e1 = triangle.
v[2] - triangle.
v[0];
2181 Coord3D normal = e0.cross(e1);
2200 if (DdQxE1 >= (
Real)0)
2203 if (DdE0xQ >= (
Real)0)
2205 if (DdQxE1 + DdE0xQ <= DdN)
2208 Real QdN = -
sign * diff.dot(normal);
2230 template<
typename Real>
2238 Real discr = a1 * a1 - a0;
2239 if (discr > (
Real)0)
2241 Real root = glm::sqrt(discr);
2243 if (-a1 + root <
Real(0))
2247 else if (-a1 + root <
Real(0))
2259 else if (discr <
Real(0))
2274 template<
typename Real>
2294 else if (iRay.
inside(t1))
2297 interSeg.
v1 = interSeg.
v0;
2306 template<
typename Real>
2310 if (interNum == 0) {
2325 else if (iRay.
inside(t1))
2328 interSeg.
v1 = interSeg.
v0;
2337 template<
typename Real>
2346 template<
typename Real>
2352 template<
typename Real>
2359 template<
typename Real>
2366 template<
typename Real>
2373 template<
typename Real>
2379 Real a = dir0.normSquared();
2380 Real b = dir0.dot(dir1);
2381 Real c = dir1.normSquared();
2382 Real d = u.dot(dir0);
2383 Real e = u.dot(dir1);
2384 Real det = a * c - b * b;
2394 bool bOpposite = l0 < l1 ? false :
true;
2398 return bOpposite ? -ret : ret;
2407 Real sNum = b * e - c * d;
2408 Real tNum = a * e - b * d;
2418 else if (sNum > det) {
2438 else if (tNum > tDenom) {
2443 else if ((-d + b) > a) {
2452 Real s = sNum / sDenom;
2453 Real t = tNum / tDenom;
2458 template<
typename Real>
2472 template<
typename Real>
2489 template<
typename Real>
2494 Real maxT = D.norm();
2498 Real DdN = D.dot(
N);
2511 Real W1dDxQ = rectangle.
axis[1].dot(DxQ);
2512 if (
abs(W1dDxQ) <= rectangle.
extent[0] * absDdN)
2514 Real W0dDxQ = rectangle.
axis[0].dot(DxQ);
2515 if (
abs(W0dDxQ) <= rectangle.
extent[1] * absDdN)
2517 Real t = -Q.dot(
N) / DdN;
2518 if (t >= 0.f && t <= maxT)
2520 Real s0 = W1dDxQ / DdN;
2521 Real s1 = -W0dDxQ / DdN;
2532 for (
int i = 0; i < 4; i++)
2543 for (
int i = 0; i < 2; i++)
2558 template<
typename Real>
2575 template<
typename Real>
2592 template<
typename Real>
2597 for (
int i = 1; i < 4; i++)
2606 template<
typename Real>
2612 template<
typename Real>
2618 template<
typename Real>
2621 return proximity(segment).lengthSquared();
2624 template<
typename Real>
2627 return proximity(triangle).lengthSquared();
2630 template<
typename Real>
2652 template<
typename Real>
2657 Coord3D e0 = triangle.
v[1] - triangle.
v[0];
2658 Coord3D e1 = triangle.
v[2] - triangle.
v[0];
2659 Coord3D normal = e0.cross(e1);
2661 Real DdN = dir.dot(normal);
2677 Real DdQxE1 =
sign * dir.dot(diff.cross(e1));
2678 if (DdQxE1 >= (
Real)0)
2680 Real DdE0xQ =
sign * dir.dot(e0.cross(diff));
2681 if (DdE0xQ >= (
Real)0)
2683 if (DdQxE1 + DdE0xQ <= DdN)
2686 Real QdN = -
sign * diff.dot(normal);
2708 template<
typename Real>
2714 Real a1 = dir.dot(diff);
2717 Real discr = a1 * a1 - a0;
2718 if (discr > (
Real)0)
2720 Real root = glm::sqrt(discr);
2739 else if (discr < (
Real)0)
2755 template<
typename Real>
2770 if ((0.0f <= t0 && t0 <= 1.0f) && (0.0f <= t1 && t1 <= 1.0f))
2772 interSeg.
v0 =
v0 + t0 * lineDir;
2773 interSeg.
v1 =
v0 + t1 * lineDir;
2776 else if ((0.0f <= t1 && t1 <= 1.0f))
2778 interSeg.
v0 =
v0 + t1 * lineDir;
2779 interSeg.
v1 = interSeg.
v0;
2782 else if ((0.0f <= t0 && t0 <= 1.0f))
2784 interSeg.
v0 =
v0 + t0 * lineDir;
2785 interSeg.
v1 = interSeg.
v0;
2794 template<
typename Real>
2800 Coord3D v0Prime =
Coord3D(diff0.dot(obb.
u), diff0.dot(obb.
v), diff0.dot(obb.
w));
2801 Coord3D v1Prime =
Coord3D(diff1.dot(obb.
u), diff1.dot(obb.
v), diff1.dot(obb.
w));
2811 Coord3D p = pPrime[0] * obb.
u + pPrime[1] * obb.
v + pPrime[2] * obb.
w + obb.
center;
2812 Coord3D q = qPrime[0] * obb.
u + qPrime[1] * obb.
v + qPrime[2] * obb.
w + obb.
center;
2819 template<
typename Real>
2822 return (
v1 -
v0).norm();
2825 template<
typename Real>
2828 return (
v1 -
v0).normSquared();
2831 template<
typename Real>
2836 Real d2 = dir.normSquared();
2841 template<
typename Real>
2851 template<
typename Real>
2857 template<
typename Real>
2864 template<
typename Real>
2871 template<
typename Real>
2878 template<
typename Real>
2884 template<
typename Real>
2892 template<
typename Real>
2900 template<
typename Real>
2903 v[0] = triangle.
v[0];
2904 v[1] = triangle.
v[1];
2905 v[2] = triangle.
v[2];
2908 template<
typename Real>
2911 return Real(0.5) * ((
v[1] -
v[0]).cross(
v[2] -
v[0])).norm();
2914 template<
typename Real>
2926 template<
typename Real>
2943 Real d00 = d0.dot(d0);
2944 Real d01 = d0.dot(d1);
2945 Real d11 = d1.dot(d1);
2946 Real d20 = d2.dot(d0);
2947 Real d21 = d2.dot(d1);
2948 Real denom = d00 * d11 - d01 * d01;
2950 bary.
v = (d11 * d20 - d01 * d21) / denom;
2951 bary.
w = (d00 * d21 - d01 * d20) / denom;
2952 bary.
u =
Real(1) - bary.
v - bary.
w;
2958 template<
typename Real>
2963 return v[0] + bary.
v * d0 + bary.
w * d1;
2967 template<
typename Real>
2973 template<
typename Real>
2980 template<
typename Real>
2991 template<
typename Real>
3000 q[0] = triangle.
v[0];
3001 q[1] = triangle.
v[1];
3002 q[2] = triangle.
v[2];
3005 Real minD = (q[0] - p[0]).normSquared();
3008 for (
int st = 0; st < 3; st++)
3011 int ind1 = (st + 1) % 3;
3015 for (
int st = 0; st < 3; st++)
3018 int ind1 = (st + 1) % 3;
3038 template<
typename Real>
3044 template<
typename Real>
3053 template<
typename Real>
3062 template<
typename Real>
3071 template<
typename Real>
3094 template<
typename Real>
3100 template<
typename Real>
3106 template<
typename Real>
3112 template<
typename Real>
3124 par.
u = offset.dot(
axis[0]);
3125 par.
v = offset.dot(
axis[1]);
3130 template<
typename Real>
3145 template<
typename Real>
3153 template<
typename Real>
3162 template<
typename Real>
3170 template<
typename Real>
3176 template<
typename Real>
3182 template<
typename Real>
3190 template<
typename Real>
3198 template<
typename Real>
3206 template<
typename Real>
3214 template<
typename Real>
3220 template<
typename Real>
3227 template<
typename Real>
3238 template<
typename Real>
3249 template<
typename Real>
3261 template<
typename Real>
3273 template<
typename Real>
3284 template<
typename Real>
3295 template<
typename Real>
3306 template<
typename Real>
3315 template<
typename Real>
3318 center = 0.5f * (v0 + v1);
3319 Real len = (v1 - v0).norm();
3326 template<
typename Real>
3335 template<
typename Real>
3344 template<
typename Real>
3351 template<
typename Real>
3357 template<
typename Real>
3368 template<
typename Real>
3377 template<
typename Real>
3386 template<
typename Real>
3395 template<
typename Real>
3423 template<
typename Real>
3449 template<
typename Real>
3456 v0 =
v[0]; v1 =
v[1]; v2 =
v[3]; v3 =
v[2];
3459 v0 =
v[1]; v1 =
v[0]; v2 =
v[2]; v3 =
v[3];
3462 v0 =
v[2]; v1 =
v[0]; v2 =
v[3]; v3 =
v[1];
3465 v0 =
v[3]; v1 =
v[0]; v2 =
v[1]; v3 =
v[2];
3479 Real dividend = A.dot(B.cross(C));
3480 Real divisor = a * b * c + A.dot(B) * c + A.dot(C) * b + B.dot(C) * a;
3482 Real angle = 2 * glm::atan(glm::abs(dividend) / divisor);
3484 if (dividend > 0 && divisor < 0) angle +=
M_PI;
3489 template<
typename Real>
3493 M.setRow(0,
v[1] -
v[0]);
3494 M.setRow(1,
v[2] -
v[0]);
3495 M.setRow(2,
v[3] -
v[0]);
3497 return M.determinant() /
Real(6);
3500 template<
typename Real>
3507 template<
typename Real>
3511 center = (
v[0] +
v[1] +
v[2] +
v[3]) / 4.0f;
3512 for (
int idx = 0; idx < 4; idx++)
3515 Real rr = dir.norm();
3518 v[idx] = dir * rr + center;
3522 template<
typename Real>
3529 Coord3D mid = (tet2.
v[0] + tet2.
v[1] + tet2.
v[2] + tet2.
v[3]) / 4.0f;
3530 Coord3D v11 = mid + (tet2.
v[0] - mid) / (tet2.
v[0] - mid).norm() * ((tet2.
v[0] - mid).norm());
3531 Coord3D v22 = mid + (tet2.
v[1] - mid) / (tet2.
v[1] - mid).norm() * ((tet2.
v[1] - mid).norm());
3532 Coord3D v33 = mid + (tet2.
v[2] - mid) / (tet2.
v[2] - mid).norm() * ((tet2.
v[2] - mid).norm());
3533 Coord3D v44 = mid + (tet2.
v[3] - mid) / (tet2.
v[3] - mid).norm() * ((tet2.
v[3] - mid).norm());
3536 Real inter_dist_0 = 0.0f;
3537 Coord3D p11, p22, interNorm_0;
3563 for (
int i = 0; i < 18; i++)
3565 if (i >= 6 && !(inter_dist_0 < -0.000f))
3573 Real left = (tmp_seg.
v0 - s[i].
v0).
dot(s[i].direction().normalize());
3574 Real right = (tmp_seg.
v1 - s[i].
v0).
dot(s[i].direction().normalize());
3581 Real maxx = (s[i].
v1 - s[i].
v0).
dot(s[i].direction().normalize());
3582 if (right < 0 || left > maxx)
3587 p1 = s[i].
v0 + ((left + right) / 2.0f * s[i].
direction().normalize());
3590 interDist = -(p1 - p2).norm();
3596 if ((p11 - p22).norm() >
abs(interDist))
3599 interDist = -(p1 - p2).norm();
3602 p11 = s[i].
v0 + right * s[i].
direction().normalize();
3604 if ((p11 - p22).norm() >
abs(interDist))
3607 interDist = -(p1 - p2).norm();
3610 Coord3D dir = (p1 - p2) / interDist;
3614 if (interDist < inter_dist_0)
3616 inter_dist_0 = interDist;
3619 interNorm_0 = interNorm;
3622 if (need_distance == 0)
3623 if (inter_dist_0 < -0.000f)
3625 interDist = inter_dist_0;
3628 interNorm = interNorm_0;
3629 interDist += 0.0000f;
3636 if (inter_dist_0 < -0.000f)
3638 interDist = inter_dist_0;
3641 interNorm = interNorm_0;
3642 interDist += 0.0000f;
3649 template<
typename Real>
3659 Real inter_dist_0 = 0.0f;
3660 Coord3D p11, p22, interNorm_0;
3668 for (
int i = 0; i < 3; i++)
3677 Real left = (tmp_seg.
v0 - s[i].
v0).
dot(s[i].direction().normalize());
3678 Real right = (tmp_seg.
v1 - s[i].
v0).
dot(s[i].direction().normalize());
3685 Real maxx = (s[i].
v1 - s[i].
v0).
dot(s[i].direction().normalize());
3686 if (right < 0 || left > maxx)
3691 p2 = s[i].
v0 + ((left + right) / 2.0f * s[i].
direction().normalize());
3694 interDist = -(p1 - p2).norm();
3699 if ((p11 - p22).norm() >
abs(interDist))
3702 interDist = -(p1 - p2).norm();
3705 p11 = s[i].
v0 + right * s[i].
direction().normalize();
3707 if ((p11 - p22).norm() >
abs(interDist))
3710 interDist = -(p1 - p2).norm();
3713 Coord3D dir = (p1 - p2) / interDist;
3717 if (interDist < inter_dist_0)
3719 inter_dist_0 = interDist;
3722 interNorm_0 = interNorm;
3730 if (inter_dist_0 < -0.000f)
3732 interDist = inter_dist_0;
3735 interNorm = interNorm_0;
3736 interDist += 0.0000f;
3763 for (
int i = 0; i < 18; i++)
3772 Real left = (tmp_point.
origin - s[i].
v0).
dot(s[i].direction().normalize());
3773 Real maxx = (s[i].
v1 - s[i].
v0).
dot(s[i].direction().normalize());
3775 if (left < 0 || left > maxx)
3778 if (left < maxx / 2.0f)
3783 interDist = -(p1 - p2).norm();
3784 Coord3D dir = (p1 - p2) / interDist;
3789 if (inter_dist_0 < -0.000f)
3791 interDist = inter_dist_0;
3794 interNorm = interNorm_0;
3795 interDist += 0.0000f;
3804 template<
typename Real>
3819 template<
typename Real>
3825 Real ba_x =
v[1][0] -
v[0][0];
3826 Real ba_y =
v[1][1] -
v[0][1];
3827 Real ba_z =
v[1][2] -
v[0][2];
3830 Real ca_x =
v[2][0] -
v[0][0];
3831 Real ca_y =
v[2][1] -
v[0][1];
3832 Real ca_z =
v[2][2] -
v[0][2];
3835 Real da_x =
v[3][0] -
v[0][0];
3836 Real da_y =
v[3][1] -
v[0][1];
3837 Real da_z =
v[3][2] -
v[0][2];
3840 Real len_ba = ba_x * ba_x + ba_y * ba_y + ba_z * ba_z;
3841 Real len_ca = ca_x * ca_x + ca_y * ca_y + ca_z * ca_z;
3842 Real len_da = da_x * da_x + da_y * da_y + da_z * da_z;
3847 Real cross_cd_x = ca_y * da_z - da_y * ca_z;
3848 Real cross_cd_y = ca_z * da_x - da_z * ca_x;
3849 Real cross_cd_z = ca_x * da_y - da_x * ca_y;
3852 Real cross_db_x = da_y * ba_z - ba_y * da_z;
3853 Real cross_db_y = da_z * ba_x - ba_z * da_x;
3854 Real cross_db_z = da_x * ba_y - ba_x * da_y;
3857 Real cross_bc_x = ba_y * ca_z - ca_y * ba_z;
3858 Real cross_bc_y = ba_z * ca_x - ca_z * ba_x;
3859 Real cross_bc_z = ba_x * ca_y - ca_x * ba_y;
3862 Real denominator = 0.5 / (ba_x * cross_cd_x + ba_y * cross_cd_y + ba_z * cross_cd_z);
3865 Real circ_x = (len_ba * cross_cd_x + len_ca * cross_db_x + len_da * cross_bc_x) * denominator;
3866 Real circ_y = (len_ba * cross_cd_y + len_ca * cross_db_y + len_da * cross_bc_y) * denominator;
3867 Real circ_z = (len_ba * cross_cd_z + len_ca * cross_db_z + len_da * cross_bc_z) * denominator;
3872 template<
typename Real>
3878 template<
typename Real>
3884 template<
typename Real>
3888 v[0].y -
v[3].y,
v[1].y -
v[3].y,
v[2].y -
v[3].y,
3889 v[0].z -
v[3].z,
v[1].z -
v[3].z,
v[2].z -
v[3].z);
3895 return Vector<Real, 4>(lambda.x, lambda.y, lambda.z,
Real(1) - lambda.x - lambda.y - lambda.z);
3898 template<
typename Real>
3905 template<
typename Real>
3912 template<
typename Real>
3919 template<
typename Real>
3922 for (
int i = 0; i < 3; i++)
3924 if (
v1[i] <= abox.
v0[i] ||
v0[i] >= abox.
v1[i])
3930 interBox.
v0 =
v0.maximum(abox.
v0);
3931 interBox.
v1 =
v1.minimum(abox.
v1);
3933 for (
int i = 0; i < 3; i++)
3935 if (
v1[i] <= abox.
v1[i])
3937 interBox.
v1[i] =
v1[i];
3941 interBox.
v1[i] = abox.
v1[i];
3944 if (
v0[i] <= abox.
v0[i])
3946 interBox.
v0[i] = abox.
v0[i];
3950 interBox.
v0[i] =
v0[i];
3958 template<
typename Real>
3961 for (
int i = 0; i < 3; i++)
3963 if (
v1[i] <= abox.
v0[i] ||
v0[i] >= abox.
v1[i])
3973 template<
typename Real>
3977 ret.
v0 =
v0.minimum(aabb.
v0);
3978 ret.
v1 =
v1.maximum(aabb.
v1);
3984 template<
typename Real>
4025 Coord3D m_triangle_index[12][3] = {
4040 for (
int i = 0; i < 12; i++)
4065 template<
typename Real>
4079 template<
typename Real>
4082 return v1[0] >
v0[0] &&
v1[1] >
v0[1] &&
v1[2] >
v0[2];
4085 template<
typename Real>
4096 template<
typename Real>
4106 template<
typename Real>
4118 template<
typename Real>
4128 template<
typename Real>
4136 return TPoint3D<Real>(
center + (2 * (
id & 1) - 1) * hu + (2 * ((
id >> 1) & 1) - 1) * hv + (2 * ((
id >> 2) & 1) - 1) * hw);
4139 template<
typename Real>
4149 template<
typename Real>
4193 template<
typename Real>
4199 template<
typename Real>
4219 template<
typename Real>
4225 obox.
u = mat * obox.
u;
4226 obox.
v = mat * obox.
v;
4227 obox.
w = mat * obox.
w;
4233 template<
typename Real>
4251 template<
typename Real>
4272 Real distance = 1.0f;
4280 for (
int i = 0; i < 8; i++)
4283 Real tmp = offset_self.dot(OBB.
u);
4284 if (i == 0) min_u = max_u = tmp;
4291 if (max_u < -OBB.
extent[0] || min_u > OBB.
extent[0])
return false;
4300 for (
int i = 0; i < 8; i++)
4303 Real tmp = offset_self.dot(OBB.
v);
4304 if (i == 0) min_v = max_v = tmp;
4311 if (max_v < -OBB.
extent[1] || min_v > OBB.
extent[1])
return false;
4313 if (inter_v < inter)
4323 for (
int i = 0; i < 8; i++)
4326 Real tmp = offset_self.dot(OBB.
w);
4327 if (i == 0) min_w = max_w = tmp;
4334 if (max_w < -OBB.
extent[2] || min_w > OBB.
extent[2]) {
return false; }
4336 if (inter_w < inter)
4346 for (
int i = 0; i < 8; i++)
4349 if (tmp < distance && p[i].distance(OBB) <
EPSILON)
4356 for (
int i = 0; i < 12; i++)
4359 if (s[i].intersect(OBB, tmp))
4363 if (tmp_distance < distance)
4369 distance = tmp_distance;
4377 if (distance >
EPSILON)
return false;
4378 interDist = distance;
4395 p2 = pt.
project(plane1).origin;
4400 p2 = pt.
project(plane2).origin;
4407 template<
typename Real>
4451 for (
int i = 0; i < 12; i++)
4459 Real left = (tmp_seg.
v0 - s[i].
v0).
dot(s[i].direction().normalize());
4460 Real right = (tmp_seg.
v1 - s[i].
v0).
dot(s[i].direction().normalize());
4467 Real maxx = (s[i].
v1 - s[i].
v0).
dot(s[i].direction().normalize());
4468 if (right < 0 || left > maxx)
4479 if ((p11 - p22).norm() >
abs(interDist))
4481 interDist = -(p11 - p22).norm();
4485 p11 = s[i].
v0 + left * s[i].
direction().normalize();
4487 if ((p11 - p22).norm() >
abs(interDist))
4490 interDist = -(p1 - p2).norm();
4493 p11 = s[i].
v0 + right * s[i].
direction().normalize();
4495 if ((p11 - p22).norm() >
abs(interDist))
4498 interDist = -(p1 - p2).norm();
4505 for (
int i = 0; i < 18; i++)
4509 if (s_tet[i].intersect(OBB, tmp))
4534 if (interDist > -
EPSILON)
return false;
4535 interNorm = (p1 - p2) / interDist;
4540 template<
typename Real>
4571 for (
int i = 0; i < 3; i++)
4575 if (s_tri[i].intersect(OBB, tmp))
4600 interNorm = (p1 - p2) / interDist;
4604 for (
int i = 0; i < 12; i++)
4607 if (s[i].intersect(TRI, tmp_point))
4630 interNorm = (p1 - p2) / interDist;
DYN_FUNC bool inside(Real val) const
DYN_FUNC Real rightLimit() const
DYN_FUNC Real leftLimit() const
DYN_FUNC SquareMatrix< Real, 3 > toMatrix3x3() const
SquareMatrix< Real, 3 > Matrix3D
Vector< Real, 3 > Coord3D
DYN_FUNC bool checkOverlap(const TAlignedBox3D< Real > &abox) const
DYN_FUNC bool intersect(const TAlignedBox3D< Real > &abox, TAlignedBox3D< Real > &interBox) const
DYN_FUNC bool meshInsert(const TTriangle3D< Real > &tri) const
DYN_FUNC TOrientedBox3D< Real > rotate(const Matrix3D &mat)
DYN_FUNC TAlignedBox3D< Real > merge(const TAlignedBox3D< Real > &aabb) const
DYN_FUNC Real volume() const
DYN_FUNC TSegment3D< Real > centerline() const
Vector< Real, 3 > Coord3D
DYN_FUNC bool isValid() const
DYN_FUNC Coord3D endPoint() const
DYN_FUNC TAlignedBox3D< Real > aabb() const
DYN_FUNC Coord3D startPoint() const
Vector< Real, 3 > Coord3D
Vector< Real, 3 > Coord3D
Vector< Real, 3 > Coord3D
1D geometric primitives in three-dimensional space
DYN_FUNC TSegment3D< Real > proximity(const TLine3D< Real > &line) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC int intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
intersection tests
DYN_FUNC bool isValid() const
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
Vector< double, 3 > Coord3D
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
DYN_FUNC TOrientedBox3D()
Vector< Real, 2 > Coord2D
Coord3D u
three unit vectors u, v and w forming a right-handed orthornormal basis
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC TSegment3D< Real > edge(const int i) const
Vector< Real, 3 > Coord3D
DYN_FUNC TRectangle3D< Real > face(const int i) const
Coord3D extent
half the dimension in each of the u, v, and w directions
SquareMatrix< Real, 3 > Matrix3D
DYN_FUNC bool point_intersect(const TOrientedBox3D< Real > &OBB, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2) const
Coord3D center
centerpoint
DYN_FUNC TOrientedBox3D< Real > rotate(const Matrix3D &mat)
DYN_FUNC TAlignedBox3D< Real > aabb()
2D geometric primitives in three-dimensional space
DYN_FUNC bool isValid() const
Vector< double, 3 > Coord3D
Coord3D normal
the plane will be treated as a single point if its normal is zero
0D geometric primitive in three-dimensional space
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
DYN_FUNC TPoint3D & operator=(const Coord3D &p)
DYN_FUNC TPoint3D< Real > project(const TPlane3D< Real > &plane) const
project a point onto planar components – planes, triangles and disks
Vector< double, 2 > Coord2D
DYN_FUNC TPoint3D< Real > project(const TLine3D< Real > &line) const
project a point onto linear components – lines, rays and segments
DYN_FUNC const TSegment3D< Real > operator-(const TPoint3D< Real > &pt) const
DYN_FUNC bool inside(const TLine3D< Real > &line) const
check whether a point strictly lies inside (excluding boundary) a 1D geometric primitive
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
Vector< Real, 3 > Coord3D
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC bool isValid() const
DYN_FUNC int intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
Vector< double, 3 > Coord3D
DYN_FUNC TSegment3D< Real > proximity(const TRay3D< Real > &ray) const
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
Coord3D axis[2]
two orthonormal unit axis
Vector< Real, 2 > Coord2D
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC bool computeParams(const Coord3D &p, Param &par) const
Vector< double, 3 > Coord3D
DYN_FUNC TSegment3D< Real > edge(const int i) const
DYN_FUNC Coord3D normal() const
DYN_FUNC Real area() const
DYN_FUNC bool isValid() const
DYN_FUNC Real distance(const TSegment3D< Real > &segment) const
DYN_FUNC Coord3D & endPoint()
DYN_FUNC TSegment3D< Real > operator-(void) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC Real lengthSquared() const
DYN_FUNC Coord3D direction() const
DYN_FUNC TSegment3D< Real > proximity(const TSegment3D< Real > &segment) const
DYN_FUNC bool isValid() const
DYN_FUNC Real length() const
Vector< double, 3 > Coord3D
DYN_FUNC bool intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
DYN_FUNC Coord3D & startPoint()
DYN_FUNC Real distanceSquared(const TSegment3D< Real > &segment) const
3D geometric primitives in three-dimensional space
Vector< Real, 3 > Coord3D
DYN_FUNC TAlignedBox3D< Real > aabb()
vertices are ordered so that the normal vectors for the triangular faces point outwards 3 / | \ 0 - 2...
DYN_FUNC TPoint3D< Real > circumcenter() const
DYN_FUNC bool contain(Coord3D p)
DYN_FUNC TPoint3D< Real > barycenter() const
Vector< double, 3 > Coord3D
SquareMatrix< Real, 3 > Matrix3D
DYN_FUNC bool isValid() const
DYN_FUNC TSegment3D< Real > edge(const int index) const
DYN_FUNC bool intersect(const TTet3D< Real > &tet, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2, int need_distance=1) const
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC Vector< Real, 4 > computeBarycentricCoordinates(const Coord3D &p)
DYN_FUNC void expand(Real r)
DYN_FUNC TTriangle3D< Real > face(const int index) const
DYN_FUNC Real solidAngle(const int index) const
DYN_FUNC Real volume() const
DYN_FUNC Real distance(const TTriangle3D< Real > &triangle) const
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC Coord3D computeLocation(const Param &bary) const
Vector< Real, 3 > Coord3D
DYN_FUNC bool isValid() const
DYN_FUNC Real maximumEdgeLength() const
DYN_FUNC bool computeBarycentrics(const Coord3D &p, Param &bary) const
DYN_FUNC Real area() const
DYN_FUNC Real distanceSquared(const TTriangle3D< Real > &triangle) const
DYN_FUNC Coord3D normal() const
This is an implementation of AdditiveCCD based on peridyno.
DYN_FUNC int sign(T const &a, T const EPS=EPSILON)
constexpr Real REAL_EPSILON_SQUARED
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
DYN_FUNC T abs(const T &v)
Vector< uint32_t, 2 > Vec2u
DYN_FUNC T minimum(const T &v0, const T &v1)
::dyno::TAlignedBox3D< Real > AABB
constexpr Real REAL_EPSILON
DYN_FUNC T clamp(const T &v, const T &lo, const T &hi)
DYN_FUNC T maximum(const T &v0, const T &v1)
DYN_FUNC int clip(ClipVertex *outVerts, float *outDepths, const Vector< Real, 3 > &rPos, const Vector< Real, 3 > &e, unsigned char *clipEdges, const SquareMatrix< Real, 3 > &basis, ClipVertex *incident)