67 #include "../../Math/VectorT.hh"
68 #include "../../Math/Matrix4x4T.hh"
87 template <
typename Scalar>
99 PlaneT( Scalar _a=0, Scalar _b=0, Scalar _c=0, Scalar _d=0 )
100 : coeffs_(_a, _b, _c, _d)
106 : coeffs_(_n[0], _n[1], _n[2], -(_n|_o))
111 PlaneT(
const Vec3& _v0,
const Vec3& _v1,
const Vec3& _v2 )
113 Vec3 n = (_v1-_v0) % (_v2-_v0);
114 coeffs_ = Vec4(n[0], n[1], n[2], -(n|_v0));
120 Vec3
normal()
const {
return Vec3(coeffs_[0], coeffs_[1], coeffs_[2]); }
124 const Vec4&
coeffs()
const {
return coeffs_; }
130 return ( _v[0]*coeffs_[0] +
142 enum IntersectionTarget { Line, LineSegment, Ray };
145 bool intersect_line(
const Vec3& _v0,
const Vec3& _v1,
146 Vec3& _v, Scalar& _t )
const
147 {
return intersect(_v0, _v1, _v, _t, Line); }
150 bool intersect_ray(
const Vec3& _v0,
const Vec3& _v1,
151 Vec3& _v, Scalar& _t )
const
152 {
return intersect(_v0, _v1, _v, _t, Ray); }
155 bool intersect_linesegment(
const Vec3& _v0,
const Vec3& _v1,
156 Vec3& _v, Scalar& _t )
const
157 {
return intersect(_v0, _v1, _v, _t, LineSegment); }
174 IntersectionTarget _target )
const
176 #define SGN(d) ((d>0.0) ? 1 : -1)
179 Scalar a0(fabs(d0)), a1(fabs(d1));
182 if (a0 < FLT_MIN) { _v = _v0; _t = 0.0;
return true; }
183 if (a1 < FLT_MIN) { _v = _v1; _t = 1.0;
return true; }
186 if (SGN(d0) != SGN(d1))
189 _v = _v0*(1.0-_t) + _v1*_t;
196 if (_target == LineSegment)
return false;
198 if (fabs(d0-d1) < FLT_MIN)
return false;
199 else _t = d0/(d0-d1);
201 if (_target == Ray && _t < 0.0)
return false;
203 _v = _v0*(1.0-_t) + _v1*_t;
214 if (!M.
invert())
return false;
216 affineTransformation_precomp(M);
224 coeffs_ = _M_inverseTransposed*coeffs_;
232 Scalar n =
normal().norm();
233 if (n != 0.0) coeffs_ /= n;
241 typedef PlaneT<float> Planef;
242 typedef PlaneT<double> Planed;
249 #endif // ACG_PLANE_HH defined
bool operator()(const Vec3 &_v) const
predicate: above plane
Vec3 normal() const
normal vector
Namespace providing different geometric functions concerning angles.
PlaneT(Scalar _a=0, Scalar _b=0, Scalar _c=0, Scalar _d=0)
constructor: coefficients
PlaneT(const Vec3 &_v0, const Vec3 &_v1, const Vec3 &_v2)
constructor: 3 points
VectorT< Scalar, 3 > Vec3
typedefs
void affine_transformation_precomp(const Mat4x4 &_M_inverseTransposed)
affine transformation of the plane (M^{-T} precomputed)
bool affine_transformation(const Mat4x4 &_M)
affine transformation of the plane
bool intersect(const Vec3 &_v0, const Vec3 &_v1, Vec3 &_v, Scalar &_t, IntersectionTarget _target) const
General intersection function.
Scalar distance(const Vec3 &_v) const
signed distance point-plane
const Vec4 & coeffs() const
coeffitients
PlaneT(const Vec3 &_o, const Vec3 &_n)
constructor: origin and normal
bool invert()
matrix inversion (returns true on success)