28 template <
typename Real>
37 int& plane1, Real D[3]);
46 template <
typename Real>
53 std::vector<Vector3<Real>> A(numPoints);
54 for (
int i = 0; i < numPoints; ++i)
67 template <
typename Real>
69 int& plane0,
int& plane1, Real D[3])
72 Real xDir = A[plane0][1] * A[plane1][2] - A[plane1][1] * A[plane0][2];
73 Real yDir = A[plane0][2] * A[plane1][0] - A[plane1][2] * A[plane0][0];
74 Real zDir = A[plane0][0] * A[plane1][1] - A[plane1][0] * A[plane0][1];
77 Real a0 = D[0] * D[1] * zDir + D[0] * D[2] * yDir + D[1] * D[2] * xDir;
78 Real a1 = ((Real)2)*(D[2] * xDir*yDir + D[1] * xDir*zDir + D[0] * yDir*zDir);
79 Real a2 = ((Real)3)*(xDir*yDir*zDir);
85 Real invA2 = ((Real)1) / a2;
86 Real discr = a1*a1 - ((Real)4)*a0*a2;
87 discr = sqrt(std::max(discr, (Real)0));
88 tFinal = -((Real)0.5)*(a1 + discr)*invA2;
89 if (a1 + ((Real)2)*a2*tFinal > (Real)0)
91 tFinal = ((Real)0.5)*(-a1 + discr)*invA2;
94 else if (a1 != (Real)0)
98 else if (a0 != (Real)0)
100 Real fmax = std::numeric_limits<Real>::max();
101 tFinal = (a0 >= (Real)0 ? fmax : -fmax);
108 if (tFinal < (Real)0)
120 int numPoints =
static_cast<int>(A.size());
121 for (
int i = 0; i < numPoints; ++i)
123 if (i == plane0 || i == plane1)
128 Real norDotDir = A[i][0] * xDir + A[i][1] * yDir + A[i][2] * zDir;
129 if (norDotDir <= (Real)0)
139 Real numer = (Real)1 - A[i][0] * D[0] - A[i][1] * D[1] - A[i][2] * D[2];
148 Real
t = numer / norDotDir;
149 if (0 <= t && t < tMax)
175 template <
typename Real>
177 int& plane0, Real D[3])
179 Real tFinal, xDir, yDir, zDir;
181 if (A[plane0][0] > (Real)0
182 && A[plane0][1] > (Real)0
183 && A[plane0][2] > (Real)0)
186 Real oneThird = ((Real)1) / (Real)3;
187 Real xMax = oneThird / A[plane0][0];
188 Real yMax = oneThird / A[plane0][1];
189 Real zMax = oneThird / A[plane0][2];
199 tFinal = std::numeric_limits<Real>::max();
201 if (A[plane0][0] > (Real)0)
210 if (A[plane0][1] > (Real)0)
219 if (A[plane0][2] > (Real)0)
232 int numPoints =
static_cast<int>(A.size());
233 for (
int i = 0; i < numPoints; ++i)
240 Real norDotDir = A[i][0] * xDir + A[i][1] * yDir + A[i][2] * zDir;
241 if (norDotDir <= (Real)0)
251 Real numer = (Real)1 - A[i][0] * D[0] - A[i][1] * D[1] - A[i][2] * D[2];
260 Real
t = numer / norDotDir;
261 if (0 <= t && t < tMax)
287 template <
typename Real>
299 std::uniform_real_distribution<Real> rnd((Real)0, (Real)1);
300 Real maxJitter = (Real)1e-12;
301 int numPoints =
static_cast<int>(A.size());
303 for (i = 0; i < numPoints; ++i)
305 A[i][0] += maxJitter*rnd(mte);
306 A[i][1] += maxJitter*rnd(mte);
307 A[i][2] += maxJitter*rnd(mte);
313 for (i = 0; i < numPoints; ++i)
321 LogAssert(plane != -1,
"Unexpected condition.");
326 D[2] = ((Real)1) /
zmax;
#define LogAssert(condition, message)
void operator()(int numPoints, Vector3< Real > const *points, Vector3< Real > const &C, Matrix3x3< Real > const &R, Real D[3])
GLfixed GLfixed GLint GLint GLfixed points
void FindEdgeMax(std::vector< Vector3< Real >> &A, int &plane0, int &plane1, Real D[3])
#define LogError(message)
void FindFacetMax(std::vector< Vector3< Real >> &A, int &plane0, Real D[3])
void MaxProduct(std::vector< Vector3< Real >> &A, Real D[3])