Skip to content

The vector class

API: Vec3 class

xyz property

Get the vector as a tuple Useful for passing to arguments e.g. player.spawn(sim, *v.xyz())

Returns:

Name Type Description
values tuple

a tuple with x,y,z

__add__(v)

operator add immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__eq__(v)

operator equals immutable

Parameters:

Name Type Description Default
v Vec3

the other vector

required

Returns:

Type Description
bool

new vector

__iadd__(v)

operator inline add (+=) mutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__imul__(v)

operator inline multiply mutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__isub__(v)

operator inline subtract mutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__itruediv__(v)

operator inline divide mutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__matmul__(v)

operator matrix multiply (@) dot product immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__mul__(v)

operator multiply immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__neg__()

operator Negate a vector immutable

Returns:

Type Description
Vec3

new vector negated version of this one

__sub__(v)

operator sub immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

__truediv__(v)

operator divide immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

add(v)

add immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

angleTo(a)

angle to

Parameters:

Name Type Description Default
a Vec3

The other point

required

Returns:

Name Type Description
float

Angle in radians

cross(v)

cross product immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

divide(v)

divide immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

dot(v)

dot product immutable

Parameters:

Name Type Description Default
v Vec3

the other vector

required

Returns:

Type Description
Vec3

new vector

equals(v)

equals immutable

Parameters:

Name Type Description Default
v Vec3

the other vector

required

Returns:

Type Description
bool

if they are equal

length()

length immutable

Returns:

Type Description
float

The length of the vector

max()

max of x,y,z

Returns:

Type Description
float

max of x,y,z

min()

min of x,y,z

Returns:

Type Description
float

min of x,y,z

multiply(v)

multiply immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

neg()

Negate a vector immutable

Returns:

Type Description
Vec3

new vector negated version of this one

rand_in_sphere(radius, outer=0, only_top_half=False, ring=False)

random within a sphere

Parameters:

Name Type Description Default
radius float

radius

required
outer float

outer radius if 0 r is outer, if non-zero r is inner radius. default=0

0
only_top_half bool

limit to top half

False
ring bool

limit to 2d ring

False

Returns:

Type Description
Vec3

A randomly offset vector within the sphere/ring

rand_offset(r, outer=0, top_only=False, ring=False)

random spherical offset

Parameters:

Name Type Description Default
r float

radius

required
outer float

outer radius if 0 r is outer, if non-zero r is inner radius. default=0

0
top_only bool

limit to top half

False
ring bool

limit to 2d ring

False

Returns:

Type Description
Vec3

A randomly offset vector within the sphere/ring

rotate_around(o, ax, ay, az, degrees=True)

Rotate around a point

Parameters:

Name Type Description Default
o Vec3

origin

required
ax float

x angle

required
ay float

y angle

required
az float

z angle

required
degrees bool

Use degrees if true, radians if false. Defaults to True.

True

Returns:

Name Type Description
Vec3

The new vector

subtract(v)

subtract immutable

Parameters:

Name Type Description Default
v Vec3 or number

the other vector

required

Returns:

Type Description
Vec3

new vector

toAngles()

polar angles

Returns:

Type Description

theta, phi (float, float): tuple containing theta and phi

unit()

unit vector immutable

Returns:

Type Description
Vec3

new vector