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

◆ compute_path_curvature()

MAYAFLUX_API std::vector< Kakshya::LineVertex > MayaFlux::Kinesis::compute_path_curvature ( const std::vector< Kakshya::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 333 of file GeometryPrimitives.cpp.

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

Referenced by MayaFlux::Nodes::GpuSync::LineSegmentsNode::add_curvature().

+ Here is the caller graph for this function: