1#include <Core/Geometry/PolyLine.hpp>
10 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
11 m_ptsDiff.reserve( m_pts.size() - 1 );
12 m_lengths.
reserve( m_pts.size() - 1 );
14 for ( uint i = 0; i < m_pts.size() - 1; ++i ) {
15 m_ptsDiff.push_back( m_pts[i + 1] - m_pts[i] );
16 len += m_ptsDiff.back().norm();
31 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
33 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
34 sqDist =
std::min( Geometry::pointToSegmentSq( p, m_pts[i], m_ptsDiff[i] ), sqDist );
44 CORE_ASSERT( segment < m_ptsDiff.size(),
"invalid segment index" );
45 const Scalar tSegment = Geometry::projectOnSegment( p, m_pts[segment], m_ptsDiff[segment] );
50 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
58 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
59 Scalar proj = Geometry::projectOnSegment( p, m_pts[i], m_ptsDiff[i] );
60 Scalar d = ( p - ( m_pts[i] + proj * ( m_ptsDiff[i] ) ) ).squaredNorm();
69 CORE_ASSERT( segment < m_ptsDiff.size(),
"Invalid index" );
70 Scalar t = ts[segment];
71 if ( t > 0 && t < 1 ) {
72 bool prev = segment > 0 && ts[segment - 1] > 0 && ts[segment - 1] < 1;
73 bool next = segment < m_ptsDiff.size() - 1 && ts[segment + 1] > 0 && ts[segment + 1] < 1;
75 if ( prev && next ) { prev = ds[segment - 1] < ds[segment + 1]; }
76 uint i = prev ? segment - 1 : segment;
77 Vector3 ba = -m_ptsDiff[i];
78 Vector3 bc = m_ptsDiff[i + 1];
79 Vector3 bp = p - m_pts[i + 1];
85 return ( c1 * t1 + c2 * t2 ) / ( c1 + c2 );
98 while ( m_lengths[i] < param ) {
103 CORE_ASSERT( i < m_ptsDiff.size(),
"Invalid index" );
106 return m_pts[i] + ( ( param - lprev ) / ( m_lengths[i] - lprev ) ) * m_ptsDiff[i];
110 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
113 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
114 Scalar proj = Geometry::projectOnSegment( p, m_pts[i], m_ptsDiff[i] );
115 Scalar d = ( p - ( m_pts[i] + proj * ( m_ptsDiff[i] ) ) ).squaredNorm();
122 CORE_ASSERT( segment < m_ptsDiff.size(),
"Invalid index" );
uint getNearestSegment(const Vector3 &p) const
Returns the index of the nearest segment.
PolyLine(const Vector3Array &pt)
Create a polyline from a given set of points.
Vector3 f(Scalar t) const
void update()
Update the precomputed values after new points have been set.
Scalar distance(const Vector3 &p) const
Return the distance between the line and a given point p.
Scalar getLineParameter(uint segment, Scalar tSegment) const
void setPoints(const Vector3Array &pt)
Update the points of the polyline.
Scalar squaredDistance(const Vector3 &p) const
Return the squared distance between the line and a given point p.
Scalar projectOnSegment(const Vector3 &p, uint segment) const
Scalar project(const Vector3 &p) const
Scalar length() const
Get the total length of the line .
Scalar cotan(const Vector_ &v1, const Vector_ &v2)
constexpr T saturate(T v)
Clamps the value between 0 and 1.
@ Geometry
"Geometry" render objects are those loaded using Radium::IO and generated by GeometrySystem
hepler function to manage enum as underlying types in VariableSet