ordito.normals
Vertex normals under three weighting rules, and the accumulators beneath them.
A vertex has no normal of its own -- only the faces around it do -- so a vertex normal is always a
weighted average of incident face normals, and the weight is a modelling choice rather than a
detail. vertex_normals is the entry point, and its
weighting= keyword is that choice: by face area, by incident angle (the one invariant to how a
neighbouring polygon happened to be triangulated), or by Nelson Max's sine-and-edge-length
reciprocals.
Two accumulators sit underneath it and are public in their own right:
weighted_vertex_normals takes a caller-supplied
per-corner weight table and mean_vertex_normals is the
same thing with unit weights. They know no geometry -- they take no vertices at all, which is
why they keep an explicit n_vertices argument where vertex_normals derives it. That
asymmetry is the visible marker of which of the two layers you are in.
Referenced by 3 places
API Reference levelset › thicken_mesh · triangles › corner_normals · interpolation
Functions:
| Name | Description |
|---|---|
mean_vertex_normals |
Vertex normals as the (unnormalized) sum of incident face normals, then unit-length. |
weighted_vertex_normals |
Vertex normals from a weighted sum of incident face normals, then unit-length. |
vertex_normals |
Per-vertex unit normals, as a weighted average of the incident face normals. |
mean_vertex_normals
mean_vertex_normals(
n_vertices: int,
faces: array[int32],
face_normals: array[vec3],
) -> wp.array[wp.vec3]
Vertex normals as the (unnormalized) sum of incident face normals, then unit-length.
For each vertex, face normals sharing that corner are accumulated in float64 on
faces.device, cast to wp.vec3, and L2-normalized. Vertices not referenced by
any face remain zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_vertices
|
int
|
Number of vertices indexed by |
required |
faces
|
array[int32]
|
|
required |
face_normals
|
array[vec3]
|
|
required |
Returns:
| Type | Description |
|---|---|
array[vec3]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
weighted_vertex_normals
The same accumulator with a per-corner weight table; this is that with unit weights.
vertex_normals
The geometry-aware entry point, which derives a weight table and calls one of these two.
Examples:
Each corner of a cube averages its incident face normals with unit weight; a corner with two triangles in one side leans towards that side:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
face_normals, _areas = od.triangles.face_normals_and_areas(vertices, faces)
normals = od.normals.mean_vertex_normals(vertices.shape[0], faces, face_normals)
print(normals.shape) # (8,)
print(np.round(normals.numpy()[0], 3)) # [-0.816 -0.408 -0.408]
Referenced by 5 places
API Reference array › astype · normals · normals › vertex_normals · normals › weighted_vertex_normals
Migrating from another library Migrating from libigl › Discrete differential geometry
Source code in ordito/normals.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
weighted_vertex_normals
weighted_vertex_normals(
n_vertices: int,
faces: array[int32],
face_normals: array[vec3],
face_weights: Array2dFloat32,
) -> wp.array[wp.vec3]
Vertex normals from a weighted sum of incident face normals, then unit-length.
Each face contributes its normal scaled by the per-corner weight in face_weights;
contributions are summed per vertex in float64 on faces.device, cast to
wp.vec3, and L2-normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_vertices
|
int
|
Number of vertices indexed by |
required |
faces
|
array[int32]
|
|
required |
face_normals
|
array[vec3]
|
|
required |
face_weights
|
Array2dFloat32
|
|
required |
Returns:
| Type | Description |
|---|---|
array[vec3]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
mean_vertex_normals
This with unit weights.
vertex_normals
The geometry-aware entry point, which derives a weight table and calls this.
Examples:
Weighting each corner by its interior angle makes every cube corner normal the diagonal, whatever the triangulation of the sides:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
face_normals, _areas = od.triangles.face_normals_and_areas(vertices, faces)
angles = od.triangles.face_angles(vertices, faces)
normals = od.normals.weighted_vertex_normals(vertices.shape[0], faces, face_normals, angles)
print(np.round(normals.numpy()[0], 3)) # [-0.577 -0.577 -0.577]
Referenced by 5 places
API Reference normals · normals › mean_vertex_normals · normals › vertex_normals · triangles › corner_normals
Migrating from another library Migrating from libigl › Discrete differential geometry
Source code in ordito/normals.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
vertex_normals
vertex_normals(
vertices: array[vec3],
faces: array[int32],
*,
weighting: Literal["area", "angle", "mwselr"] = "area",
face_normals: array[vec3] | None = None,
face_weights: array[float32]
| Array2dFloat32
| None = None,
) -> wp.array[wp.vec3]
Per-vertex unit normals, as a weighted average of the incident face normals.
A vertex has no normal of its own -- only the faces around it do -- so the weight is the whole
content of the choice, and weighting selects it. Contributions are summed per vertex and
L2-normalized, so any constant factor in the weights cancels.
Which weighting to want is a measurable question, not a preference: one reference library
ships both conventions as separate entry points, and its plain per-vertex normals reproduce
"area" to 1.19e-07 while its pseudo-normals reproduce "angle" to 1.19e-07 --
each sitting 6.8e-03 from the other's partner, so the two are distinguishable well above
float32 noise. Reach for "angle" when the answer must not depend on
how a neighbouring polygon happened to be triangulated -- it is the only one of the three that
is invariant to that -- and for "area" otherwise, since it is what libigl and most of the
field default to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
weighting
|
Literal['area', 'angle', 'mwselr']
|
Which average to take.
|
'area'
|
face_normals
|
array[vec3] | None
|
|
None
|
face_weights
|
array[float32] | Array2dFloat32 | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
array[vec3]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
weighted_vertex_normals
The accumulator underneath: a caller-supplied per-corner weight table, no geometry.
mean_vertex_normals
The same accumulator with unit weights.
ordito.triangles.face_normals_and_areas
Produces the face_normals / face_weights the "area" path derives.
ordito.triangles.face_angles
Produces the "angle" path's weight table.
Examples:
The weighting matters at a cube corner, whose three sides carry different numbers of triangles
there; only "angle" returns the symmetric diagonal:
import numpy as np
import ordito as od
vertices, faces = od.creation.box()
by_area = od.normals.vertex_normals(vertices, faces)
by_angle = od.normals.vertex_normals(vertices, faces, weighting="angle")
print(by_area.shape) # (8,)
print(np.round(by_area.numpy()[0], 3)) # [-0.816 -0.408 -0.408]
print(np.round(by_angle.numpy()[0], 3)) # [-0.577 -0.577 -0.577]
Referenced by 14 places
API Reference API reference › Find a function by task · config · visibility › ambient_occlusion · visibility › shape_diameter · levelset › thicken_mesh · smoothing › inflate · Trimesh › vertex_normals · normals · normals › mean_vertex_normals · normals › weighted_vertex_normals · tangent_space › vertex_tangent_frames · triangles › corner_normals
Examples Inspecting meshes › Normals: per face, per vertex, per corner
Migrating from another library Migrating from libigl › Discrete differential geometry
Source code in ordito/normals.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |