- final class Vec3(x: int | float = 0, y: int | float = 0, z: int | float = 0)¶
Vec3
is an immutable 3-dimensional vector for representingx
,y
andz
coordinates. As instances of this class are immutable, calculations yield new instances ofVec3
instead of changing the x, y and z values directly.v = Vec3(1, 4, 8) assert v.x == 1 and v.y == 4 and v.z == 8 # do NOT assign to x, y and z directly, Vec3 is immutable! # instead use withX/withY/withZ or addX/east, addY/up and addZ/south or other methods to create new instances assert v.east().south(5) == Vec3(2, 4, 13) assert v.addX(-1).withY(0) - Vec3(z=8) == Vec3() # Vec3() == Vec3(0, 0, 0)
- property x¶
- property y¶
- property z¶
- classmethod from_yaw_pitch(yaw: int | float = 0, pitch: int | float = 0) Vec3 ¶
Build direction unit-vector from yaw and pitch values. This translate the in-Minecraft yaw and pitch values of entities or players (in which direction they are looking) into directional unit-vectors.
yaw: -180..179.99 (-180/180 north, -90 east, 0 south, 90 west)
pitch: -90..90 (-90 up, 0 straight, 90 down)
- yaw_pitch() tuple[float, float] ¶
The yaw and pitch values from self as directional vector. This translates directional unit-vectors into in-Minecraft yaw and pitch values used by entities or players (in which direction they are looking).
yaw: -180..179.99 (-180 north, -90 east, 0 south, 90 west)
pitch: -90..90 (-90 up, 0 straight, 90 down)
- __mul__(v: Vec3 | int | float) Vec3 ¶
Scalar multiplication if v is a number or equivalent to
multiply_elementwise()
otherwise
- length() float ¶
The length/magnitude of vector self, equivalent to
abs(self)
- with_length(length: int | float) Vec3 ¶
A vector with the same direction as self scaled to length length
- multiply_elementwise(v: Vec3) Vec3 ¶
The element-wise multiplicated vector of self and v, equivalent to
self * v
- map(func: Callable[[int | float], int | float]) Vec3 ¶
A vector with func applied to x, y and z of self as arguments
- map_pairwise(func: Callable[[int | float, int | float], int | float], v: Vec3) Vec3 ¶
A vector with func applied to each x, y and z of both self and v as arguments
- map_nwise(func: Callable[[...], int | float], *vectors: Vec3) Vec3 ¶
A vector with func applied to each x, y and z of self and all other vectors as arguments
- max(*vectors: Vec3) Vec3 ¶
A vector that is the component-wise maximum of self and the other vectors
- min(*vectors: Vec3) Vec3 ¶
A vector that is the component-wise minimum of self and the other vectors
- rotate_rad(v: Vec3, phi: float) Vec3 ¶
Rotate self around vector v by phi degree radians - Rodrigues rotation
- to_dict() dict[str, int | float] ¶
x, y and z in a dictionary
- to_tuple() tuple[int | float] ¶
x, y and z in a tuple
- is_close(v: Vec3, *, rel_tol: float = 1e-09, abs_tol: float = 0.0) bool ¶
Whether all components of self and v are approximately equal
- direction_label() Literal['east', 'south', 'west', 'north', 'up', 'down'] ¶
The direction of the longest (most significant) axis
- cardinal_label() Literal['east', 'south', 'west', 'north'] ¶
The direction of the longest (most significant) cardinal axis
- clamp(min_v: Vec3, max_v: Vec3) Vec3 ¶
The vector self with clamped x, y and z between the corresponding components of min_val and max_val
- in_box(corner1: Vec3, corner2: Vec3) bool ¶
Whether self is enclosed in the bounding box/cube spanned between corner1 and corner2, both corners inclusive
- add() Vec3 ¶
- add(scalar: int | float) Vec3
- add(vector: Vec3) Vec3
- add(x: int | float, y: int | float, z: int | float) Vec3
- add(*, x: int | float | None = None, y: int | float | None = None, z: int | float | None = None) Vec3
self with added scalar, another vector, or explicit component-wise values. Supports: * add() will add 1 to all components * add(scalar) will add scalar to all components * add(Vec3) * add(x, y, z) * add(x=1, y=2, z=3) with optional partials (missing parts default to 0)