43#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_SEGMENT_3D_RAY_3D_H
44#define LASS_GUARDIAN_OF_INCLUSION_PRIM_LINE_SEGMENT_3D_RAY_3D_H
56template<
typename T,
class PP1,
class NP2,
class PP2>
61 return num::sqrt(squaredDistance(lineSegment, ray, tMin));
64template<
typename T,
class PP1,
class NP2,
class PP2>
69 typedef typename LineSegment3D<T, PP1>::TValue TValue;
73 const TPoint S1 = ray.support();
74 const TVector D = ray.direction();
75 const TPoint R = lineSegment.tail();
76 const TVector E = lineSegment.vector();
79 const TVector N = cross(D,E);
80 if(N.squaredNorm() == 0)
81 return squaredDistance(ray.project(R), R);
82 const TPoint S = S1 + N.project(SR);
91 tRay = (SR.x * E.y - SR.y * E.x) / N.z;
92 tSeg = (SR.x * D.y - SR.y * D.x) / N.z;
96 tRay = (SR.y * E.z - SR.z * E.y) / N.x;
97 tSeg = (SR.y * D.z - SR.z * D.y) / N.x;
100 tRay = (SR.z * E.x - SR.x * E.z) / N.y;
101 tSeg = (SR.z * D.x - SR.x * D.z) / N.y;
106 TValue tHead = ray.t(lineSegment.head());
108 return squaredDistance(ray.point(tHead), lineSegment.head());
111 tSeg = lineSegment.t(S1);
113 return squaredDistance(S1, lineSegment.tail());
115 return squaredDistance(S1, lineSegment.head());
116 return squaredDistance(S1, lineSegment.point(tSeg));
121 TValue tTail = ray.t(R);
123 return squaredDistance(ray.point(tTail), R);
126 tSeg = lineSegment.t(S1);
128 return squaredDistance(S1, lineSegment.tail());
130 return squaredDistance(S1, lineSegment.head());
131 return squaredDistance(S1, lineSegment.point(tSeg));
136 return squaredDistance(ray.point(tRay), lineSegment.point(tSeg));
138 return lineSegment.squaredDistance(S1);
141template<
typename T,
class PP1,
class NP2,
class PP2>
144 T &tSeg, T &tRay,
const T& tMin = T())
146 typedef typename LineSegment3D<T, PP1>::TValue TValue;
150 const TPoint S1 = ray.support();
151 const TVector D = ray.direction();
152 const TPoint R = lineSegment.tail();
153 const TVector E = lineSegment.vector();
156 const TVector N = cross(D,E);
157 if(N.squaredNorm() == 0)
158 return squaredDistance(ray.project(R), R);
159 const TPoint S = S1 + N.project(SR);
166 tRay = (SR.x * E.y - SR.y * E.x) / N.z;
167 tSeg = (SR.x * D.y - SR.y * D.x) / N.z;
171 tRay = (SR.y * E.z - SR.z * E.y) / N.x;
172 tSeg = (SR.y * D.z - SR.z * D.y) / N.x;
175 tRay = (SR.z * E.x - SR.x * E.z) / N.y;
176 tSeg = (SR.z * D.x - SR.x * D.z) / N.y;
181 TValue tHead = ray.t(lineSegment.head());
186 return squaredDistance(ray.point(tHead), lineSegment.head());
190 tSeg = lineSegment.t(S1);
195 return squaredDistance(S1, lineSegment.tail());
200 return squaredDistance(S1, lineSegment.head());
202 return squaredDistance(S1, lineSegment.point(tSeg));
207 TValue tTail = ray.t(R);
211 return squaredDistance(ray.point(tTail), R);
215 tSeg = lineSegment.t(S1);
220 return squaredDistance(S1, lineSegment.tail());
225 return squaredDistance(S1, lineSegment.head());
227 return squaredDistance(S1, lineSegment.point(tSeg));
232 return squaredDistance(ray.point(tRay), lineSegment.point(tSeg));
235 return lineSegment.closestsPoint(S1, tSeg);
T abs(const T &x)
if x < 0 return -x, else return x.
set of geometrical primitives
Library for Assembled Shared Sources.