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

◆ compute_path_normals()

std::vector< Nodes::LineVertex > MayaFlux::Kinesis::compute_path_normals ( const std::vector< Nodes::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 235 of file GeometryPrimitives.cpp.

239{
240 if (path_vertices.size() < 2 || stride == 0) {
241 return {};
242 }
243
244 std::vector<Nodes::LineVertex> normals;
245 normals.reserve((path_vertices.size() - 1) / stride * 2);
246
247 for (size_t i = 0; i < path_vertices.size() - 1; i += stride) {
248 glm::vec3 p0 = path_vertices[i].position;
249 glm::vec3 p1 = path_vertices[i + 1].position;
250
251 glm::vec3 tangent = p1 - p0;
252 float length = glm::length(tangent);
253
254 if (length < 1e-6F) {
255 continue;
256 }
257
258 tangent /= length;
259
260 // Normal (perpendicular in XY plane)
261 // For 2D: rotate tangent 90° counter-clockwise
262 glm::vec3 normal(-tangent.y, tangent.x, 0.0F);
263 normal = glm::normalize(normal) * normal_length;
264
265 glm::vec3 midpoint = (p0 + p1) * 0.5F;
266
267 glm::vec3 color = path_vertices[i].color;
268 float thickness = path_vertices[i].thickness;
269
270 normals.push_back({ .position = midpoint - normal * 0.5F,
271 .color = color,
272 .thickness = thickness });
273
274 normals.push_back({ .position = midpoint + normal * 0.5F,
275 .color = color,
276 .thickness = thickness });
277 }
278
279 return normals;
280}