57#include "../../Math/VectorT.hh"
58#include "../../Math/Matrix4x4T.hh"
77template <
typename Scalar>
89 PlaneT( Scalar _a=0, Scalar _b=0, Scalar _c=0, Scalar _d=0 )
90 : coeffs_(_a, _b, _c, _d)
96 : coeffs_(_n[0], _n[1], _n[2], -(_n|_o))
103 Vec3 n = (_v1-_v0) % (_v2-_v0);
104 coeffs_ =
Vec4(n[0], n[1], n[2], -(n|_v0));
120 return ( _v[0]*coeffs_[0] +
132 enum IntersectionTarget { Line, LineSegment, Ray };
135 bool intersect_line(
const Vec3& _v0,
const Vec3& _v1,
136 Vec3& _v, Scalar& _t )
const
137 {
return intersect(_v0, _v1, _v, _t, Line); }
140 bool intersect_ray(
const Vec3& _v0,
const Vec3& _v1,
141 Vec3& _v, Scalar& _t )
const
142 {
return intersect(_v0, _v1, _v, _t, Ray); }
145 bool intersect_linesegment(
const Vec3& _v0,
const Vec3& _v1,
146 Vec3& _v, Scalar& _t )
const
147 {
return intersect(_v0, _v1, _v, _t, LineSegment); }
164 IntersectionTarget _target )
const
166#define SGN(d) ((d>0.0) ? 1 : -1)
169 Scalar a0(fabs(d0)), a1(fabs(d1));
172 if (a0 < FLT_MIN) { _v = _v0; _t = 0.0;
return true; }
173 if (a1 < FLT_MIN) { _v = _v1; _t = 1.0;
return true; }
176 if (SGN(d0) != SGN(d1))
179 _v = _v0*(1.0-_t) + _v1*_t;
186 if (_target == LineSegment)
return false;
188 if (fabs(d0-d1) < FLT_MIN)
return false;
189 else _t = d0/(d0-d1);
191 if (_target == Ray && _t < 0.0)
return false;
193 _v = _v0*(1.0-_t) + _v1*_t;
204 if (!M.invert())
return false;
206 affineTransformation_precomp(M);
214 coeffs_ = _M_inverseTransposed*coeffs_;
223 if (n != 0.0) coeffs_ /= n;
231typedef PlaneT<float> Planef;
232typedef PlaneT<double> Planed;
void affine_transformation_precomp(const Mat4x4 &_M_inverseTransposed)
affine transformation of the plane (M^{-T} precomputed)
Scalar distance(const Vec3 &_v) const
signed distance point-plane
PlaneT(const Vec3 &_o, const Vec3 &_n)
constructor: origin and normal
bool intersect(const Vec3 &_v0, const Vec3 &_v1, Vec3 &_v, Scalar &_t, IntersectionTarget _target) const
General intersection function.
PlaneT(Scalar _a=0, Scalar _b=0, Scalar _c=0, Scalar _d=0)
constructor: coefficients
const Vec4 & coeffs() const
coeffitients
Vec3 normal() const
normal vector
bool affine_transformation(const Mat4x4 &_M)
affine transformation of the plane
bool operator()(const Vec3 &_v) const
predicate: above plane
PlaneT(const Vec3 &_v0, const Vec3 &_v1, const Vec3 &_v2)
constructor: 3 points
VectorT< Scalar, 3 > Vec3
typedefs
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM > >().sqrnorm()))
compute euclidean norm
Namespace providing different geometric functions concerning angles.