|
|
|
|
@ -41,34 +41,30 @@ class Intersection {
|
|
|
|
|
* @brief %Intersection of a plane and line |
|
|
|
|
* @param planePosition Plane position |
|
|
|
|
* @param planeNormal Plane normal |
|
|
|
|
* @param a Starting point of the line |
|
|
|
|
* @param b Ending point of the line |
|
|
|
|
* @return %Intersection point position, NaN if the line lies on the |
|
|
|
|
* plane or infinity if the intersection doesn't exist. %Intersection |
|
|
|
|
* point can be computed from the position with `a+intersection(...)*b`. |
|
|
|
|
* If returned value is in range @f$ [ 0 ; 1 ] @f$, the intersection |
|
|
|
|
* is inside the line segment defined by `a` and `b`. |
|
|
|
|
* @param p Starting point of the line |
|
|
|
|
* @param r Direction of the line |
|
|
|
|
* @return %Intersection point position `t` on the line, NaN if the |
|
|
|
|
* line lies on the plane or infinity if the intersection doesn't |
|
|
|
|
* exist. %Intersection point can be then computed from with |
|
|
|
|
* `p + t*r`. If returned value is in range @f$ [ 0 ; 1 ] @f$, the |
|
|
|
|
* intersection is inside the line segment defined by `p` and `r`. |
|
|
|
|
* |
|
|
|
|
* First the parameter *f* of parametric equation of the plane |
|
|
|
|
* is computed from plane normal **n** and plane position: @f[ |
|
|
|
|
* \begin{pmatrix} n_0 \\ n_1 \\ n_2 \end{pmatrix} \cdot |
|
|
|
|
* \begin{pmatrix} x \\ y \\ z \end{pmatrix} - f = 0 |
|
|
|
|
* @f] |
|
|
|
|
* Using plane normal **n**, parameter *f* and points **a** and **b**, |
|
|
|
|
* value of *t* is computed and returned. @f[ |
|
|
|
|
* Using plane normal **n**, parameter *f* and line defined by **p** |
|
|
|
|
* and **r**, value of *t* is computed and returned. @f[ |
|
|
|
|
* \begin{array}{rcl} |
|
|
|
|
* \Delta \boldsymbol b & = & \boldsymbol b - \boldsymbol a \\
|
|
|
|
|
* f & = & \boldsymbol n \cdot (\boldsymbol a + \Delta \boldsymbol b \cdot t) \\
|
|
|
|
|
* \Rightarrow t & = & \cfrac{f - \boldsymbol n \cdot \boldsymbol a}{\boldsymbol n \cdot \Delta \boldsymbol b} |
|
|
|
|
* f & = & \boldsymbol n \cdot (\boldsymbol p + t \boldsymbol r) \\
|
|
|
|
|
* \Rightarrow t & = & \cfrac{f - \boldsymbol n \cdot \boldsymbol p}{\boldsymbol n \cdot \boldsymbol r} |
|
|
|
|
* \end{array} |
|
|
|
|
* @f] |
|
|
|
|
*/ |
|
|
|
|
template<class T> static T planeLine(const Vector3<T>& planePosition, const Vector3<T>& planeNormal, const Vector3<T>& a, const Vector3<T>& b) { |
|
|
|
|
/* Compute f from normal and plane position */ |
|
|
|
|
T f = Vector3<T>::dot(planePosition, planeNormal); |
|
|
|
|
|
|
|
|
|
/* Compute t */ |
|
|
|
|
return (f-Vector3<T>::dot(planeNormal, a))/Vector3<T>::dot(planeNormal, b-a); |
|
|
|
|
template<class T> static T planeLine(const Vector3<T>& planePosition, const Vector3<T>& planeNormal, const Vector3<T>& p, const Vector3<T>& r) { |
|
|
|
|
const T f = Vector3<T>::dot(planePosition, planeNormal); |
|
|
|
|
return (f-Vector3<T>::dot(planeNormal, p))/Vector3<T>::dot(planeNormal, r); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|