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

◆ compute_path_curvature()

std::vector< Nodes::LineVertex > MayaFlux::Kinesis::compute_path_curvature ( const std::vector< Nodes::LineVertex > &  path_vertices,
float  curvature_scale,
size_t  stride = 1 
)

Compute curvature vectors along a path (2nd derivative approximation)

Parameters
path_verticesSequential vertices defining curve
curvature_scaleMagnitude scaling factor
strideSample every stride-th vertex
Returns
Line segments representing discrete curvature

Curvature at i approximated by: (v[i+1] - 2*v[i] + v[i-1])

Definition at line 332 of file GeometryPrimitives.cpp.

336{
337 if (path_vertices.size() < 3 || stride == 0) {
338 return {};
339 }
340
341 std::vector<Nodes::LineVertex> curvatures;
342 curvatures.reserve((path_vertices.size() - 2) / stride * 2);
343
344 for (size_t i = 1; i < path_vertices.size() - 1; i += stride) {
345 glm::vec3 p_prev = path_vertices[i - 1].position;
346 glm::vec3 p_curr = path_vertices[i].position;
347 glm::vec3 p_next = path_vertices[i + 1].position;
348
349 glm::vec3 curvature = (p_next - 2.0F * p_curr + p_prev) * curvature_scale;
350
351 glm::vec3 color = path_vertices[i].color;
352 float thickness = path_vertices[i].thickness;
353
354 curvatures.push_back({ .position = p_curr,
355 .color = color,
356 .thickness = thickness });
357
358 curvatures.push_back({ .position = p_curr + curvature,
359 .color = color,
360 .thickness = thickness });
361 }
362
363 return curvatures;
364}
std::optional< glm::vec3 > color

References color.