MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ turning_profile()

TurningProfile MayaFlux::Kinesis::turning_profile ( std::span< const glm::vec2 >  path,
size_t  samples,
bool  rotation_invariant = true 
)
inline

Build a turning profile from a path.

Parameters
pathPositions in chronological order, at least three
samplesProfile length, minimum 3
rotation_invariantSubtract the initial heading from every sample, making the profile independent of which direction the path was started in
Returns
A profile of exactly samples entries

Resamples to uniform arc length first, so the profile is indexed by distance along the path rather than by time, and two recordings of the same shape at different frame rates produce comparable profiles.

Definition at line 199 of file PathShape.hpp.

201{
202 samples = samples < 3 ? 3 : samples;
203
204 TurningProfile profile;
205 profile.turning.assign(samples - 1, 0.0F);
206
207 if (path.size() < 2)
208 return profile;
209
210 for (size_t i = 1; i < path.size(); ++i)
211 profile.length += glm::length(path[i] - path[i - 1]);
212
213 const std::vector<glm::vec2> even = resample_uniform(path, samples);
214
215 float unwrapped = heading(even[1] - even[0]);
216 profile.initial_heading = unwrapped;
217 profile.turning[0] = unwrapped;
218
219 float prev = unwrapped;
220 for (size_t i = 2; i < even.size(); ++i) {
221 const float h = heading(even[i] - even[i - 1]);
222 unwrapped += angular_delta(h, prev);
223 prev = h;
224 profile.turning[i - 1] = unwrapped;
225 }
226
227 if (rotation_invariant) {
228 for (auto& t : profile.turning)
229 t -= profile.initial_heading;
230 }
231
232 return profile;
233}
uint32_t h
Definition InkPress.cpp:29
float angular_delta(float to, float from) noexcept
Shortest signed angular difference between two headings.
std::vector< glm::vec2 > resample_uniform(std::span< const glm::vec2 > path, size_t count)
Resample a path to a fixed point count at uniform arc length.
Definition PathShape.hpp:45
float heading(const glm::vec2 &v) noexcept
Heading angle of a 2D vector.
float initial_heading
Heading of the first segment, before any invariance subtraction.
float length
Total arc length of the source path.
std::vector< float > turning
Unwrapped heading at each arc-length sample.
A path's heading as a function of arc length, at a fixed sample count.

References angular_delta(), h, heading(), MayaFlux::Kinesis::TurningProfile::initial_heading, MayaFlux::Kinesis::TurningProfile::length, resample_uniform(), and MayaFlux::Kinesis::TurningProfile::turning.

+ Here is the call graph for this function: