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

◆ compute_path_normals()

MAYAFLUX_API std::vector< Kakshya::LineVertex > MayaFlux::Kinesis::compute_path_normals ( const std::vector< Kakshya::LineVertex > &  path_vertices,
float  normal_length,
size_t  stride = 1 
)

Compute normal vectors along a piecewise-linear path.

Parameters
path_verticesSequential vertices defining curve
normal_lengthMagnitude of normal vectors
strideSample every stride-th vertex (default: 1)
Returns
Line segments (pairs) representing normals (for LINE_LIST topology)

Normal at vertex i: perpendicular to tangent (v[i+1] - v[i]) Returned as pairs: [midpoint - normal/2, midpoint + normal/2]

Definition at line 306 of file GeometryPrimitives.cpp.

310{
311 if (path_vertices.size() < 2 || stride == 0) {
312 return {};
313 }
314
315 std::vector<Kakshya::LineVertex> normals;
316 normals.reserve((path_vertices.size() - 1) / stride * 2);
317
318 for (size_t i = 0; i < path_vertices.size() - 1; i += stride) {
319 glm::vec3 p0 = path_vertices[i].position;
320 glm::vec3 p1 = path_vertices[i + 1].position;
321
322 glm::vec3 tangent = p1 - p0;
323 float length = glm::length(tangent);
324
325 if (length < 1e-6F) {
326 continue;
327 }
328
329 tangent /= length;
330
331 // Normal (perpendicular in XY plane)
332 // For 2D: rotate tangent 90° counter-clockwise
333 glm::vec3 normal(-tangent.y, tangent.x, 0.0F);
334 normal = glm::normalize(normal) * normal_length;
335
336 glm::vec3 midpoint = (p0 + p1) * 0.5F;
337
338 glm::vec3 color = path_vertices[i].color;
339 float thickness = path_vertices[i].thickness;
340
341 normals.push_back({ .position = midpoint - normal * 0.5F,
342 .color = color,
343 .thickness = thickness });
344
345 normals.push_back({ .position = midpoint + normal * 0.5F,
346 .color = color,
347 .thickness = thickness });
348 }
349
350 return normals;
351}
uint64_t length
Definition Composite.cpp:11
glm::vec3 color
Definition Decoder.cpp:97
uint32_t tangent

References color, length, and tangent.

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

+ Here is the caller graph for this function: