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

◆ compute_path_tangents()

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

Compute tangent vectors along a piecewise-linear path.

Parameters
path_verticesSequential vertices defining curve
tangent_lengthMagnitude of tangent vectors
strideSample every stride-th vertex
Returns
Line segments (pairs) representing tangents (for LINE_LIST topology)

Tangent at vertex i: direction (v[i+1] - v[i]) Returned as pairs: [vertex - tangent/2, vertex + tangent/2]

Definition at line 292 of file GeometryPrimitives.cpp.

296{
297 if (path_vertices.size() < 2 || stride == 0) {
298 return {};
299 }
300
301 std::vector<Nodes::LineVertex> tangents;
302 tangents.reserve((path_vertices.size() - 1) / stride * 2);
303
304 for (size_t i = 0; i < path_vertices.size() - 1; i += stride) {
305 glm::vec3 p0 = path_vertices[i].position;
306 glm::vec3 p1 = path_vertices[i + 1].position;
307
308 glm::vec3 tangent = p1 - p0;
309 float length = glm::length(tangent);
310
311 if (length < 1e-6F) {
312 continue;
313 }
314
315 tangent = glm::normalize(tangent) * tangent_length;
316
317 glm::vec3 color = path_vertices[i].color;
318 float thickness = path_vertices[i].thickness;
319
320 tangents.push_back({ .position = p0 - tangent * 0.5F,
321 .color = color,
322 .thickness = thickness });
323
324 tangents.push_back({ .position = p0 + tangent * 0.5F,
325 .color = color,
326 .thickness = thickness });
327 }
328
329 return tangents;
330}
std::optional< glm::vec3 > color

References color.