Math Classes
Auto-generated API reference for the math classes. For guided, example-driven introductions see the tutorials — in particular Vectors, Matrices, Quaternions, and Understanding the Method Names.
Vec2
Bases: VectorBase['Vec2']
A simple 2D vector class for graphics, using numpy for efficient operations.
| Attributes: |
|
|---|
Source code in ncca/ngl/vec2.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
__matmul__(rhs)
Vec2 @ Mat2 matrix multiplication.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec2.py
71 72 73 74 75 76 77 78 79 80 81 82 83 | |
cross(rhs)
Cross product of two vectors a x b (2D version returns scalar).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec2.py
30 31 32 33 34 35 36 37 38 39 | |
outer(rhs)
Outer product of two vectors a x b.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec2.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
reflected(n)
Return a new vector reflected about a normal.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec2.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
set(*args)
Set the x,y values of the vector.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in ncca/ngl/vec2.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
Vec3
Bases: VectorBase['Vec3']
A simple 3D vector class for 3D graphics, using numpy for efficient operations.
| Attributes: |
|
|---|
Source code in ncca/ngl/vec3.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
__matmul__(rhs)
Vec3 @ Mat3 matrix multiplication.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec3.py
74 75 76 77 78 79 80 81 82 83 84 85 | |
cross(rhs)
Cross product of two vectors a x b.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec3.py
31 32 33 34 35 36 37 38 39 40 41 42 | |
outer(rhs)
Outer product of two vectors a x b.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec3.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
reflected(n)
Return a new vector reflected about a normal.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec3.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
set(*args)
Set the x,y,z values of the vector.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in ncca/ngl/vec3.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Vec4
Bases: VectorBase['Vec4']
A simple 4D vector class for graphics, using numpy for efficient operations.
| Attributes: |
|
|---|
Source code in ncca/ngl/vec4.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 106 107 | |
__matmul__(rhs)
Vec4 @ Mat4 matrix multiplication.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec4.py
77 78 79 80 81 82 83 84 85 86 | |
cross(rhs)
Cross product of two vectors a x b (4D version uses first 3 components).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec4.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
outer(rhs)
Outer product of two vectors a x b.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec4.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
reflected(n)
Return a new vector reflected about a normal.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/vec4.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
set(*args)
Set the x,y,z,w values of the vector.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in ncca/ngl/vec4.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
Mat2
Bases: MatrixBase
A 2x2 matrix for 2D transforms.
Source code in ncca/ngl/mat2.py
6 7 8 9 10 11 12 13 14 | |
Mat3
Bases: MatrixBase
A 3x3 matrix for basic affine transforms.
Source code in ncca/ngl/mat3.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
from_mat4(mat4)
classmethod
Return the upper-left 3x3 of a Mat4.
Source code in ncca/ngl/mat3.py
70 71 72 73 74 75 | |
rotate_x(angle)
classmethod
Return a rotation matrix around the X axis by angle degrees.
Source code in ncca/ngl/mat3.py
31 32 33 34 35 36 37 38 39 40 41 42 | |
rotate_y(angle)
classmethod
Return a rotation matrix around the Y axis by angle degrees.
Source code in ncca/ngl/mat3.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
rotate_z(angle)
classmethod
Return a rotation matrix around the Z axis by angle degrees.
Source code in ncca/ngl/mat3.py
57 58 59 60 61 62 63 64 65 66 67 68 | |
scale(x, y, z)
classmethod
Return a scale matrix with the diagonal set to (x, y, z).
Source code in ncca/ngl/mat3.py
22 23 24 25 26 27 28 29 | |
Mat4
Bases: MatrixBase
A 4x4 matrix for 3D affine and projective transforms.
Source code in ncca/ngl/mat4.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
from_mat3(mat3)
classmethod
Return a Mat4 with the given Mat3 as its upper-left block.
Source code in ncca/ngl/mat4.py
79 80 81 82 83 84 | |
rotate_x(angle)
classmethod
Return a rotation matrix around the X axis by angle degrees.
Source code in ncca/ngl/mat4.py
40 41 42 43 44 45 46 47 48 49 50 51 | |
rotate_y(angle)
classmethod
Return a rotation matrix around the Y axis by angle degrees.
Source code in ncca/ngl/mat4.py
53 54 55 56 57 58 59 60 61 62 63 64 | |
rotate_z(angle)
classmethod
Return a rotation matrix around the Z axis by angle degrees.
Source code in ncca/ngl/mat4.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
scale(x, y, z)
classmethod
Return a scale matrix with the diagonal set to (x, y, z, 1).
Source code in ncca/ngl/mat4.py
22 23 24 25 26 27 28 29 | |
translate(x, y, z)
classmethod
Return a translation matrix.
Source code in ncca/ngl/mat4.py
31 32 33 34 35 36 37 38 | |
Quaternion
A quaternion for representing and composing 3D rotations.
| Attributes: |
|
|---|
Source code in ncca/ngl/quaternion.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 106 107 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 179 180 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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
__add__(rhs)
Quaternion addition a+b, component-wise.
Source code in ncca/ngl/quaternion.py
107 108 109 110 111 | |
__eq__(rhs)
Quaternion comparison a==b using numpy.allclose.
Source code in ncca/ngl/quaternion.py
313 314 315 316 317 | |
__getitem__(index)
Return the component at index (0=s, 1=x, 2=y, 3=z).
| Raises: |
|
|---|
Source code in ncca/ngl/quaternion.py
192 193 194 195 196 197 198 199 200 | |
__hash__()
Compute hash for use in sets and dictionaries.
Source code in ncca/ngl/quaternion.py
324 325 326 327 328 329 330 331 | |
__init__(s=1.0, x=0.0, y=0.0, z=0.0)
Initializes a new instance of the Quaternion class.
| Parameters: |
|
|---|
Source code in ncca/ngl/quaternion.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__iter__()
Yield the components in order (s, x, y, z).
Source code in ncca/ngl/quaternion.py
337 338 339 | |
__len__()
Return the number of components (always 4).
Source code in ncca/ngl/quaternion.py
333 334 335 | |
__matmul__(rhs)
Quaternion product (Hamilton), returning a new quaternion.
Source code in ncca/ngl/quaternion.py
119 120 121 122 123 124 125 126 127 128 129 130 | |
__mul__(rhs)
Scalar scale or Vec3 rotation. Quaternion product uses @.
Source code in ncca/ngl/quaternion.py
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 | |
__ne__(rhs)
Quaternion comparison a!=b using numpy.allclose.
Source code in ncca/ngl/quaternion.py
319 320 321 322 | |
__neg__()
Return a new quaternion with every component negated.
Source code in ncca/ngl/quaternion.py
171 172 173 174 175 | |
__repr__()
Eval-able representation, e.g. Quaternion(1.0, 0.0, 0.0, 0.0).
Source code in ncca/ngl/quaternion.py
341 342 343 344 | |
__rmul__(rhs)
Scalar scale (right operand).
Source code in ncca/ngl/quaternion.py
165 166 167 168 169 | |
__str__()
Pretty representation, e.g. Quaternion(1.0, [0.0, 0.0, 0.0]).
Source code in ncca/ngl/quaternion.py
346 347 348 349 | |
__sub__(rhs)
Quaternion subtraction a-b, component-wise.
Source code in ncca/ngl/quaternion.py
113 114 115 116 117 | |
__truediv__(rhs)
Scalar division, returning a new quaternion.
| Raises: |
|
|---|
Source code in ncca/ngl/quaternion.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
conjugate()
Return the conjugate of the quaternion (s, -x, -y, -z).
Source code in ncca/ngl/quaternion.py
223 224 225 226 227 228 | |
copy()
Return a new quaternion with the same values.
Source code in ncca/ngl/quaternion.py
282 283 284 | |
dot(rhs)
Dot product of two quaternions.
Source code in ncca/ngl/quaternion.py
239 240 241 | |
from_axis_angle(axis, angle)
classmethod
Creates a new Quaternion from an axis and angle.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/quaternion.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
from_list(lst)
classmethod
Create from [s, x, y, z].
Source code in ncca/ngl/quaternion.py
298 299 300 301 302 303 | |
from_mat4(mat)
classmethod
Creates a new Quaternion from a Mat4 rotation matrix.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/quaternion.py
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 | |
from_numpy(arr)
classmethod
Create from an array [s, x, y, z].
Source code in ncca/ngl/quaternion.py
305 306 307 308 309 310 311 | |
inverse()
Return the multiplicative inverse (conjugate / |q|^2).
Source code in ncca/ngl/quaternion.py
230 231 232 233 234 235 236 237 | |
length()
Return the length/magnitude of the quaternion.
Source code in ncca/ngl/quaternion.py
215 216 217 | |
length_squared()
Return the squared magnitude.
Source code in ncca/ngl/quaternion.py
219 220 221 | |
normalized()
Return a new unit-length quaternion.
| Raises: |
|
|---|
Source code in ncca/ngl/quaternion.py
202 203 204 205 206 207 208 209 210 211 212 213 | |
set(s, x, y, z)
Set all four components.
Source code in ncca/ngl/quaternion.py
278 279 280 | |
slerp(rhs, t)
Spherical linear interpolation from self to rhs at t in [0, 1].
Source code in ncca/ngl/quaternion.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
to_list()
Return the quaternion as a list [s, x, y, z].
Source code in ncca/ngl/quaternion.py
290 291 292 | |
to_mat4()
Return the equivalent rotation matrix (row-vector convention).
Source code in ncca/ngl/quaternion.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
to_numpy()
Return the quaternion as a numpy array [s, x, y, z].
Source code in ncca/ngl/quaternion.py
286 287 288 | |
to_tuple()
Return (s, x, y, z) as plain floats.
Source code in ncca/ngl/quaternion.py
294 295 296 | |
BBox
A bounding box class for 3D geometry.
Stores center, dimensions, extents, vertices, and normals for a box. Provides methods to recalculate from center/dimensions or from extents.
Source code in ncca/ngl/bbox.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 106 107 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 179 180 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 | |
center
property
writable
Get or set the center of the bounding box.
depth
property
writable
Get or set the depth of the bounding box.
height
property
writable
Get or set the height of the bounding box.
max_x
property
Get the maximum x extent.
max_y
property
Get the maximum y extent.
max_z
property
Get the maximum z extent.
min_x
property
Get the minimum x extent.
min_y
property
Get the minimum y extent.
min_z
property
Get the minimum z extent.
width
property
writable
Get or set the width of the bounding box.
__init__(center=Vec3(), width=2.0, height=2.0, depth=2.0)
Initialize a bounding box from center and dimensions.
| Parameters: |
|---|
Source code in ncca/ngl/bbox.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
from_extents(min_x, max_x, min_y, max_y, min_z, max_z)
classmethod
Create a bounding box from min/max extents.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/bbox.py
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 | |
get_normal_array()
Get the list of 6 normals for the bounding box faces.
| Returns: |
|
|---|
Source code in ncca/ngl/bbox.py
147 148 149 150 151 152 153 | |
get_vertex_array()
Get the list of 8 vertices for the bounding box.
| Returns: |
|
|---|
Source code in ncca/ngl/bbox.py
139 140 141 142 143 144 145 | |
recalculate_from_center_dims()
Recalculate extents and update vertices/normals from center and dimensions.
Source code in ncca/ngl/bbox.py
182 183 184 185 186 187 188 189 190 191 192 193 194 | |
recalculate_from_extents()
Recalculate center and dimensions from extents, then update vertices/normals.
Source code in ncca/ngl/bbox.py
196 197 198 199 200 201 202 203 204 205 206 | |
set_extents(min_x, max_x, min_y, max_y, min_z, max_z)
Set the extents of the bounding box and recalculate center/dimensions.
| Parameters: |
|
|---|
Source code in ncca/ngl/bbox.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
Plane
A mathematical plane.
Source code in ncca/ngl/plane.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
d
property
The plane's distance term in the equation normal.p + d = 0.
normal
property
The plane's unit normal vector.
point
property
A point known to lie on the plane.
__init__(p1=None, p2=None, p3=None)
Construct a plane, optionally through three points.
| Parameters: |
|---|
Source code in ncca/ngl/plane.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
distance(p)
Return the signed distance from point p to the plane.
Source code in ncca/ngl/plane.py
66 67 68 | |
set_floats(a, b, c, d)
Define the plane from the coefficients of ax + by + cz + d = 0.
Source code in ncca/ngl/plane.py
59 60 61 62 63 64 | |
set_normal_point(normal, point)
Define the plane from a normal and a point on the plane.
Source code in ncca/ngl/plane.py
52 53 54 55 56 57 | |
set_points(p1, p2, p3)
Define the plane from three points.
Source code in ncca/ngl/plane.py
43 44 45 46 47 48 49 50 | |
Transform
A position/rotation/scale transform that can generate a Mat4.
| Attributes: |
|---|
Source code in ncca/ngl/transform.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
__init__()
Initialize the transform to identity position/rotation/scale.
Source code in ncca/ngl/transform.py
32 33 34 35 36 37 38 39 | |
__str__()
Pretty representation showing position, rotation and scale.
Source code in ncca/ngl/transform.py
116 117 118 | |
matrix()
Return a transform matrix based on rotation order.
Source code in ncca/ngl/transform.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
reset()
Reset position, rotation, scale and order to their defaults.
Source code in ncca/ngl/transform.py
73 74 75 76 77 78 79 | |
set_order(order)
Set rotation order from string e.g xyz or zyx.
Source code in ncca/ngl/transform.py
93 94 95 96 97 98 | |
set_position(*args)
Set position attrib using either x,y,z or vec types.
Source code in ncca/ngl/transform.py
81 82 83 | |
set_rotation(*args)
Set rotation attrib using either x,y,z or vec types.
Source code in ncca/ngl/transform.py
85 86 87 | |
set_scale(*args)
Set scale attrib using either x,y,z or vec types.
Source code in ncca/ngl/transform.py
89 90 91 | |
BezierCurve
A Bezier curve class.
Source code in ncca/ngl/bezier_curve.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 | |
control_points
property
The curve's control points.
knots
property
The curve's knot vector.
__init__(control_points=None, knots=None)
Create a curve from optional control points and knots.
| Parameters: |
|
|---|
Source code in ncca/ngl/bezier_curve.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
add_knot(k)
Append a knot value to the knot vector.
Source code in ncca/ngl/bezier_curve.py
57 58 59 60 | |
add_point(x, y=None, z=None)
Add a control point, either as a Vec3 or as x, y, z floats.
Source code in ncca/ngl/bezier_curve.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
cox_de_boor(u, i, k, knots)
Recursively evaluate the Cox-de Boor basis function.
Source code in ncca/ngl/bezier_curve.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
create_knots()
Generate a clamped knot vector for the current control points.
Source code in ncca/ngl/bezier_curve.py
62 63 64 65 66 67 | |
get_point_on_curve(u)
Evaluate the curve at parameter u and return the point.
Source code in ncca/ngl/bezier_curve.py
69 70 71 72 73 74 75 76 | |
Utility Functions
Free functions from ncca.ngl.util, re-exported from ncca.ngl. The
camera and projection ones are explained in the
Cameras and Projection tutorial;
clamp, lerp, and calc_normal have
their own tutorial.
clamp
Clamp num to the range [low, high].
| Raises: |
|
|---|
Source code in ncca/ngl/util.py
18 19 20 21 22 23 24 25 26 | |
lerp
Linearly interpolate between a and b at parameter t.
Works for floats and any type supporting + and scalar * (Vec2/3/4, Quaternion, matrices).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
calc_normal
Calculates the normal of a triangle defined by three points.
This is a Python implementation of the NGL C++ Util::calcNormal function. It uses the vector cross product method for clarity and leverages the py-ngl library. The order of the cross product is chosen to match the output of the C++ version.
| Parameters: |
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
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 | |
look_at
Calculate 4x4 matrix for camera lookAt.
Source code in ncca/ngl/util.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
perspective
Calculate a perspective matrix for various 3D graphics APIs.
Default mode is OpenGL, but will convert for Vulkan and WebGPU if required.
Args
fov : float - Field of view angle in degrees. aspect : float - Aspect ratio of the viewport. near : float - Near clipping plane distance. far : float - Far clipping plane distance.
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
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 | |
PerspMode
Bases: Enum
Target graphics API clip-space convention for projection matrices.
Source code in ncca/ngl/util.py
55 56 57 58 59 60 | |
ortho
Calculate an orthographic projection matrix.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
106 107 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 | |
frustum
Create a frustum projection matrix.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
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 | |
renderman_look_at
Calculate 4x4 matrix for RenderMan camera lookAt.
Accounts for RenderMan's right-handed Y-down, Z-forward coordinate system.
| Parameters: |
|---|
| Returns: |
|
|---|
Source code in ncca/ngl/util.py
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 | |
Exceptions
MatrixError
Bases: Exception
Raised for invalid matrix construction or operations.
Source code in ncca/ngl/mat_base.py
14 15 | |