34 #ifndef OPENVDB_MATH_PLANE_HAS_BEEN_INCLUDED
35 #define OPENVDB_MATH_PLANE_HAS_BEEN_INCLUDED
65 template<
typename Real>
93 : mNorm(N), mPoint(P0), mDist(N.dot(P0))
99 : mNorm(N), mPoint(P0)
101 mNorm *=
Inv(mNorm.length());
102 mDist = mNorm.dot(P0);
111 mNorm *=
Inv(mNorm.length());
114 mDist = mNorm.
dot(mPoint);
124 mNorm.cross(P1-P0,P2-P0);
125 mNorm *=
Inv(mNorm.length());
126 assert(
Abs(1.-mNorm.length())<0.001);
137 mNorm.cross(P1-P0,P2-P0);
138 mNorm *=
Inv(mNorm.length());
139 assert(
Abs(1.-mNorm.length())<0.001);
140 mPoint = n==0 ? P0: n==1 ? P1 : P2;
147 mNorm[0] = -mNorm[0];
148 mNorm[1] = -mNorm[1];
149 mNorm[2] = -mNorm[2];
179 mDist = N.
dot(mPoint);
184 inline void setPoint(
const Point &P0)
187 mDist = mNorm.
dot(P0);
202 mNorm *=
Inv(mNorm.length());
214 return mNorm.eq(other.mNorm) && mPoint.eq(other.mPoint);
223 return !(*
this == other );
228 inline bool isValid()
const {
return (mNorm[0] || mNorm[1] || mNorm[2]);}
232 inline bool isInside(
const Point &P)
const
234 return mNorm.dot(P) < mDist;
240 return mNorm.dot(P1)<mDist && mNorm.dot(P2)<mDist;
246 return mNorm.dot(P1)<mDist && mNorm.dot(P2)<mDist && mNorm.dot(P3)<mDist;
250 inline bool isOutside(
const Point &P)
const
252 return mNorm.dot(P) > mDist;
256 inline bool isOutside(
const Point &P1,
const Point &P2)
const
258 return mNorm.dot(P1)>mDist && mNorm.dot(P2)>mDist;
264 return mNorm.dot(P1)>mDist && mNorm.dot(P2)>mDist && mNorm.dot(P3)>mDist;
270 return std::abs(mNorm.dot(pt) - mDist) <
tolerance;
274 inline bool intersects(
const Point &P1,
const Point &P2)
const
276 return (mNorm.dot(P1)-mDist)*(mNorm.dot(P2)-mDist)<0;
282 return this->intersects(ray.
start(),ray.
end());
291 t = (mDist-mNorm.dot(ray.
getOrigin()))/cosAngle;
297 inline Real angle(
const Plane &other)
const {
return acos(mNorm.dot(other.mNorm));}
304 const Real NdotN = mNorm.dot(other.mNorm);
305 if (NdotN > 0.9995) {
306 return Plane(t0*mPoint + t1*other.mPoint,
310 const Real c0 = sin(t0*angle)*inv, c1 = sin(t1*angle)*inv;
311 return Plane(t0*mPoint + t1*other.mPoint,
312 c0*mNorm + c1*other.mNorm);
321 return Plane(t0*mPoint + t1*other.mPoint,
329 return Plane(t0*mPoint + t1*other.mPoint,mNorm);
335 template<
typename Real>
336 inline std::ostream& operator<<(std::ostream& os, const Plane<Real>& p) {
337 os <<
"Plane: N=" << p.getNorm() <<
" P=" << p.getPoint() <<
" D=" << p.getDist();
345 #endif // OPENVDB_MATH_PLANE_HAS_BEEN_INCLUDED