30#define PI 3.1415926535897932384626433832795
43 WXYZ(
double W,
double X,
double Y,
double Z) {
w=W;
x=X;
y=Y;
z=Z;}
45 WXYZ(
double Coords[4]) {
w=Coords[0];
x=Coords[1];
y=Coords[2];
z=Coords[3];}
51 WXYZ(
double dAzimuth,
double dElevation,
double dTilt);
69 return (!
x && !
y && !
z);
96 XYZ(
double X,
double Y,
double Z) {
x=X;
y=Y;
z=Z;}
98 XYZ(
double Coords[3]) {
x=Coords[0];
y=Coords[1];
z=Coords[2];}
108 XY(
double X,
double Y) {
x=X;
y=Y;}
110 XY(
double Coords[2]) {
x=Coords[0];
y=Coords[1];}
114 return x == right.
x &&
y == right.
y;
121 operator bool()
const
146 return XY(Val.
x, Val.
y);
151 return (left.
x==right.
x && left.
y==right.
y && left.
z==right.
z);
156 return (left.
x==value && left.
y==value && left.
z==value);
161 return (left.
x==value && left.
y==value && left.
z==value);
167 ReturnVal.
w = left.
w + right.
w;
168 ReturnVal.
x = left.
x + right.
x;
169 ReturnVal.
y = left.
y + right.
y;
170 ReturnVal.
z = left.
z + right.
z;
177 ReturnVal.
x = left.
x + right.
x;
178 ReturnVal.
y = left.
y + right.
y;
179 ReturnVal.
z = left.
z + right.
z;
186 ReturnVal.
x = left.
x + right.
x;
187 ReturnVal.
y = left.
y + right.
y;
218 ReturnVal.
w = left.
w - right.
w;
219 ReturnVal.
x = left.
x - right.
x;
220 ReturnVal.
y = left.
y - right.
y;
221 ReturnVal.
z = left.
z - right.
z;
228 ReturnVal.
x = left.
x - right.
x;
229 ReturnVal.
y = left.
y - right.
y;
230 ReturnVal.
z = left.
z - right.
z;
237 ReturnVal.
x = left.
x - right.
x;
238 ReturnVal.
y = left.
y - right.
y;
270 Quaternion.
w = left.
w * right.
w - left.
x * right.
x - left.
y * right.
y - left.
z * right.
z;
271 Quaternion.
x = left.
w * right.
x + left.
x * right.
w + left.
y * right.
z - left.
z * right.
y;
272 Quaternion.
y = left.
w * right.
y + left.
y * right.
w + left.
z * right.
x - left.
x * right.
z;
273 Quaternion.
z = left.
w * right.
z + left.
z * right.
w + left.
x * right.
y - left.
y * right.
x;
280 ReturnVal.
x = left.
x * right.
x;
281 ReturnVal.
y = left.
y * right.
y;
282 ReturnVal.
z = left.
z * right.
z;
289 ReturnVal.
x = left.
x * right.
x;
290 ReturnVal.
y = left.
y * right.
y;
298 ReturnVal.
x = left.
x / right.
x;
299 ReturnVal.
y = left.
y / right.
y;
300 ReturnVal.
z = left.
z / right.
z;
308 Quaternion.
w = left.
w * right.
w - left.
x * right.
x - left.
y * right.
y - left.
z * right.
z;
309 Quaternion.
x = left.
w * right.
x + left.
x * right.
w + left.
y * right.
z - left.
z * right.
y;
310 Quaternion.
y = left.
w * right.
y + left.
y * right.
w + left.
z * right.
x - left.
x * right.
z;
311 Quaternion.
z = left.
w * right.
z + left.
z * right.
w + left.
x * right.
y - left.
y * right.
x;
334 ReturnVal.
x = left.
x * right;
335 ReturnVal.
y = left.
y * right;
336 ReturnVal.
z = left.
z * right;
343 ReturnVal.
x = left.
x * right;
344 ReturnVal.
y = left.
y * right;
345 ReturnVal.
z = left.
z * right;
352 ReturnVal.
x = left.
x * right;
353 ReturnVal.
y = left.
y * right;
354 ReturnVal.
z = left.
z * right;
361 ReturnVal.
x = left.
x * right;
362 ReturnVal.
y = left.
y * right;
369 ReturnVal.
x = right.
x * left;
370 ReturnVal.
y = right.
y * left;
371 ReturnVal.
z = right.
z * left;
378 ReturnVal.
x = right.
x * left;
379 ReturnVal.
y = right.
y * left;
380 ReturnVal.
z = right.
z * left;
387 ReturnVal.
x = right.
x * left;
388 ReturnVal.
y = right.
y * left;
389 ReturnVal.
z = right.
z * left;
396 ReturnVal.
x = right.
x * left;
397 ReturnVal.
y = right.
y * left;
404 ReturnVal.
x = left.
x / right;
405 ReturnVal.
y = left.
y / right;
406 ReturnVal.
z = left.
z / right;
413 ReturnVal.
x = left.
x / right;
414 ReturnVal.
y = left.
y / right;
420 double dDivisor = 1/right;
430 double dDivisor = 1/right;
439 double dDivisor = 1/right;
447 left.
x = left.
x * right;
448 left.
y = left.
y * right;
449 left.
z = left.
z * right;
455 left.
x = left.
x * right;
456 left.
y = left.
y * right;
463 ReturnVal.
x = left.
x / right;
464 ReturnVal.
y = left.
y / right;
465 ReturnVal.
z = left.
z / right;
471 output << Quat.
w <<
", " << Quat.
x <<
", " << Quat.
y <<
", " << Quat.
z;
477 output << Vector.
x <<
", " << Vector.
y <<
", " << Vector.
z;
483 output << Vector.
x <<
", " << Vector.
y;
489 input >> Quat.
w; input.ignore();
490 input >> Quat.
x; input.ignore();
491 input >> Quat.
y; input.ignore();
498 input >> Vector.
x; input.ignore();
499 input >> Vector.
y; input.ignore();
506 input >> Vector.
x; input.ignore();
514 return (left.
x*right.
x + left.
y*right.
y + left.
z*right.
z);
520 return (left.
x*right.
x + left.
y*right.
y);
527 ReturnVal.
x = left.
y*right.
z - right.
y*left.
z;
528 ReturnVal.
y = left.
z*right.
x - right.
z*left.
x;
529 ReturnVal.
z = left.
x*right.
y - right.
x*left.
y;
536 return ((
double(rand())/RAND_MAX)*(dMax-dMin))+dMin;
542 return sqrt((Point2.
x-Point1.
x)*(Point2.
x-Point1.
x)+
543 (Point2.
y-Point1.
y)*(Point2.
y-Point1.
y)+
544 (Point2.
z-Point1.
z)*(Point2.
z-Point1.
z));
550 return ((Point2.
x-Point1.
x)*(Point2.
x-Point1.
x)+
551 (Point2.
y-Point1.
y)*(Point2.
y-Point1.
y)+
552 (Point2.
z-Point1.
z)*(Point2.
z-Point1.
z));
558 return sqrt((Point2.
x-Point1.
x)*(Point2.
x-Point1.
x)+
559 (Point2.
y-Point1.
y)*(Point2.
y-Point1.
y));
565 return ((Point2.
x-Point1.
x)*(Point2.
x-Point1.
x)+
566 (Point2.
y-Point1.
y)*(Point2.
y-Point1.
y));
572 return sqrt((Quaternion.
w)*(Quaternion.
w)+
573 (Quaternion.
x)*(Quaternion.
x)+
574 (Quaternion.
y)*(Quaternion.
y)+
575 (Quaternion.
z)*(Quaternion.
z));
581 return sqrt((Vector.
x)*(Vector.
x)+
582 (Vector.
y)*(Vector.
y)+
583 (Vector.
z)*(Vector.
z));
589 return sqrt((Vector.
x)*(Vector.
x)+
590 (Vector.
y)*(Vector.
y));
596 return ((Point.
x)*(Point.
x)+
598 (Point.
z)*(Point.
z));
604 return ((Point.
x)*(Point.
x)+
605 (Point.
y)*(Point.
y));
613 Quaternion /= dLength;
644 double max = Vector.
x;
645 if ( Vector.
y > max )
647 if ( Vector.
z > max )
656 double dCoeff = sin(0.5*dAngle);
665 double dTrace = 1 + X.
x + Y.
y + Z.
z;
669 S = 1/(2*sqrt(dTrace));
678 if ((X.
x > Y.
y)&&(X.
x > Z.
z))
680 S = sqrt( 1.0 + X.
x - Y.
y - Z.
z ) * 2;
682 y = (Y.
x + X.
y ) / S;
683 z = (Z.
x + X.
z ) / S;
684 w = (Y.
z - Z.
y ) / S;
688 S = sqrt( 1.0 + Y.
y - X.
x - Z.
z ) * 2;
689 x = (Y.
x + X.
y ) / S;
691 z = (Z.
y + Y.
z ) / S;
692 w = (Z.
x - X.
z ) / S;
696 S = sqrt( 1.0 + Z.
z - X.
x - Y.
y ) * 2;
697 x = (Z.
x + X.
z ) / S;
698 y = (Z.
y + Y.
z ) / S;
700 w = (X.
y - Y.
x ) / S;
712 inline WXYZ::WXYZ(
double dAzimuth,
double dElevation,
double dTilt)
714 double c1 = cos(dAzimuth / 2);
715 double c2 = cos(dElevation / 2);
716 double c3 = cos(dTilt / 2);
717 double s1 = sin(dAzimuth / 2);
718 double s2 = sin(dElevation / 2);
719 double s3 = sin(dTilt / 2);
720 w = c1*c2*c3 - s1*s2*s3;
721 x = s1*s2*c3 + c1*c2*s3;
722 y = c1*s2*c3 - s1*c2*s3;
723 z = s1*c2*c3 + c1*s2*s3;
731 XYZ qvec(left.
x, left.
y, left.
z);
734 uv *= (2.0f * left.
w);
737 return right + uv + uuv;
751 double dLineLengthSquared;
756 dU =
DotProduct(Point-LineStart, LineEnd-LineStart) / ( dLineLengthSquared );
758 Intersection = LineStart + dU * ( LineEnd - LineStart );
800 denom = (p4.
y-p3.
y)*(p2.
x-p1.
x) - (p4.
x-p3.
x)*(p2.
y-p1.
y);
803 dU1 = (p4.
x-p3.
x)*(p1.
y-p3.
y)-(p4.
y-p3.
y)*(p1.
x-p3.
x);
804 dU2 = (p2.
x-p1.
x)*(p1.
y-p3.
y)-(p2.
y-p1.
y)*(p1.
x-p3.
x);
807 if (dU1 < 0 || dU1 > 1 ||
822 double d1343,d4321,d1321,d4343,d2121;
842 denom = d2121 * d4343 - d4321 * d4321;
847 numer = d1343 * d4321 - d1321 * d4343;
850 dU2 = (d1343 + d4321 * dU1) / d4343;
852 pa = p1 + dU1 * (p2 - p1);
853 pb = p3 + dU2 * (p4 - p3);
921 double dOverlap1, dOverlap2;
939 if (dOverlap1 > dOverlap2)
944 dOverlap1 =
GetLength(p2 - p1) * (mua-1);
946 if (dOverlap1 > dOverlap2)
952 dOverlap2 =
GetLength(p4 - p3) * (mub-1);
953 if (dOverlap1 > dOverlap2)
958 dOverlap1 =
GetLength(p2 - p1) * (mua-1);
959 dOverlap2 =
GetLength(p4 - p3) * (mub-1);
960 if (dOverlap1 > dOverlap2)
972 if (BBox1Min.
x > BBox2Max.
x + dTolerance)
974 if (BBox1Max.
x < BBox2Min.
x - dTolerance)
976 if (BBox1Min.
y > BBox2Max.
y + dTolerance)
978 if (BBox1Max.
y < BBox2Min.
y - dTolerance)
980 if (BBox1Min.
z > BBox2Max.
z + dTolerance)
982 if (BBox1Max.
z < BBox2Min.
z - dTolerance)
990 if (Point.
x > BoxMax.
x + dTolerance)
992 if (Point.
x < BoxMin.
x - dTolerance)
994 if (Point.
y > BoxMax.
y + dTolerance)
996 if (Point.
y < BoxMin.
y - dTolerance)
998 if (Point.
z > BoxMax.
z + dTolerance)
1000 if (Point.
z < BoxMin.
z - dTolerance)
1011 LocalX = Point2-Point1;
1028 double dNumer, dDenom;
1034 Intersection = p1 + (p2-p1)*dU;
1045 const int iMaxIndex = 12;
1046 double ColorArray[iMaxIndex][3] =
1066 }
while (iIndex < 0 || iIndex >= iMaxIndex);
1068 r = ColorArray[iIndex][0];
1069 g = ColorArray[iIndex][1];
1070 b = ColorArray[iIndex][2];
1083 else if (dFraction>1)
1089 if (dFraction > 0.75f)
1091 else if (dFraction > 0.5f)
1092 r = (dFraction-0.5f)*4;
1094 if (dFraction < 0.25f)
1096 else if (dFraction < 0.5f)
1097 b = (0.5f-dFraction)*4;
1099 if (dFraction > 0.75f)
1100 g = (1.0f-dFraction)*4;
1101 else if (dFraction > 0.25f)
1135 Return.
x = P1.
x > P2.
x ? P1.
x : P2.
x;
1136 Return.
y = P1.
y > P2.
y ? P1.
y : P2.
y;
1137 Return.
z = P1.
z > P2.
z ? P1.
z : P2.
z;
1145 Return.
x = P1.
x < P2.
x ? P1.
x : P2.
x;
1146 Return.
y = P1.
y < P2.
y ? P1.
y : P2.
y;
1147 Return.
z = P1.
z < P2.
z ? P1.
z : P2.
z;
1155 Return.
x = P1.
x > P2.
x ? P1.
x : P2.
x;
1156 Return.
y = P1.
y > P2.
y ? P1.
y : P2.
y;
1164 Return.
x = P1.
x < P2.
x ? P1.
x : P2.
x;
1165 Return.
y = P1.
y < P2.
y ? P1.
y : P2.
y;
1171 return int(dValue + (dValue > 0 ? 0.5 : -0.5));
1174 template<
typename T>
1177 double mum1 = 1 - mu;
1179 return (mum1*mum1*mum1)*p1 + (3*mu*mum1*mum1)*p2 + (3*mu*mu*mum1)*p3 + (mu*mu*mu)*p4;
1182 template<
typename T>
1185 double mum1 = 1 - mu;
1187 return (-3*mum1*mum1)*p1 + (3*((mum1*mum1)-2*mu*mum1))*p2 + (3*(2*mu*mum1-mu*mu))*p3 + (3*mu*mu)*p4;
1192 const double A1 = -3.969683028665376e+01;
1193 const double A2 = 2.209460984245205e+02;
1194 const double A3 = -2.759285104469687e+02;
1195 const double A4 = 1.383577518672690e+02;
1196 const double A5 = -3.066479806614716e+01;
1197 const double A6 = 2.506628277459239e+00;
1199 const double B1 = -5.447609879822406e+01;
1200 const double B2 = 1.615858368580409e+02;
1201 const double B3 = -1.556989798598866e+02;
1202 const double B4 = 6.680131188771972e+01;
1203 const double B5 = -1.328068155288572e+01;
1205 const double C1 = -7.784894002430293e-03;
1206 const double C2 = -3.223964580411365e-01;
1207 const double C3 = -2.400758277161838e+00;
1208 const double C4 = -2.549732539343734e+00;
1209 const double C5 = 4.374664141464968e+00;
1210 const double C6 = 2.938163982698783e+00;
1212 const double D1 = 7.784695709041462e-03;
1213 const double D2 = 3.224671290700398e-01;
1214 const double D3 = 2.445134137142996e+00;
1215 const double D4 = 3.754408661907416e+00;
1217 const double P_LOW = 0.02425;
1218 const double P_HIGH = 0.97575;
1226 }
while (p <= 0 || p >= 1);
1228 if (p > 0 && p < P_LOW){
1229 q = sqrt(-2*log(p));
1230 x = (((((C1*q+C2)*q+C3)*q+C4)*q+C5)*q+C6) / ((((D1*q+D2)*q+D3)*q+D4)*q+1);
1232 else if (p >= P_LOW && p <= P_HIGH)
1236 x = (((((A1*r+A2)*r+A3)*r+A4)*r+A5)*r+A6)*q /(((((B1*r+B2)*r+B3)*r+B4)*r+B5)*r+1);
1238 else if (p > P_HIGH && p < 1){
1239 q = sqrt(-2*log(1-p));
1240 x = -(((((C1*q+C2)*q+C3)*q+C4)*q+C5)*q+C6) / ((((D1*q+D2)*q+D3)*q+D4)*q+1);
1242 return x*dStandrdDeviation+dAverage;
1250 for (i=0; i<iNumPoints; ++i)
1253 Point2 = Points[(i+1)%iNumPoints];
1254 dArea += (Point1.
x-Point2.
x)*(Point1.
y+Point2.
y);
1262 const double dTolerance = 1e-6;
1264 XYZ vert0p = P1 - P;
XYZ vert1p = P2 - P;
1266 XYZ vert2p = P3 - P;
1275 const double dTolerance = 1e-6;
1276 XYZ vert0p = P1 - P;
XYZ vert1p = P2 - P;
1278 XYZ vert2p = P3 - P;
1287 XYZ vert0p = P1 - P;
XYZ vert1p = P2 - P;
1288 XYZ vert2p = P3 - P;
1300 dN = (P2.
x-P1.
x)*(P3.
y-P1.
y) - (P3.
x-P1.
x)*(P2.
y-P1.
y);
1305 if ((V1.
x*V2.
y-V2.
x*V1.
y) * dN < 0.0)
1308 if ((V2.
x*V3.
y-V3.
x*V2.
y) * dN < 0.0)
1310 if ((V3.
x*V1.
y-V1.
x*V3.
y) * dN < 0.0)
1332 XYZ ClosestPlanePoint;
1335 ClosestPlanePoint = P+Normal*dDist;
1342 *pTrianglePoint = ClosestPlanePoint;
1356 double dShortestDist = -1;
1358 if (u1 >= 0 && u1 <= 1)
1361 if (dDist < dShortestDist || dShortestDist < 0)
1363 dShortestDist = dDist;
1365 *pTrianglePoint = X1;
1369 if (u2 >= 0 && u2 <= 1)
1372 if (dDist < dShortestDist || dShortestDist < 0)
1374 dShortestDist = dDist;
1376 *pTrianglePoint = X2;
1380 if (u3 >= 0 && u3 <= 1)
1383 if (dDist < dShortestDist || dShortestDist < 0)
1385 dShortestDist = dDist;
1387 *pTrianglePoint = X3;
1394 if (dDist < dShortestDist || dShortestDist < 0)
1396 dShortestDist = dDist;
1398 *pTrianglePoint = P1;
1402 if (dDist < dShortestDist || dShortestDist < 0)
1404 dShortestDist = dDist;
1406 *pTrianglePoint = P2;
1410 if (dDist < dShortestDist || dShortestDist < 0)
1412 dShortestDist = dDist;
1414 *pTrianglePoint = P3;
1417 return dShortestDist;
1424 double denom = (-P1.
x * P3.
y - P2.
x * P1.
y + P2.
x * P3.
y + P1.
y * P3.
x + P2.
y * P1.
x - P2.
y * P3.
x);
1426 if (fabs(denom) >= 1e-6)
1428 Coordinates.
x = (P2.
x * P3.
y - P2.
y * P3.
x - P.
x * P3.
y + P3.
x * P.
y - P2.
x * P.
y + P2.
y * P.
x) / denom;
1429 Coordinates.
y = -(-P1.
x * P.
y + P1.
x * P3.
y + P1.
y * P.
x - P.
x * P3.
y + P3.
x * P.
y - P1.
y * P3.
x) / denom;
1432 Coordinates.
z = 1 - Coordinates.
x - Coordinates.
y;
1441 std::vector<XY>::const_iterator itPoint;
1442 double dClosestDistSqrd = -1;
1444 int iClosestIndex = -1, i;
1445 for (itPoint = Points.begin(), i=0; itPoint != Points.end(); ++itPoint, ++i)
1448 if ( dDistSqrd < dClosestDistSqrd || dClosestDistSqrd == -1 )
1450 dClosestDistSqrd = dDistSqrd;
1454 return iClosestIndex;
1461 std::vector<XY>::const_iterator itPoint;
1462 double dClosestDistSqrd = -1;
1464 int iClosestIndex = -1, i;
1465 for (itPoint = Points.begin(), i=0; itPoint != Points.end(); ++itPoint, ++i)
1468 if ( dDistSqrd < dClosestDistSqrd || dClosestDistSqrd == -1 )
1470 dClosestDistSqrd = dDistSqrd;
1471 if ( dClosestDistSqrd <= dTol )
1475 return iClosestIndex;
1483 int iSize = (int)Points.size();
1484 int iNextInd = (index+1)%iSize;
1486 XYZ Pos(Position.
x, Position.
y, 0);
1487 XYZ p1(Points[index].x, Points[index].y, 0);
1489 XYZ p2(Points[iNextInd].x, Points[iNextInd].y, 0);
1494 iPrevInd = Points[0] == Points[iSize-1] ? iSize-2 : iSize-1;
1495 XYZ p3(Points[iPrevInd].x, Points[iPrevInd].y, 0);
1499 XYZ comp = dDist1 < dDist2 ? p2 : p3;
1503 return XY(pClosest.
x, pClosest.
y);
1510 std::vector<XYZ>::const_iterator itPoint;
1511 double dClosestDistSqrd = -1;
1513 int iClosestIndex = -1, i;
1514 for (itPoint = Points.begin(), i=0; itPoint != Points.end(); ++itPoint, ++i)
1517 if ( dDistSqrd < dClosestDistSqrd || dClosestDistSqrd == -1 )
1519 dClosestDistSqrd = dDistSqrd;
1523 return iClosestIndex;
1530 std::vector<XYZ>::const_iterator itPoint;
1531 double dClosestDistSqrd = -1;
1533 int iClosestIndex = -1, i;
1534 for (itPoint = Points.begin(), i=0; itPoint != Points.end(); ++itPoint, ++i)
1537 if ( dDistSqrd < dClosestDistSqrd || dClosestDistSqrd == -1 )
1539 dClosestDistSqrd = dDistSqrd;
1540 if ( dClosestDistSqrd <= dTol )
1544 return iClosestIndex;
1552 int iSize = (int)Points.size();
1553 int iNextInd = (index+1)%iSize;
1556 XYZ p1(Points[index].x, Points[index].y, Points[index].z);
1558 XYZ p2(Points[iNextInd].x, Points[iNextInd].y, Points[iNextInd].z);
1563 iPrevInd = Points[0] == Points[iSize-1] ? iSize-2 : iSize-1;
1564 XYZ p3(Points[iPrevInd].x, Points[iPrevInd].y, Points[iPrevInd].z);
1566 double dDist1 =
GetLength(Position, p2);
1567 double dDist2 =
GetLength(Position, p3);
1568 XYZ comp = dDist1 < dDist2 ? p2 : p3;
1579 int i, N = (int)Nodes.size();
1583 for (i = 1;i <= N;i++)
1586 if (Point.
y > std::min(p1.
y, p2.
y))
1588 if (Point.
y <= std::max(p1.
y, p2.
y))
1590 if (Point.
x <= std::max(p1.
x, p2.
x))
1594 xinters = (Point.
y - p1.
y)*(p2.
x - p1.
x) / (p2.
y - p1.
y) + p1.
x;
1595 if (p1.
x == p2.
x || Point.
x <= xinters)
1604 if (counter % 2 == 1)
1615 int i, N = (int)Nodes.size();
1619 for (i = 1;i <= N;i++)
1622 if (Point.
y > std::min(p1.
y, p2.
y))
1624 if (Point.
y <= std::max(p1.
y, p2.
y))
1626 if (Point.
x <= std::max(p1.
x, p2.
x))
1630 xinters = (Point.
y - p1.
y)*(p2.
x - p1.
x) / (p2.
y - p1.
y) + p1.
x;
1631 if (p1.
x == p2.
x || Point.
x <= xinters)
1640 if (counter % 2 == 1)
Namespace containing a series of customised math operations not found in the standard c++ library.
double PointInsideTriangleAccuracy(const XYZ &P1, const XYZ &P2, const XYZ &P3, const XYZ &P, const XYZ &N)
P1, P2, P3 are the three triangle corners, P is the points to be tested, N is the normal to the trian...
bool SphereSphereIntersect(const XYZ &p1, const XYZ &p2, double dRadii)
Check if two spheres intersect given their center points and combined radii.
void GetFractionColor(double dFraction, double &r, double &g, double &b)
bool SphereCylinderIntersect(const XYZ &Point, const XYZ &LineStart, const XYZ &LineEnd, double dRadii, double *pdUReturn=NULL)
XYZ GetBarycentricCoordinates(const XY &P1, const XY &P2, const XY &P3, const XY &P)
Get the barycentric coordinates of a point lying on a triangle.
bool GetCircleCenter(const XYZ &A, const XYZ &B, const XYZ &C, XYZ &Center)
double GetLengthSquared(const XYZ &Point1, const XYZ &Point2)
Get the length squared between two points.
double RandomNormalDistribution(double dStandrdDeviation=1, double dAverage=0)
WXYZ & operator-=(WXYZ &left, const WXYZ &right)
WXYZ & operator*=(WXYZ &left, const WXYZ &right)
Grassmann product multiplication between two quaternions.
bool RoundedCylinderIntersect(const XYZ &p1, const XYZ &p2, const XYZ &p3, const XYZ &p4, double dRadii, double *pdU1=NULL, double *pdU2=NULL)
void GetRandomColor(double &r, double &g, double &b)
Create a random color from a set of pre-defined colors.
WXYZ & operator+=(WXYZ &left, const WXYZ &right)
XYZ operator/(const XYZ &left, const XYZ &right)
Do a simple divide of all members, perhaps not mathematically correct but usefull.
bool GetIntersectionLinePlane(const XYZ &p1, const XYZ &p2, const XYZ &p3, const XYZ &N, XYZ &Intersection, double *pdU=NULL)
P1 and P2 are two points on the line, P3 is a point on the plane, N is the plane normal,...
std::istream & operator>>(std::istream &input, WXYZ &Quat)
XYZ ShortestDistPointLine(const XYZ &Point, const XYZ &LineStart, const XYZ &LineEnd, double &dU)
void GetLocalCoordinateSystem(XYZ &LocalX, XYZ &LocalY, XYZ &LocalZ, const XYZ &Point1, const XYZ &Point2)
WXYZ operator+(const WXYZ &left, const WXYZ &right)
XYZ operator*(const CMatrix &Transform, const XYZ &Vector)
bool LineLineIntersect2D(const XY &p1, const XY &p2, const XY &p3, const XY &p4, double &dU1, double &dU2)
XY GetClosestPoint(const std::vector< XY > &Points, const XY Position)
bool operator==(const XYZ &left, const XYZ &right)
int GetClosestPointWithinTol(const std::vector< XY > &Points, const XY Position, double dTol)
bool PointInside(const XY &Point, const std::vector< XY > &Nodes)
WXYZ & operator/=(WXYZ &left, const double &right)
double RandomNumber(double dMin, double dMax)
Generate a random number between the limits given.
WXYZ operator-(const WXYZ &left, const WXYZ &right)
int GetClosestPointIndex(const std::vector< XY > &Points, const XY Position)
double Max(XYZ &Vector)
Get maximum element of vector and return it.
bool PointInsideBox(const XYZ &Point, const XYZ &BoxMin, const XYZ &BoxMax, double dTolerance=0)
Find if a point is inside an Axis Aligned Bounding Box with given tolerance.
bool PointInsideTriangle2D(const XYZ &P1, const XYZ &P2, const XYZ &P3, const XYZ &P, const XYZ *pNormal=NULL)
P1, P2, P3 are the three triangle corners, P is the points to be tested, ignoring the z component.
bool ShortestDistLineLine(const XYZ &p1, const XYZ &p2, const XYZ &p3, const XYZ &p4, double &dU1, double &dU2, XYZ &pa, XYZ &pb)
XY Convert(const XYZ &Val)
double GetLength(const XYZ &Point1, const XYZ &Point2)
Get the length between two points.
T CalculateBezierTangent(T p1, T p2, T p3, T p4, double mu)
XYZ Min(const XYZ &P1, const XYZ &P2)
Given two points, return a new point who's coordinates are the smaller of the two.
ostream & operator<<(ostream &output, CMatrix &Matrix)
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
bool BoundingBoxIntersect(const XYZ &BBox1Min, const XYZ &BBox1Max, const XYZ &BBox2Min, const XYZ &BBox2Max, double dTolerance=0)
Find if two AABBs intersect with given tolerance.
double ShortestDistPointTriangle(const XYZ &P1, const XYZ &P2, const XYZ &P3, const XYZ &P, XYZ *pTrianglePoint=NULL, XYZ *pNormal=NULL)
P1, P2, P3 are the three triangle corners, P is the points to be tested.
double DotProduct(const XYZ &left, const XYZ &right)
Get the dot product of two vectors.
XYZ CrossProduct(const XYZ &left, const XYZ &right)
Get the cross product of two vectors.
double GetArea(XYZ Points[], int iNumPoints)
T CalculateBezierPoint(T p1, T p2, T p3, T p4, double mu)
bool PointInsideTriangle(const XYZ &P1, const XYZ &P2, const XYZ &P3, const XYZ &P)
P1, P2, P3 are the three triangle corners, P is the points to be tested.
Struct for representing a quaternion.
WXYZ(double Coords[4])
Set coordinates to those specified in the constructor.
WXYZ(double W, double X, double Y, double Z)
Set coordinates to those specified in the constructor.
WXYZ()
Set all coordinates to 0 as default constructor.
Struct for representing points in 2D space.
XY()
Set all coordinates to 0 as default constructor.
XY operator-()
Reverse all coordinates.
XY(double X, double Y)
Set coordinates to those specified in the constructor.
bool operator==(const XY &right) const
Overload to see if two XY coordinates are the same.
double & operator[](int i)
XY(double Coords[2])
Set coordinates to those specified in the constructor.
bool operator!() const
Check if all the coordinates are 0.
Struct for representing points in 3D space.
XYZ(double Coords[3])
Set coordinates to those specified in the constructor.
XYZ(double X, double Y, double Z)
Set coordinates to those specified in the constructor.
bool operator!() const
Check if all the coordinates are 0.
double & operator[](int i)
double operator=(double right)
Set all coordinates equal to value.
XYZ operator-()
Reverse all coordinates.
XYZ()
Set all coordinates to 0 as default constructor.