diff --git a/src/Magnum/Math/Geometry/Intersection.h b/src/Magnum/Math/Geometry/Intersection.h index f41589fc5..91ca5eeca 100644 --- a/src/Magnum/Math/Geometry/Intersection.h +++ b/src/Magnum/Math/Geometry/Intersection.h @@ -44,14 +44,17 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Intersection @param q Starting point of second line segment @param s Direction of second line segment -Returns intersection point positions @f$ t @f$, @f$ u @f$ on both lines, NaN if -the lines are collinear or infinity if they are parallel. Intersection point -can be then calculated with @f$ \boldsymbol{p} + t \boldsymbol{r} @f$ or -@f$ \boldsymbol{q} + u \boldsymbol{s} @f$. If @f$ t @f$ is in range -@f$ [ 0 ; 1 ] @f$, the intersection is inside the line segment defined by -@f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{p} + \boldsymbol{r} @f$, if @f$ u @f$ -is in range @f$ [ 0 ; 1 ] @f$, the intersection is inside the line segment -defined by @f$ \boldsymbol{q} @f$ and @f$ \boldsymbol{q} + \boldsymbol{s} @f$. +Returns intersection point positions @f$ t @f$, @f$ u @f$ on both lines: + +- @f$ t, u = \mathrm{NaN} @f$ if the lines are collinear +- @f$ t \in [ 0 ; 1 ] @f$ if the intersection is inside the line segment + defined by @f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{p} + \boldsymbol{r} @f$ +- @f$ t \notin [ 0 ; 1 ] @f$ if the intersection is outside the line segment +- @f$ u \in [ 0 ; 1 ] @f$ if the intersection is inside the line segment + defined by @f$ \boldsymbol{q} @f$ and @f$ \boldsymbol{q} + \boldsymbol{s} @f$ +- @f$ u \notin [ 0 ; 1 ] @f$ if the intersection is outside the line segment +- @f$ t, u \in \{-\infty, \infty\} @f$ if the intersection doesn't exist (the + 2D lines are parallel) The two lines intersect if @f$ t @f$ and @f$ u @f$ exist such that: @f[ \boldsymbol p + t \boldsymbol r = \boldsymbol q + u \boldsymbol s @@ -70,7 +73,9 @@ for @f$ t @f$ and similarly for @f$ u @f$: @f[ See also @ref lineSegmentLine() which calculates only @f$ t @f$, useful if you don't need to test that the intersection lies inside line segment defined by @f$ \boldsymbol{q} @f$ and @f$ \boldsymbol{q} + \boldsymbol{s} @f$. - */ + +@see @ref isInf(), @ref isNan() +*/ template inline std::pair lineSegmentLineSegment(const Vector2& p, const Vector2& r, const Vector2& q, const Vector2& s) { const Vector2 qp = q - p; const T rs = cross(r, s); @@ -84,13 +89,18 @@ template inline std::pair lineSegmentLineSegment(const Vector2 @param q Starting point of second line @param s Direction of second line -Returns intersection point position @f$ t @f$ on first line, NaN if the lines -are collinear or infinity if they are parallel. Intersection point can be then -calculated with @f$ \boldsymbol{p} + t \boldsymbol{r} @f$. If returned value is -in range @f$ [ 0 ; 1 ] @f$, the intersection is inside the line segment defined -by @f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{p} + \boldsymbol{r} @f$. +Returns intersection point position @f$ t @f$ on the first line: + +- @f$ t = \mathrm{NaN} @f$ if the lines are collinear +- @f$ t \in [ 0 ; 1 ] @f$ if the intersection is inside the line segment + defined by @f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{p} + \boldsymbol{r} @f$ +- @f$ t \notin [ 0 ; 1 ] @f$ if the intersection is outside the line segment +- @f$ t \in \{-\infty, \infty\} @f$ if the intersection doesn't exist (the 2D + lines are parallel) Unlike @ref lineSegmentLineSegment() calculates only @f$ t @f$. + +@see @ref isInf(), @ref isNan() */ template inline T lineSegmentLine(const Vector2& p, const Vector2& r, const Vector2& q, const Vector2& s) { return cross(q - p, s)/cross(r, s); @@ -103,11 +113,13 @@ template inline T lineSegmentLine(const Vector2& p, const Vector2 @param p Starting point of the line @param r Direction of the line -Returns intersection point position @f$ t @f$ on the line, NaN if the line lies -on the plane or infinity if the intersection doesn't exist. Intersection point -can be then calculated from with @f$ \boldsymbol{p} + t \boldsymbol{r} @f$. If -returned value is in range @f$ [ 0 ; 1 ] @f$, the intersection is inside the -line segment defined by @f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{r} @f$. +Returns intersection point position @f$ t @f$ on the line: + +- @f$ t = \mathrm{NaN} @f$ if the line lies on the plane +- @f$ t \in [ 0 ; 1 ] @f$ if the intersection is inside the line segment + defined by @f$ \boldsymbol{p} @f$ and @f$ \boldsymbol{p} + \boldsymbol{r} @f$ +- @f$ t \notin [ 0 ; 1 ] @f$ if the intersection is outside the line segment +- @f$ t \in \{-\infty, \infty\} @f$ if the intersection doesn't exist First the parameter @f$ f @f$ of parametric equation of the plane is calculated from plane normal @f$ \boldsymbol{n} @f$ and plane position: @f[ @@ -122,7 +134,9 @@ calculated and returned. @f[ \Rightarrow t & = & \cfrac{f - \boldsymbol n \cdot \boldsymbol p}{\boldsymbol n \cdot \boldsymbol r} \end{array} @f] - */ + +@see @ref isInf(), @ref isNan() +*/ template inline T planeLine(const Vector3& planePosition, const Vector3& planeNormal, const Vector3& p, const Vector3& r) { const T f = dot(planePosition, planeNormal); return (f - dot(planeNormal, p))/dot(planeNormal, r);