MayaFlux 0.4.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 245 of file GeometryPrimitives.cpp.

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

References color.