38 #ifndef FCL_NARROWPHASE_DETAIL_PROJECT_INL_H 39 #define FCL_NARROWPHASE_DETAIL_PROJECT_INL_H 41 #include "fcl/math/detail/project.h" 51 class Project<double>;
59 const Vector3<S> d = b - a;
60 const S l = d.squaredNorm();
64 const S t = (p - a).dot(d);
81 static const size_t nexti[3] = {1, 2, 0};
82 const Vector3<S>* vt[] = {&a, &b, &c};
83 const Vector3<S> dl[] = {a - b, b - c, c - a};
84 const Vector3<S>& n = dl[0].cross(dl[1]);
85 const S l = n.squaredNorm();
90 for(
size_t i = 0; i < 3; ++i)
92 if((*vt[i] - p).dot(dl[i].cross(n)) > 0)
100 res.
encode =
static_cast<size_t>(((res_line.
encode&1)?1<<i:0) + ((res_line.
encode&2)?1<<j:0));
110 S d = (a - p).dot(n);
112 Vector3<S> p_to_project = n * (d / l);
113 mindist = p_to_project.squaredNorm();
128 template <
typename S>
133 static const size_t nexti[] = {1, 2, 0};
134 const Vector3<S>* vt[] = {&a, &b, &c, &d};
135 const Vector3<S> dl[3] = {a-d, b-d, c-d};
136 S vl = triple(dl[0], dl[1], dl[2]);
137 bool ng = (vl * (a-p).dot((b-c).cross(a-b))) <= 0;
138 if(ng && std::abs(vl) > 0)
142 for(
size_t i = 0; i < 3; ++i)
145 S s = vl * (d-p).dot(dl[i].cross(dl[j]));
148 ProjectResult res_triangle = projectTriangle(*vt[i], *vt[j], d, p);
152 res.
encode =
static_cast<size_t>( (res_triangle.
encode&1?1<<i:0) + (res_triangle.
encode&2?1<<j:0) + (res_triangle.
encode&4?8:0) );
175 res = projectTriangle(a, b, c, p);
182 template <
typename S>
187 const Vector3<S> d = b - a;
188 const S l = d.squaredNorm();
192 const S t = - a.dot(d);
204 template <
typename S>
209 static const size_t nexti[3] = {1, 2, 0};
210 const Vector3<S>* vt[] = {&a, &b, &c};
211 const Vector3<S> dl[] = {a - b, b - c, c - a};
212 const Vector3<S>& n = dl[0].cross(dl[1]);
213 const S l = n.squaredNorm();
218 for(
size_t i = 0; i < 3; ++i)
220 if(vt[i]->dot(dl[i].cross(n)) > 0)
228 res.
encode =
static_cast<size_t>(((res_line.
encode&1)?1<<i:0) + ((res_line.
encode&2)?1<<j:0));
240 Vector3<S> o_to_project = n * (d / l);
241 mindist = o_to_project.squaredNorm();
256 template <
typename S>
261 static const size_t nexti[] = {1, 2, 0};
262 const Vector3<S>* vt[] = {&a, &b, &c, &d};
263 const Vector3<S> dl[3] = {a-d, b-d, c-d};
264 S vl = triple(dl[0], dl[1], dl[2]);
265 bool ng = (vl * a.dot((b-c).cross(a-b))) <= 0;
266 if(ng && std::abs(vl) > 0)
270 for(
size_t i = 0; i < 3; ++i)
273 S s = vl * d.dot(dl[i].cross(dl[j]));
276 ProjectResult res_triangle = projectTriangleOrigin(*vt[i], *vt[j], d);
280 res.
encode =
static_cast<size_t>( (res_triangle.
encode&1?1<<i:0) + (res_triangle.
encode&2?1<<j:0) + (res_triangle.
encode&4?8:0) );
303 res = projectTriangleOrigin(a, b, c);
310 template <
typename S>
312 : parameterization{0.0, 0.0, 0.0, 0.0}, sqr_distance(-1), encode(0)
static ProjectResult projectTetrahedraOrigin(const Vector3< S > &a, const Vector3< S > &b, const Vector3< S > &c, const Vector3< S > &d)
Project origin (0) onto tetrahedran a-b-c-d.
Definition: project-inl.h:257
unsigned int encode
the code of the projection type
Definition: project.h:64
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
S parameterization[4]
Parameterization of the projected point (based on the simplex to be projected, use 2 or 3 or 4 of the...
Definition: project.h:58
static ProjectResult projectTetrahedra(const Vector3< S > &a, const Vector3< S > &b, const Vector3< S > &c, const Vector3< S > &d, const Vector3< S > &p)
Project point p onto tetrahedra a-b-c-d.
Definition: project-inl.h:129
static ProjectResult projectTriangle(const Vector3< S > &a, const Vector3< S > &b, const Vector3< S > &c, const Vector3< S > &p)
Project point p onto triangle a-b-c.
Definition: project-inl.h:77
Project functions.
Definition: project.h:52
static ProjectResult projectTriangleOrigin(const Vector3< S > &a, const Vector3< S > &b, const Vector3< S > &c)
Project origin (0) onto triangle a-b-c.
Definition: project-inl.h:205
static ProjectResult projectLine(const Vector3< S > &a, const Vector3< S > &b, const Vector3< S > &p)
Project point p onto line a-b.
Definition: project-inl.h:55
static ProjectResult projectLineOrigin(const Vector3< S > &a, const Vector3< S > &b)
Project origin (0) onto line a-b.
Definition: project-inl.h:183
S sqr_distance
square distance from the query point to the projected simplex
Definition: project.h:61