1#include <Core/Geometry/DistanceQueries.hpp>
2#include <Core/Geometry/PolyLine.hpp>
3#include <Core/Math/LinearAlgebra.hpp>
16 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
17 m_ptsDiff.reserve( m_pts.size() - 1 );
18 m_lengths.
reserve( m_pts.size() - 1 );
20 for ( uint i = 0; i < m_pts.size() - 1; ++i ) {
21 m_ptsDiff.push_back( m_pts[i + 1] - m_pts[i] );
22 len += m_ptsDiff.back().norm();
37 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
39 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
40 sqDist =
std::min( Geometry::pointToSegmentSq( p, m_pts[i], m_ptsDiff[i] ), sqDist );
50 CORE_ASSERT( segment < m_ptsDiff.size(),
"invalid segment index" );
51 const Scalar tSegment = Geometry::projectOnSegment( p, m_pts[segment], m_ptsDiff[segment] );
56 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
64 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
65 Scalar proj = Geometry::projectOnSegment( p, m_pts[i], m_ptsDiff[i] );
66 Scalar d = ( p - ( m_pts[i] + proj * ( m_ptsDiff[i] ) ) ).squaredNorm();
75 CORE_ASSERT( segment < m_ptsDiff.size(),
"Invalid index" );
76 Scalar t = ts[segment];
77 if ( t > 0 && t < 1 ) {
78 bool prev = segment > 0 && ts[segment - 1] > 0 && ts[segment - 1] < 1;
79 bool next = segment < m_ptsDiff.size() - 1 && ts[segment + 1] > 0 && ts[segment + 1] < 1;
81 if ( prev && next ) { prev = ds[segment - 1] < ds[segment + 1]; }
82 uint i = prev ? segment - 1 : segment;
83 Vector3 ba = -m_ptsDiff[i];
84 Vector3 bc = m_ptsDiff[i + 1];
85 Vector3 bp = p - m_pts[i + 1];
91 return ( c1 * t1 + c2 * t2 ) / ( c1 + c2 );
104 while ( m_lengths[i] < param ) {
105 lprev = m_lengths[i];
109 CORE_ASSERT( i < m_ptsDiff.size(),
"Invalid index" );
112 return m_pts[i] + ( ( param - lprev ) / ( m_lengths[i] - lprev ) ) * m_ptsDiff[i];
116 CORE_ASSERT( m_pts.size() > 1,
"Line must have at least two points" );
119 for ( uint i = 0; i < m_ptsDiff.size(); ++i ) {
120 Scalar proj = Geometry::projectOnSegment( p, m_pts[i], m_ptsDiff[i] );
121 Scalar d = ( p - ( m_pts[i] + proj * ( m_ptsDiff[i] ) ) ).squaredNorm();
128 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