Vec3:length
methodVec3:length() -> numberMagnitude.
handle40 methods, 3 fields, 6 operators
A 3D vector (Y-up). Construct with datumhue.math.vec3(x, y, z). #v is v:length(), not a component count.
datumhue.math.vec3, datumhue.time.tween (in its callback), datumhue.physics.raycast, datumhue.physics.raycast_all, datumhue.physics.shapecast, datumhue.voxel.world (in its callback), datumhue.math.vec3.from_array, Scene:raycast and 40 moredatumhue.math.ray, datumhue.time.tween, datumhue.physics.add_joint, datumhue.physics.point_query, datumhue.voxel.new, datumhue.voxel.world, datumhue.particles.emitter, datumhue.math.quat.from_axis_angle and 63 moreVec3 + Vec3 -> Vec3 Component-wise addition.Vec3 - Vec3 -> Vec3 Component-wise subtraction.Vec3 * Vec3 | number -> Vec3 Vector or scalar multiplication.Vec3 / Vec3 | number -> Vec3 Vector or scalar division.-Vec3 -> Vec3 Negation.#Vec3 -> number Magnitude (the # operator).| Field | Type | Access | Description |
|---|---|---|---|
x | number | read-only | X component. |
y | number | read-only | Y component. |
z | number | read-only | Z component. |
Vec3:length() -> numberMagnitude.
Vec3:length_squared() -> numberSquared magnitude (no sqrt).
Vec3:min_element() -> numberSmallest component.
Vec3:max_element() -> numberLargest component.
Vec3:normalize() -> Vec3Unit vector. Raises if v is zero-length / non-finite; use normalize_or or try_normalize for a fallback.
Unit vector, or fallback if v is zero-length / non-finite.
Vec3:try_normalize() -> Vec3?Unit vector, or nil if v is zero-length / non-finite.
Vec3:distance_squared(o: Vec3) -> numberSquared Euclidean distance to o (no sqrt).
Vec3:signum() -> Vec3Component-wise sign (-1, 0, or +1).
Vec3:fract() -> Vec3Component-wise fractional part (self - self.trunc()).
Vec3:recip() -> Vec3Component-wise reciprocal (1/x).
Vec3:element_sum() -> numberSum of the components.
Vec3:element_product() -> numberProduct of the components.
Vec3:to_array() -> number[]Components as a {x, y, z} array.
Vec3:abs() -> Vec3Component-wise absolute value.
Vec3:floor() -> Vec3Component-wise floor.
Vec3:ceil() -> Vec3Component-wise ceil.
Vec3:round() -> Vec3Component-wise round.
Vec3:any_orthogonal() -> Vec3An arbitrary vector orthogonal to v.
Vec3:dot(o: Vec3) -> numberDot product.
Vec3:distance(o: Vec3) -> numberEuclidean distance to o.
Vec3:angle_between(o: Vec3) -> numberUnsigned angle to o in radians.
-- Unsigned radians, from 0 to pi.
local x = datumhue.math.vec3(1, 0, 0)
local up = datumhue.math.vec3(0, 1, 0)
local back = datumhue.math.vec3(-1, 0, 0)
print(string.format("%.4f", x:angle_between(up))) --> 1.5708
print(string.format("%.4f", x:angle_between(back))) --> 3.1416Cross product.
-- The order matters: X cross Y is +Z, Y cross X is -Z.
local x = datumhue.math.vec3(1, 0, 0)
local y = datumhue.math.vec3(0, 1, 0)
print(x:cross(y)) --> vec3(0.0, 0.0, 1.0)
print(y:cross(x)) --> vec3(0.0, 0.0, -1.0)Midpoint between v and o.
Reflect v about the normal o.
Component-wise minimum.
Component-wise maximum.
Projection of v onto o. Errors if o is zero-length.
Rejection of v from o. Errors if o is zero-length.
Linear interpolation toward o by t; t outside 0..1 extrapolates past the endpoints (not clamped).
Spherical interpolation toward o by t.
Move toward o by at most distance d.
Component-wise clamp to [lo, hi].
Vec3:clamp_length(lo: number, hi: number) -> Vec3Clamp magnitude to [lo, hi].
Vec3:is_normalized() -> booleanWhether the vector is unit length.
Vec3:truncate() -> Vec2Drop the z component, returning a Vec2.
Vec3:with_x(x: number) -> Vec3Copy with x replaced.
Vec3:with_y(y: number) -> Vec3Copy with y replaced.
Vec3:with_z(z: number) -> Vec3Copy with z replaced.
Vec3:unpack() -> number, number, numberReturn the x, y and z components as three values.
local x, y, z = datumhue.math.vec3(1, 2, 3):unpack()
print(x, y, z) --> 1.0 2.0 3.0