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

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

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

+ Here is the caller graph for this function: