/** * @brief * Construct a plane with a point and a normal. * @param p * the point * @param n * the normal * @throw std::domain_error * if the normal vector is the zero vector * @remark * The plane normal is normalized if necessary. * @remark * Let \f$X\f$ be the point and \f$\vec{n}\f$ the unnormalized plane normal, then the plane equation is given by * \f{align*}{ * \hat{n} \cdot P + d = 0, \hat{n}=\frac{\vec{n}}{|\vec{n}|}, d = -\left(\hat{n} \cdot X\right) * \f} * \f$X\f$ is on the plane as * \f{align*}{ * &\hat{n} \cdot X + d\\ * =&\hat{n} \cdot X + -(\hat{n} \cdot X)\\ * =&\hat{n} \cdot X - \hat{n} \cdot X\\ * =&0 * \f} */ Plane3(const VectorType& p, const VectorType& n) : _n(n), _d(0.0f) { if (_n.normalize() == 0.0f) { throw std::domain_error("normal vector is zero vector"); } _d = -_n.dot(p); }
/** * @brief * Construct a plane with three non-collinear points. * @param a, b, c * the point * @throw std::domain_error * if the points are collinear * @remark * Assume \f$a\f$, \f$b\f$ and \f$c\f$ are not collinear. Let \f$u = b - a\f$, * \f$v = c - a\f$, \f$n = u \times v\f$, \f$\hat{n} = \frac{n}{|n|}\f$ and * \f$d = -\left(\hat{n} \cdot a\right)\f$. * @remark * We show that \f$a\f$, \f$b\f$ and \f$c\f$ are on the plane given by the * equation \f$\hat{n} \cdot p + d = 0\f$. To show this for \f$a\f$, rewrite * the plane equation to * \f{eqnarray*}{ * \hat{n} \cdot p + -(\hat{n} \cdot a) = 0\\ * \f} * shows for \f$p=a\f$ immediatly that \f$a\f$ is on the plane. * @remark * To show that \f$b\f$ and \f$c\f$ are on the plane, the plane equation is * rewritten yet another time using the bilinearity property of the dot product * and the definitions of \f$d\f$ and \f$\hat{n}\f$ its * \f{align*}{ * &\hat{n} \cdot p + -(\hat{n} \cdot a) \;\;\text{Def. of } d\\ * =&\hat{n} \cdot p + \hat{n} \cdot (-a) \;\;\text{Bilinearity of the dot product}\\ * =&\hat{n} \cdot (p - a) \;\;\text{Bilinearity of the dot product}\\ * =&\frac{n}{|n|} \cdot (p - a) \;\;\text{Def. of } \hat{n}\\ * =&(\frac{1}{|n|}n) \cdot (p - a) \;\;\\ * =&\frac{1}{|n|}(n \cdot (p - a)) \;\;\text{Compatibility of the dot product w. scalar multiplication}\\ * =&n \cdot (p - a) \;\;\\ * =&(u \times v) \cdot (p - a) \;\;\text{Def. of } n * \f} * Let \f$p = b\f$ then * \f{align*}{ * &(u \times v) \cdot (b - a) \;\text{Def. of } u\\ * =&(u \times v) \cdot u\\ * =&0 * \f} * or let \f$p = c\f$ then * \f{align*}{ * &(u \times v) \cdot (c - a) \;\text{Def. of } u\\ * =&(u \times v) \cdot v\\ * =&0 * \f} * as \f$u \times v\f$ is orthogonal to both \f$u\f$ and \f$v\f$. * This shows that \f$b\f$ and \f$c\f$ are on the plane. */ Plane3(const VectorType& a, const VectorType& b, const VectorType& c) { auto u = b - a; if (u == VectorType::zero()) { throw std::domain_error("b = a"); } auto v = c - a; if (u == VectorType::zero()) { throw std::domain_error("c = a"); } _n = u.cross(v); if (0.0f == _n.normalize()) { /* u x v = 0 is only possible for u,v != 0 if u = v and thus b = c. */ throw std::domain_error("b = c"); } _d = -_n.dot(a); }
/** * @brief * Construct a plane from a translation axis and a distance from the origin. * @param t * the translation axis * @param d * the distance from the origin * @post * Given an axis \f$\vec{t}\f$ and a distance from the origin \f$d\f$ * the plane equation is given by * \f{align*}{ * \hat{n} \cdot p + d = 0, \hat{n}=\frac{\vec{t}}{|\vec{t}|} * \f} * @throw std::domain_error * if the translation axis is the zero vector */ Plane3(const VectorType& t, const ScalarType& d) : _n(t), _d(d) { if (_n.normalize() == 0.0f) { throw std::domain_error("axis vector is zero vector"); } }