Modules | C++

Geometry

Normal computation and geometric analysis.

The Geometry module provides tools for computing geometric properties of meshes.

Include the module with:

#include <trueform/geometry.hpp>

Normal Computation

Polygon Normals

Compute face normals for polygon meshes:

compute_normals.cpp
// Compute polygon normals for all polygons
auto polygon_normals = tf::compute_normals(polygons);

// Result is a unit_vectors_buffer with one normal per face
for (auto normal : polygon_normals.unit_vectors()) {
    // Each normal is a tf::unit_vector<T, 3>
    auto [nx, ny, nz] = normal;
}

// Access underlying flat memory for export
float* normal_data = polygon_normals.data_buffer().data();

Point Normals

Compute vertex normals by averaging adjacent face normals. This requires the polygons to have both face_membership and normals tagged:

compute_point_normals.cpp
// First compute polygon normals
auto polygon_normals = tf::compute_normals(polygons);

// Build face membership for adjacency queries
tf::face_membership<int> fm;
fm.build(polygons);

// Tag the polygons with topology and normals
auto tagged_polygons = polygons
    | tf::tag(fm)
    | tf::zip_normals(polygon_normals.unit_vectors());

// Compute point normals (averages adjacent face normals)
auto point_normals = tf::compute_point_normals(tagged_polygons);

// Result is a unit_vectors_buffer with one normal per vertex
for (auto normal : point_normals.unit_vectors()) {
    auto [nx, ny, nz] = normal;
}
Point normals are computed by summing the normals of all faces adjacent to a vertex and normalizing the result.