Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Track's Segments

Gets a segement length ds, so that the visible failure in a track would become smaller than some marginal distance of e. More...

Functions

dclspc Length trax::Segment (const Track &track, Length s, Length e, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Calculates a segment length ds so that the visible failure in a track would become smaller than some marginal distance of e.
dclspc Length trax::Segment (const Track &track, Length s, Length e, Length w, Length h, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Works like the first overload, but takes the dimensions of the track model into account.
dclspc Length trax::Segment_Checked (const Track &track, Length s, Length e, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Works like Segment(), but checks the result and shrinks it if necessary.
dclspc Length trax::Segment_Checked (const Track &track, Length s, Length e, Length w, Length h, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Works like the first overload, but takes the dimensions of the track model into account.
dclspc Length trax::Segment_TotallyChecked (const Track &track, Length s, Length e, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Works like Segment(), but checks the result.
dclspc Length trax::Segment_TotallyChecked (const Track &track, Length s, Length e, Length w, Length h, common::Interval< Length > segmentLimits, bool ignoreCuvesTorsion=false)
 Works like the first overload, but takes the dimensions of the track model. into account.

Detailed Description

Gets a segement length ds, so that the visible failure in a track would become smaller than some marginal distance of e.

Parameters
trackTrack to get the segment for.
sParameter to evaluate the situation for [0,length].
eDistance failure that is assumed not to matter visibly.
wmaximum width of the track model. For asymmetric tracks take two times the widest side.
hmaximum height of the track model. For asymmetric tracks take two times the highest side.
segmentLimitsThe minimum and maximum segment length to deliver. The last segment returned might be shorter, to go to the track's end.
ignoreCuvesTorsionIf true the torsion of the curve is not taken into consideration (but the twist still is).
Returns
ds so that s+ds will not exceed the end of track. ds == 0 therefore shows that s == track.Length().

If it comes to rendering, we might want to break down a track into segments that are straight lines. This means, we graphically are working with incorrect T,N,B vectors over the length ds of this segment. This might result in visible errors that are about:

/// |dT| * ds   <= e (1)
/// |dN| * w/2  <= e (2)
/// |dB| * h/2  <= e (3)
/// 

For small errors the dX = X(s+ds) - X(s) happen to be angles - times a radius it is an error in length. With w and h being the dimensions of the track model and ds being the segment length we are looking for. For a track model, we might want to limit the model's extents, so that w/2,h/2 <= ds. That would mean, we can guarantee (1)-(3) if we guarantee the following:

/// |dT| * ds   <= e (4)
/// |dN| * ds   <= e (5)
/// |dB| * ds   <= e (6)
/// 

From Frenet https://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas it follows:

/// (4) => ds <= sqrt(e/k)
/// (5) => ds <= sqrt(e/sqrt(pow<2>(k)+pow<2>(t)))
/// (6) => ds <= sqrt(e/|t|)
///
/// k: curvature
/// t: torsion
/// 

(5) Is the most restrictive and is targeted. s+ds will not exceed the end of the track. The curve is evaluated locally at s; so the ds has to be further limited to reasonably small values (compared to the changes of curvature and torsion) to guarantee that the condition really holds.

Exceptions
std::logic_errorif no proper curve is attached with trhe track.
std::range_errorif s is outside the [0,Length()] range.

Function Documentation

◆ Segment()

dclspc Length trax::Segment ( const Track & track,
Length s,
Length e,
Length w,
Length h,
common::Interval< Length > segmentLimits,
bool ignoreCuvesTorsion = false )

Works like the first overload, but takes the dimensions of the track model into account.

In the above derivation it would follow:

/// (4) => ds <= sqrt(e/k)
/// (5) => ds <= 2*e/(w * sqrt(pow<2>(k)+pow<2>(t)))
/// (6) => ds <= 2*e/(h*|t|)
/// 

◆ Segment_Checked()

dclspc Length trax::Segment_Checked ( const Track & track,
Length s,
Length e,
common::Interval< Length > segmentLimits,
bool ignoreCuvesTorsion = false )

Works like Segment(), but checks the result and shrinks it if necessary.

This method might still deliver too large segments if the curve has huge changes inside the limits; for this reason do not choose the upper segment limit too big, since some sudden curve inside such a segment might get missed.

◆ Segment_TotallyChecked()

dclspc Length trax::Segment_TotallyChecked ( const Track & track,
Length s,
Length e,
common::Interval< Length > segmentLimits,
bool ignoreCuvesTorsion = false )

Works like Segment(), but checks the result.

This method might take a long time to compute, if segmentLimits.Near() is too small, but is guaranteed to not miss any curves with lengthes greater than segmentLimits.Near().