18 template <
typename Real>
25 Real lineParameter, rectangleParameter[2];
34 template <
typename Real>
39 template <
typename Real>
42 Line3<Real> const& line, Rectangle3<Real>
const& rectangle)
49 Real NdD =
Dot(N, line.direction);
56 basis[0] = line.direction;
57 ComputeOrthogonalComplement<Real>(1, basis);
58 Real UdD0 =
Dot(basis[1], rectangle.axis[0]);
59 Real UdD1 =
Dot(basis[1], rectangle.axis[1]);
60 Real UdPmC =
Dot(basis[1], diff);
61 Real VdD0 =
Dot(basis[2], rectangle.axis[0]);
62 Real VdD1 =
Dot(basis[2], rectangle.axis[1]);
63 Real VdPmC =
Dot(basis[2], diff);
64 Real invDet = ((Real)1) / (UdD0*VdD1 - UdD1*VdD0);
67 Real
s0 = (VdD1*UdPmC - UdD1*VdPmC)*invDet;
68 Real
s1 = (UdD0*VdPmC - VdD0*UdPmC)*invDet;
70 if (
std::abs(s0) <= rectangle.extent[0]
71 &&
std::abs(s1) <= rectangle.extent[1])
74 Real DdD0 =
Dot(line.direction, rectangle.axis[0]);
75 Real DdD1 =
Dot(line.direction, rectangle.axis[1]);
76 Real DdDiff =
Dot(line.direction, diff);
77 result.lineParameter = s0*DdD0 + s1*DdD1 - DdDiff;
80 result.rectangleParameter[0] =
s0;
81 result.rectangleParameter[1] =
s1;
84 result.closestPoint[0] = line.origin +
85 result.lineParameter*line.direction;
87 result.closestPoint[1] = rectangle.center +
88 s0*rectangle.axis[0] + s1*rectangle.axis[1];
90 result.distance = (Real)0;
91 result.sqrDistance = (Real)0;
101 result.distance = std::numeric_limits<Real>::max();
102 result.sqrDistance = std::numeric_limits<Real>::max();
105 rectangle.extent[0] * rectangle.axis[0],
106 rectangle.extent[1] * rectangle.axis[1]
108 for (
int i1 = 0, omi1 = 1; i1 <= 1; ++i1, --omi1)
110 for (
int i0 = -1; i0 <= 1; i0 += 2)
113 rectangle.center + scaledDir[i1] * (Real)i0;
115 Real segExtent = rectangle.extent[omi1];
119 auto lsResult =
query(line, segment);
120 if (lsResult.sqrDistance < result.sqrDistance)
122 result.sqrDistance = lsResult.sqrDistance;
123 result.distance = lsResult.distance;
124 result.lineParameter = lsResult.parameter[0];
125 Real ratio = lsResult.parameter[1] / segExtent;
126 result.rectangleParameter[0] =
127 rectangle.extent[0] * (omi1 * i0 + i1 * ratio);
128 result.rectangleParameter[1] =
129 rectangle.extent[1] * (i1 * i0 + omi1 * ratio);
130 result.closestPoint[0] = lsResult.closestPoint[0];
131 result.closestPoint[1] = lsResult.closestPoint[1];
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
GLsizei GLsizei GLfloat distance
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1