dymokomi/luced-3d
Source of release 0.11.8
## Angles: the scene keeps degrees on node parameters (as artists type
## them) and radians in sketches and maths; these convert.
from luce_3d.graphics import Vector3
from luce_std import math
## Degrees `value` in radians.
pub func radians(value: float) -> float:
return value * math.pi / 180.0
## Radians `value` in degrees.
pub func degrees(value: float) -> float:
return value * 180.0 / math.pi
## The X, Y and Z angles (radians) whose rotation (Z, then Y, then X, as
## Vector3.rotated and Matrix4.compose turn) takes the world's axes to
## `axes`: R = Rx Ry Rz, the axes its columns. When Y is a quarter turn, Z's
## angle is taken 0.
pub func euler_angles(axes: list[Vector3]) -> list[float]:
# R's entries: row r, column c is axes[c]'s component r.
let r02 = math.max(-1.0, math.min(1.0, axes[2].x))
let y = math.asin(r02)
if math.abs(r02) > 0.999999:
return [math.atan2(axes[1].z, axes[1].y), y, 0.0]
return [math.atan2(-axes[2].y, axes[2].z), y, math.atan2(-axes[1].x, axes[0].x)]