17 #ifndef AGXCOLLIDE_LINESEGMENTINTERSECTIONFINDER_H
18 #define AGXCOLLIDE_LINESEGMENTINTERSECTIONFINDER_H
31 namespace agxGeometryQueries {
98 bool isDegeneratedToPoint()
const;
178 bool isDegeneratedToPoint()
const;
181 bool isDegeneratedToLine()
const;
184 agx::Vec3 computeSweepDirectionPoint0()
const;
187 agx::Vec3 computeSweepDirectionPoint1()
const;
220 agx::Interval& lineParameters0,
221 agx::Interval& lineParameters1,
234 namespace agxGeometryQueries {
250 if (isDegeneratedToPoint())
253 return (m_dir * (point - m_point)) / m_dirLength2;
259 const agx::Vec3 projection = m_point + m_dir * projectPoint(point);
272 return agx::Interval(projectPoint(segment.
point0()), projectPoint(segment.
point1()),
false);
284 return m_point + m_dir * lineParameter;
302 m_dir(point1 - point0), m_dirLength2(m_dir * m_dir)
314 if (isDegeneratedToPoint())
317 return (m_dir * (point - m_point0)) / m_dirLength2;
323 const agx::Real projection = projectPointToInfiniteLine(point);
324 if (projection < 0 || projection * projection > m_dirLength2)
326 const agx::Vec3 projectionPoint = m_point0 + m_dir * projection;
327 const agx::Vec3 dist = point - projectionPoint;
328 return dist.
length2() < epsilon * epsilon;
370 return m_point0 + m_dir * lineParameter;
380 :m_segment0(start), m_segment1(
end)
387 const agx::Vec3 point = m_segment0.evaluateAt(lineParameter) * (
agx::Real(1.0) - time) + m_segment1.evaluateAt(lineParameter) * time;
394 const LineSegment segment(m_segment0.point0() * (
agx::Real(1.0) - time) + m_segment1.point0() * time,
395 m_segment0.point1() * (
agx::Real(1.0) - time) + m_segment1.point1() * time);
#define AGXPHYSICS_EXPORT
static bool calculateLineSegmentCollision(const agxGeometryQueries::SweptLineSegment &sweptSegment0, const agxGeometryQueries::SweptLineSegment &sweptSegment1, agx::Real &t, agx::Interval &lineParameters0, agx::Interval &lineParameters1, agx::StackArray< agx::Vec3, 2 > &points, agx::Vec3 &normal, agx::Real &distance)
A line segment. Note that the direction does not have to be normalized.
agx::Vec3 evaluateAt(const agx::Real lineParameter) const
Evaluates the line equation at the parameter.
agxGeometryQueries::Line getLine() const
Gets the line segment's line.
const agx::Vec3 & point1() const
Gets the line segment's second point.
bool isDegeneratedToPoint() const
Is the line segment degenerated to a point?
bool containsPoint(const agx::Vec3 &point, const agx::Real epsilon=agx::RealEpsilon) const
Does the line segment contain the point, given an epsilon threshold?
LineSegment()
Creates an empty line segment, with both end points at origin.
const agx::Vec3 & point0() const
Gets the line segment's first point.
const agx::Vec3 & dir() const
Gets the direction; not necessarily normalized.
agx::Real dirLength2() const
Gets the squared length of the line direction.
agx::Real projectPointToInfiniteLine(const agx::Vec3 &point) const
Computes the scalar value of the projection of a point along the segment's line.
An infinite line, defined by a starting point and a (not necessarily normalized) direction.
const agx::Vec3 & point() const
Gets the starting point of the line.
bool isDegeneratedToPoint() const
Is the line degenerated to a point?
agx::Interval projectLineSegment(const LineSegment &segment) const
Computes the interval of the projection of a line segment onto this line.
bool containsPoint(const agx::Vec3 &point, const agx::Real epsilon=agx::RealEpsilon) const
Does the line contain the point, given an epsilon threshold?
const agx::Vec3 & dir() const
Gets the direction; not necessarily normalized.
agx::Real projectPoint(const agx::Vec3 &point) const
Computes the scalar value of the projection of a point along the line.
agx::Vec3 evaluateAt(const agx::Real lineParameter) const
Note that the line dir does not have to be normalized.
Line(const agx::Vec3 &point, const agx::Vec3 &dir)
Note that the direction does not have to be normalized.
agx::Real dirLength2() const
Gets the squared length of the line direction.
A line segment that is swept in time from t=0 to t=1.
bool isDegeneratedToLine() const
Is the swept line segment degenerated to a line?
LineSegment computeSweepSegmentPoint0() const
Returns the line segment point0 over time.
bool isDegeneratedToPoint() const
Is the swept line segment degenerated to a point?
LineSegment computeSweepSegmentPoint1() const
Returns the line segment point1 over time.
SweptLineSegment()
Creates a SweptLineSegment, with both line segments degenaring to points at the origin.
agx::Vec3 evaluateAt(const agx::Real time, const agx::Real lineParameter) const
Evaluates the swept line at a given time and line parameter and returns a point.
agx::Vec3 computeSweepDirectionPoint1() const
Returns the non-normalized sweep direction of point1 over time.
LineSegment & segment0()
Gets the swept line segment's first line segment, i.e. at t=0.
agx::Vec3 computeSweepDirectionPoint0() const
Returns the non-normalized sweep direction of point0 over time.
LineSegment & segment1()
Gets the swept line segment's second line segment, i.e. at t=1.
Templated stack array class.
Real length2() const
Length squared of the vector = vec .
const agx::Real geometricEpsilon
class AGXPHYSICS_EXPORT LineSegment
bool AGXPHYSICS_EXPORT pointsAreIdentical(const agx::Vec3 &point0, const agx::Vec3 &point1)
Tests if two points are identical given agxGeometryQueries::geometricEpsilon.
This namespace consists of a set of classes for handling geometric intersection tests including boole...
AGXCORE_EXPORT const Real RealEpsilon
AGXPHYSICS_EXPORT agx::Bool equalsZero(const agx::AddedMassInteraction::Matrix6x6 &matrix, agx::Real eps=agx::RealEpsilon)
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)