Points/Vectors

Important

Vectors can be implicitly created from tuple, list and numpy.ndarray objects, as long as the number of elements matches the dimensionality of the vector.

viren2d.Vec2i

A 2D vector of int coordinates.

viren2d.Vec3i

A 3D vector of int coordinates.

viren2d.Vec2d

A 2D vector of float coordinates.

viren2d.Vec3d

A 3D vector of float coordinates.

Integral 2D: Vec2i

class viren2d.Vec2i

A 2D vector of int coordinates.

Corresponding C++ API: viren2d::Vec2i.

Methods:

__add__

Overloaded function.

__eq__

Checks for equality.

__getitem__

Allows accessing this vector's values via vec[i].

__getstate__

__iadd__

Overloaded function.

__init__

Overloaded function.

__mul__

Overloaded function.

__ne__

Checks for inequality.

__neg__

Returns a Vec2d, where all values are negated.

__rmul__

Element-wise multiplication: Vec2i = int * Vec2i.

__setitem__

Allows accessing this vector's values via vec[idx].

__setstate__

Vec2d instances can be pickled.

__sub__

Overloaded function.

__truediv__

Overloaded function.

all

Creates a vector where each coordinate is set to the given scalar.

angle_deg

Computes the angle \(\in [0, 180]\) between this and the other vector.

angle_rad

Computes the angle \(\in [0, \pi]\) between this and the other vector.

as_float

Returns a Vec2i as the result of explicitly casting the values.

as_int

Returns a copy of this vector as Vec2i

copy

Returns a deep copy.

direction_vector

Returns the Vec2i direction vector, other - self.

distance_l1

Returns the Manhattan distance between self and the other Vec2i.

distance_l2

Returns the Euclidean distance between self and the other Vec2i.

dot

Returns the dot product of self and the other Vec2i.

homogeneous

Returns the homogeneous representation of this vector, i.e. a 3-element tuple, where the additional dimension is set to 1.

length

Returns the length of this vector.

length_squared

Returns this vector's squared length.

max_index

Returns \(i = \arg_i \max(v_i)\).

max_value

Returns \(\max(v_i)\).

min_index

Returns \(i = \arg_i \min(v_i)\).

min_value

Returns \(\min(v_i)\).

perpendicular_ccw

Returns the 90° counterclockwise rotated vector.

perpendicular_cw

Returns the 90° clockwise rotated vector.

unit_vector

Returns the corresponding unit vector as Vec2d.

Attributes:

dtype

Underlying data type (read-only).

height

Provides alternative read-write access to the second dimension, (i.e. y).

ndim

Number of dimensions (read-only), i.e. 2.

width

Provides alternative read-write access to the first dimension, (i.e. x).

x

Read-write access to the first dimension, i.e. same as vec[0].

y

Read-write access to the second dimension, i.e. same as vec[1].

__add__(*args, **kwargs)

Overloaded function.

  1. __add__(self: viren2d.Vec2i, scalar: int) -> viren2d.Vec2i

Element-wise addition: Vec2i = Vec2i + int.

  1. __add__(self: viren2d.Vec2i, rhs: viren2d.Vec2i) -> viren2d.Vec2i

Element-wise addition: Vec2i = Vec2i + Vec2i.

__eq__(self: viren2d.Vec2i, other: viren2d.Vec2i) bool

Checks for equality.

__getitem__(self: viren2d.Vec2i, arg0: int) int

Allows accessing this vector’s values via vec[i].

__getstate__(self: viren2d.Vec2i) tuple
__iadd__(*args, **kwargs)

Overloaded function.

  1. __iadd__(self: viren2d.Vec2i, rhs: int) -> viren2d.Vec2i

In-place element-wise addition: Vec2i += int.

  1. __iadd__(self: viren2d.Vec2i, rhs: viren2d.Vec2i) -> viren2d.Vec2i

In-place element-wise addition: Vec2i += Vec2i.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: viren2d.Vec2i) -> None

Initializes all values to 0.

  1. __init__(self: viren2d.Vec2i, vec: viren2d.Vec2i) -> None

Creates a copy of the given Vec2i.

  1. __init__(self: viren2d.Vec2i, tpl: tuple) -> None

Creates a vector from a 2-element tuple.

  1. __init__(self: viren2d.Vec2i, lst: list) -> None

Creates a vector from a 2-element list.

  1. __init__(self: viren2d.Vec2i, arr: numpy.ndarray) -> None

Creates a vector from a 2-element numpy.array.

  1. __init__(self: viren2d.Vec2i, x: int, y: int) -> None

Explicit initialization from 2 separate values.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: viren2d.Vec2i, rhs: int) -> viren2d.Vec2i

Element-wise multiplication: Vec2i = Vec2i * int.

  1. __mul__(self: viren2d.Vec2i, rhs: viren2d.Vec2i) -> viren2d.Vec2i

Element-wise multiplication: Vec2i = Vec2i * Vec2i.

__ne__(self: viren2d.Vec2i, other: viren2d.Vec2i) bool

Checks for inequality.

__neg__(self: viren2d.Vec2i) viren2d.Vec2i

Returns a Vec2d, where all values are negated.

__rmul__(self: viren2d.Vec2i, lhs: int) viren2d.Vec2i

Element-wise multiplication: Vec2i = int * Vec2i.

__setitem__(self: viren2d.Vec2i, arg0: int, arg1: int) None

Allows accessing this vector’s values via vec[idx].

__setstate__(self: viren2d.Vec2i, arg0: tuple) None

Vec2d instances can be pickled.

__sub__(*args, **kwargs)

Overloaded function.

  1. __sub__(self: viren2d.Vec2i, rhs: int) -> viren2d.Vec2i

Element-wise subtraction: Vec2i = Vec2i - int.

  1. __sub__(self: viren2d.Vec2i, rhs: viren2d.Vec2i) -> viren2d.Vec2i

Element-wise subtraction: Vec2i = Vec2i - Vec2i.

__truediv__(*args, **kwargs)

Overloaded function.

  1. __truediv__(self: viren2d.Vec2i, rhs: int) -> viren2d.Vec2d

Element-wise division with implicit type conversion. Returns a double-precision Vec2d = Vec2i / int.

  1. __truediv__(self: viren2d.Vec2i, rhs: float) -> viren2d.Vec2d

Element-wise division with implicit type conversion. Returns a double-precision Vec2d = Vec2i / float.

  1. __truediv__(self: viren2d.Vec2i, rhs: viren2d.Vec2i) -> viren2d.Vec2d

Element-wise division with implicit type conversion. Returns a double-precision Vec2d = Vec2i / Vec2i.

static all(value: int) viren2d.Vec2i

Creates a vector where each coordinate is set to the given scalar.

Corresponding C++ API: viren2d::Vec2i::All.

angle_deg(self: viren2d.Vec2i, other: viren2d.Vec2i) float

Computes the angle \(\in [0, 180]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec2i

Returns:

The angle \(\in [0, 180]\) in degrees.

angle_rad(self: viren2d.Vec2i, other: viren2d.Vec2i) float

Computes the angle \(\in [0, \pi]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec2i

Returns:

The angle \(\in [0, \pi]\) in radians.

as_float(self: viren2d.Vec2i) viren2d.Vec2d

Returns a Vec2i as the result of explicitly casting the values.

Corresponding C++ API: viren2d::Vec2i::ToDouble.

as_int(self: viren2d.Vec2i) viren2d.Vec2i

Returns a copy of this vector as Vec2i

Corresponding C++ API: viren2d::Vec2i::ToInteger.

copy(self: viren2d.Vec2i) viren2d.Vec2i

Returns a deep copy.

Corresponding C++ API: Copy constructor of viren2d::Vec2i.

direction_vector(self: viren2d.Vec2i, other: viren2d.Vec2i) viren2d.Vec2i

Returns the Vec2i direction vector, other - self.

distance_l1(self: viren2d.Vec2i, other: viren2d.Vec2i) float

Returns the Manhattan distance between self and the other Vec2i.

distance_l2(self: viren2d.Vec2i, other: viren2d.Vec2i) float

Returns the Euclidean distance between self and the other Vec2i.

dot(self: viren2d.Vec2i, other: viren2d.Vec2i) int

Returns the dot product of self and the other Vec2i.

property dtype

Underlying data type (read-only).

Type:

numpy.dtype

property height

Provides alternative read-write access to the second dimension, (i.e. y).

Can be useful if you want to use this 2D vector to represent a 2D size. This property is only available for 2-dimensional vectors.

Type:

int

homogeneous(self: viren2d.Vec2i) tuple

Returns the homogeneous representation of this vector, i.e. a 3-element tuple, where the additional dimension is set to 1.

length(self: viren2d.Vec2i) float

Returns the length of this vector.

Corresponding C++ API: viren2d::Vec2i::Length.

length_squared(self: viren2d.Vec2i) float

Returns this vector’s squared length.

max_index(self: viren2d.Vec2i) int

Returns \(i = \arg_i \max(v_i)\).

Corresponding C++ API: viren2d::Vec2i::MaxIndex.

max_value(self: viren2d.Vec2i) int

Returns \(\max(v_i)\).

Corresponding C++ API: viren2d::Vec2i::MaxValue.

min_index(self: viren2d.Vec2i) int

Returns \(i = \arg_i \min(v_i)\).

Corresponding C++ API: viren2d::Vec2i::MinIndex.

min_value(self: viren2d.Vec2i) int

Returns \(\min(v_i)\).

Corresponding C++ API: viren2d::Vec2i::MinValue.

property ndim

Number of dimensions (read-only), i.e. 2.

Type:

int

perpendicular_ccw(self: viren2d.Vec2i) viren2d.Vec2i

Returns the 90° counterclockwise rotated vector.

This method assumes that the coordinate system is right-handed and is only supported for 2D vectors.

perpendicular_cw(self: viren2d.Vec2i) viren2d.Vec2i

Returns the 90° clockwise rotated vector.

This method assumes that the coordinate system is right-handed and is only supported for 2D vectors.

unit_vector(self: viren2d.Vec2i) viren2d.Vec2d

Returns the corresponding unit vector as Vec2d.

property width

Provides alternative read-write access to the first dimension, (i.e. x).

Can be useful if you want to use this 2D vector to represent a 2D size. This property is only available for 2-dimensional vectors.

Type:

int

property x

Read-write access to the first dimension, i.e. same as vec[0].

Type:

int

property y

Read-write access to the second dimension, i.e. same as vec[1].

Type:

int

Integral 3D: Vec3i

class viren2d.Vec3i

A 3D vector of int coordinates.

Corresponding C++ API: viren2d::Vec3i.

Methods:

__add__

Overloaded function.

__eq__

Checks for equality.

__getitem__

Allows accessing this vector's values via vec[i].

__getstate__

__iadd__

Overloaded function.

__init__

Overloaded function.

__mul__

Overloaded function.

__ne__

Checks for inequality.

__neg__

Returns a Vec3d, where all values are negated.

__rmul__

Element-wise multiplication: Vec3i = int * Vec3i.

__setitem__

Allows accessing this vector's values via vec[idx].

__setstate__

Vec3d instances can be pickled.

__sub__

Overloaded function.

__truediv__

Overloaded function.

all

Creates a vector where each coordinate is set to the given scalar.

angle_deg

Computes the angle \(\in [0, 180]\) between this and the other vector.

angle_rad

Computes the angle \(\in [0, \pi]\) between this and the other vector.

as_float

Returns a Vec3i as the result of explicitly casting the values.

as_int

Returns a copy of this vector as Vec3i

copy

Returns a deep copy.

cross

Computes the cross product.

direction_vector

Returns the Vec3i direction vector, other - self.

distance_l1

Returns the Manhattan distance between self and the other Vec3i.

distance_l2

Returns the Euclidean distance between self and the other Vec3i.

dot

Returns the dot product of self and the other Vec3i.

homogeneous

Returns the homogeneous representation of this vector, i.e. a 4-element tuple, where the additional dimension is set to 1.

length

Returns the length of this vector.

length_squared

Returns this vector's squared length.

max_index

Returns \(i = \arg_i \max(v_i)\).

max_value

Returns \(\max(v_i)\).

min_index

Returns \(i = \arg_i \min(v_i)\).

min_value

Returns \(\min(v_i)\).

unit_vector

Returns the corresponding unit vector as Vec3d.

Attributes:

dtype

Underlying data type (read-only).

ndim

Number of dimensions (read-only), i.e. 3.

x

Read-write access to the first dimension, i.e. same as vec[0].

y

Read-write access to the second dimension, i.e. same as vec[1].

z

Read-write access to the third dimension, i.e. same as vec[2].

__add__(*args, **kwargs)

Overloaded function.

  1. __add__(self: viren2d.Vec3i, scalar: int) -> viren2d.Vec3i

Element-wise addition: Vec3i = Vec3i + int.

  1. __add__(self: viren2d.Vec3i, rhs: viren2d.Vec3i) -> viren2d.Vec3i

Element-wise addition: Vec3i = Vec3i + Vec3i.

__eq__(self: viren2d.Vec3i, other: viren2d.Vec3i) bool

Checks for equality.

__getitem__(self: viren2d.Vec3i, arg0: int) int

Allows accessing this vector’s values via vec[i].

__getstate__(self: viren2d.Vec3i) tuple
__iadd__(*args, **kwargs)

Overloaded function.

  1. __iadd__(self: viren2d.Vec3i, rhs: int) -> viren2d.Vec3i

In-place element-wise addition: Vec3i += int.

  1. __iadd__(self: viren2d.Vec3i, rhs: viren2d.Vec3i) -> viren2d.Vec3i

In-place element-wise addition: Vec3i += Vec3i.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: viren2d.Vec3i) -> None

Initializes all values to 0.

  1. __init__(self: viren2d.Vec3i, vec: viren2d.Vec3i) -> None

Creates a copy of the given Vec3i.

  1. __init__(self: viren2d.Vec3i, tpl: tuple) -> None

Creates a vector from a 3-element tuple.

  1. __init__(self: viren2d.Vec3i, lst: list) -> None

Creates a vector from a 3-element list.

  1. __init__(self: viren2d.Vec3i, arr: numpy.ndarray) -> None

Creates a vector from a 3-element numpy.array.

  1. __init__(self: viren2d.Vec3i, x: int, y: int, z: int) -> None

Explicit initialization from 3 separate values.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: viren2d.Vec3i, rhs: int) -> viren2d.Vec3i

Element-wise multiplication: Vec3i = Vec3i * int.

  1. __mul__(self: viren2d.Vec3i, rhs: viren2d.Vec3i) -> viren2d.Vec3i

Element-wise multiplication: Vec3i = Vec3i * Vec3i.

__ne__(self: viren2d.Vec3i, other: viren2d.Vec3i) bool

Checks for inequality.

__neg__(self: viren2d.Vec3i) viren2d.Vec3i

Returns a Vec3d, where all values are negated.

__rmul__(self: viren2d.Vec3i, lhs: int) viren2d.Vec3i

Element-wise multiplication: Vec3i = int * Vec3i.

__setitem__(self: viren2d.Vec3i, arg0: int, arg1: int) None

Allows accessing this vector’s values via vec[idx].

__setstate__(self: viren2d.Vec3i, arg0: tuple) None

Vec3d instances can be pickled.

__sub__(*args, **kwargs)

Overloaded function.

  1. __sub__(self: viren2d.Vec3i, rhs: int) -> viren2d.Vec3i

Element-wise subtraction: Vec3i = Vec3i - int.

  1. __sub__(self: viren2d.Vec3i, rhs: viren2d.Vec3i) -> viren2d.Vec3i

Element-wise subtraction: Vec3i = Vec3i - Vec3i.

__truediv__(*args, **kwargs)

Overloaded function.

  1. __truediv__(self: viren2d.Vec3i, rhs: int) -> viren2d.Vec3d

Element-wise division with implicit type conversion. Returns a double-precision Vec3d = Vec3i / int.

  1. __truediv__(self: viren2d.Vec3i, rhs: float) -> viren2d.Vec3d

Element-wise division with implicit type conversion. Returns a double-precision Vec3d = Vec3i / float.

  1. __truediv__(self: viren2d.Vec3i, rhs: viren2d.Vec3i) -> viren2d.Vec3d

Element-wise division with implicit type conversion. Returns a double-precision Vec3d = Vec3i / Vec3i.

static all(value: int) viren2d.Vec3i

Creates a vector where each coordinate is set to the given scalar.

Corresponding C++ API: viren2d::Vec3i::All.

angle_deg(self: viren2d.Vec3i, other: viren2d.Vec3i) float

Computes the angle \(\in [0, 180]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec3i

Returns:

The angle \(\in [0, 180]\) in degrees.

angle_rad(self: viren2d.Vec3i, other: viren2d.Vec3i) float

Computes the angle \(\in [0, \pi]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec3i

Returns:

The angle \(\in [0, \pi]\) in radians.

as_float(self: viren2d.Vec3i) viren2d.Vec3d

Returns a Vec3i as the result of explicitly casting the values.

Corresponding C++ API: viren2d::Vec3i::ToDouble.

as_int(self: viren2d.Vec3i) viren2d.Vec3i

Returns a copy of this vector as Vec3i

Corresponding C++ API: viren2d::Vec3i::ToInteger.

copy(self: viren2d.Vec3i) viren2d.Vec3i

Returns a deep copy.

Corresponding C++ API: Copy constructor of viren2d::Vec3i.

cross(self: viren2d.Vec3i, other: viren2d.Vec3i) viren2d.Vec3i

Computes the cross product.

direction_vector(self: viren2d.Vec3i, other: viren2d.Vec3i) viren2d.Vec3i

Returns the Vec3i direction vector, other - self.

distance_l1(self: viren2d.Vec3i, other: viren2d.Vec3i) float

Returns the Manhattan distance between self and the other Vec3i.

distance_l2(self: viren2d.Vec3i, other: viren2d.Vec3i) float

Returns the Euclidean distance between self and the other Vec3i.

dot(self: viren2d.Vec3i, other: viren2d.Vec3i) int

Returns the dot product of self and the other Vec3i.

property dtype

Underlying data type (read-only).

Type:

numpy.dtype

homogeneous(self: viren2d.Vec3i) tuple

Returns the homogeneous representation of this vector, i.e. a 4-element tuple, where the additional dimension is set to 1.

length(self: viren2d.Vec3i) float

Returns the length of this vector.

Corresponding C++ API: viren2d::Vec3i::Length.

length_squared(self: viren2d.Vec3i) float

Returns this vector’s squared length.

max_index(self: viren2d.Vec3i) int

Returns \(i = \arg_i \max(v_i)\).

Corresponding C++ API: viren2d::Vec3i::MaxIndex.

max_value(self: viren2d.Vec3i) int

Returns \(\max(v_i)\).

Corresponding C++ API: viren2d::Vec3i::MaxValue.

min_index(self: viren2d.Vec3i) int

Returns \(i = \arg_i \min(v_i)\).

Corresponding C++ API: viren2d::Vec3i::MinIndex.

min_value(self: viren2d.Vec3i) int

Returns \(\min(v_i)\).

Corresponding C++ API: viren2d::Vec3i::MinValue.

property ndim

Number of dimensions (read-only), i.e. 3.

Type:

int

unit_vector(self: viren2d.Vec3i) viren2d.Vec3d

Returns the corresponding unit vector as Vec3d.

property x

Read-write access to the first dimension, i.e. same as vec[0].

Type:

int

property y

Read-write access to the second dimension, i.e. same as vec[1].

Type:

int

property z

Read-write access to the third dimension, i.e. same as vec[2].

Type:

int

Floating point 2D: Vec2d

class viren2d.Vec2d

A 2D vector of float coordinates.

Corresponding C++ API: viren2d::Vec2d.

Methods:

__add__

Overloaded function.

__eq__

Returns True if the two vectors are approximately equal.

__getitem__

Allows accessing this vector's values via vec[i].

__getstate__

__iadd__

Overloaded function.

__init__

Overloaded function.

__mul__

Overloaded function.

__ne__

Returns True if the two vectors are approximately equal.

__neg__

Returns a Vec2d, where all values are negated.

__rmul__

Overloaded function.

__setitem__

Allows accessing this vector's values via vec[idx].

__setstate__

Vec2d instances can be pickled.

__sub__

Overloaded function.

__truediv__

Overloaded function.

all

Creates a vector where each coordinate is set to the given scalar.

angle_deg

Computes the angle \(\in [0, 180]\) between this and the other vector.

angle_rad

Computes the angle \(\in [0, \pi]\) between this and the other vector.

as_float

Returns a copy of this vector as Vec2d

as_int

Returns a Vec2i as the result of explicitly casting/clipping the values.

copy

Returns a deep copy.

direction_vector

Returns the Vec2d direction vector, other - self.

distance_l1

Returns the Manhattan distance between self and the other Vec2d.

distance_l2

Returns the Euclidean distance between self and the other Vec2d.

dot

Returns the dot product of self and the other Vec2d.

homogeneous

Returns the homogeneous representation of this vector, i.e. a 3-element tuple, where the additional dimension is set to 1.

length

Returns the length of this vector.

length_squared

Returns this vector's squared length.

max_index

Returns \(i = \arg_i \max(v_i)\).

max_value

Returns \(\max(v_i)\).

min_index

Returns \(i = \arg_i \min(v_i)\).

min_value

Returns \(\min(v_i)\).

perpendicular_ccw

Returns the 90° counterclockwise rotated vector.

perpendicular_cw

Returns the 90° clockwise rotated vector.

rotate_deg

Returns a copy of this vector rotated around the reference point by the given angle.

rotate_rad

Returns a copy of this vector rotated around the reference point by the given angle.

unit_vector

Returns the corresponding unit vector as Vec2d.

Attributes:

dtype

Underlying data type (read-only).

height

Provides alternative read-write access to the second dimension, (i.e. y).

ndim

Number of dimensions (read-only), i.e. 2.

width

Provides alternative read-write access to the first dimension, (i.e. x).

x

Read-write access to the first dimension, i.e. same as vec[0].

y

Read-write access to the second dimension, i.e. same as vec[1].

__add__(*args, **kwargs)

Overloaded function.

  1. __add__(self: viren2d.Vec2d, scalar: int) -> viren2d.Vec2d

Element-wise addition: Vec2d = Vec2d + int.

  1. __add__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise addition: Vec2d = Vec2d + Vec2d.

  1. __add__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise addition: Vec2d = Vec2d + Vec2d.

  1. __add__(self: viren2d.Vec2d, rhs: float) -> viren2d.Vec2d

Element-wise addition: Vec2d = Vec2d + float.

__eq__(self: viren2d.Vec2d, other: viren2d.Vec2d) bool

Returns True if the two vectors are approximately equal.

Uses a combined test with both relative and absolute tolerance. Modulo special cases (NaN, infinity), two vectors \(x = (x_i)_{i=1}^2\) and \(y = (y_i)_{i=1}^2\) are considered approximately equal if for all their values

\(|x_i - y_i| \leq \epsilon_{\text{rel}} * \max(|x_i|, |y_i|) \quad\text{or}\quad |x_i - y_i| \leq \epsilon_{\text{abs}}\),

where \(\epsilon_{\text{rel}} = 1e-9\) and \(\epsilon_{\text{abs}} = 1e-12\).

Corresponding C++ API: viren2d::Vec2d::operator== and ::IsClose

__getitem__(self: viren2d.Vec2d, arg0: int) float

Allows accessing this vector’s values via vec[i].

__getstate__(self: viren2d.Vec2d) tuple
__iadd__(*args, **kwargs)

Overloaded function.

  1. __iadd__(self: viren2d.Vec2d, rhs: int) -> viren2d.Vec2d

In-place element-wise addition: Vec2d += int.

  1. __iadd__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

In-place element-wise addition: Vec2d += Vec2d.

  1. __iadd__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

In-place element-wise addition: Vec2d += Vec2d.

  1. __iadd__(self: viren2d.Vec2d, rhs: float) -> viren2d.Vec2d

In-place element-wise addition: Vec2d += float.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: viren2d.Vec2d) -> None

Initializes all values to 0.

  1. __init__(self: viren2d.Vec2d, vec_int: werkzeugkiste::geometry::Vec<int, 2ul>) -> None

Creates a double-precision vector from its 32-bit integral counterpart.

  1. __init__(self: viren2d.Vec2d, vec: viren2d.Vec2d) -> None

Creates a copy of the given Vec2d.

  1. __init__(self: viren2d.Vec2d, tpl: tuple) -> None

Creates a vector from a 2-element tuple.

  1. __init__(self: viren2d.Vec2d, lst: list) -> None

Creates a vector from a 2-element list.

  1. __init__(self: viren2d.Vec2d, arr: numpy.ndarray) -> None

Creates a vector from a 2-element numpy.array.

  1. __init__(self: viren2d.Vec2d, x: float, y: float) -> None

Explicit initialization from 2 separate values.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: viren2d.Vec2d, rhs: int) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = Vec2d * int.

  1. __mul__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = Vec2d * Vec2d.

  1. __mul__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = Vec2d * Vec2d.

  1. __mul__(self: viren2d.Vec2d, rhs: float) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = Vec2d * float.

__ne__(self: viren2d.Vec2d, other: viren2d.Vec2d) bool

Returns True if the two vectors are approximately equal.

Uses a combined test with both relative and absolute tolerance. Modulo special cases (NaN, infinity), two vectors \(x = (x_i)_{i=1}^2\) and \(y = (y_i)_{i=1}^2\) are considered approximately equal if for all their values

\(|x_i - y_i| \leq \epsilon_{\text{rel}} * \max(|x_i|, |y_i|) \quad\text{or}\quad |x_i - y_i| \leq \epsilon_{\text{abs}}\),

where \(\epsilon_{\text{rel}} = 1e-9\) and \(\epsilon_{\text{abs}} = 1e-12\).

Corresponding C++ API: viren2d::Vec2d::operator== and ::IsClose``Returns ``True if the two vectors differ sufficiently.

As this operator computes !(vec1 == vec2), refer to __eq__() for details.

__neg__(self: viren2d.Vec2d) viren2d.Vec2d

Returns a Vec2d, where all values are negated.

__rmul__(*args, **kwargs)

Overloaded function.

  1. __rmul__(self: viren2d.Vec2d, lhs: int) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = int * Vec2d.

  1. __rmul__(self: viren2d.Vec2d, lhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = Vec2d * Vec2d.

  1. __rmul__(self: viren2d.Vec2d, lhs: float) -> viren2d.Vec2d

Element-wise multiplication: Vec2d = float * Vec2d.

__setitem__(self: viren2d.Vec2d, arg0: int, arg1: float) None

Allows accessing this vector’s values via vec[idx].

__setstate__(self: viren2d.Vec2d, arg0: tuple) None

Vec2d instances can be pickled.

__sub__(*args, **kwargs)

Overloaded function.

  1. __sub__(self: viren2d.Vec2d, rhs: int) -> viren2d.Vec2d

Element-wise subtraction: Vec2d = Vec2d - int.

  1. __sub__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise subtraction: Vec2d = Vec2d - Vec2d.

  1. __sub__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise subtraction: Vec2d = Vec2d - Vec2d.

  1. __sub__(self: viren2d.Vec2d, rhs: float) -> viren2d.Vec2d

Element-wise subtraction: Vec2d = Vec2d - float.

__truediv__(*args, **kwargs)

Overloaded function.

  1. __truediv__(self: viren2d.Vec2d, rhs: int) -> viren2d.Vec2d

Element-wise division: Vec2d = Vec2d / int.

  1. __truediv__(self: viren2d.Vec2d, rhs: float) -> viren2d.Vec2d

Element-wise division: Vec2d = Vec2d / float.

  1. __truediv__(self: viren2d.Vec2d, rhs: viren2d.Vec2d) -> viren2d.Vec2d

Element-wise division: Vec2d = Vec2d / Vec2d.

static all(value: float) viren2d.Vec2d

Creates a vector where each coordinate is set to the given scalar.

Corresponding C++ API: viren2d::Vec2d::All.

angle_deg(self: viren2d.Vec2d, other: viren2d.Vec2d) float

Computes the angle \(\in [0, 180]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec2d

Returns:

The angle \(\in [0, 180]\) in degrees.

angle_rad(self: viren2d.Vec2d, other: viren2d.Vec2d) float

Computes the angle \(\in [0, \pi]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec2d

Returns:

The angle \(\in [0, \pi]\) in radians.

as_float(self: viren2d.Vec2d) viren2d.Vec2d

Returns a copy of this vector as Vec2d

Corresponding C++ API: viren2d::Vec2d::ToDouble.

as_int(self: viren2d.Vec2d) werkzeugkiste::geometry::Vec<int, 2ul>

Returns a Vec2i as the result of explicitly casting/clipping the values.

Corresponding C++ API: viren2d::Vec2d::ToInteger.

copy(self: viren2d.Vec2d) viren2d.Vec2d

Returns a deep copy.

Corresponding C++ API: Copy constructor of viren2d::Vec2d.

direction_vector(self: viren2d.Vec2d, other: viren2d.Vec2d) viren2d.Vec2d

Returns the Vec2d direction vector, other - self.

distance_l1(self: viren2d.Vec2d, other: viren2d.Vec2d) float

Returns the Manhattan distance between self and the other Vec2d.

distance_l2(self: viren2d.Vec2d, other: viren2d.Vec2d) float

Returns the Euclidean distance between self and the other Vec2d.

dot(self: viren2d.Vec2d, other: viren2d.Vec2d) float

Returns the dot product of self and the other Vec2d.

property dtype

Underlying data type (read-only).

Type:

numpy.dtype

property height

Provides alternative read-write access to the second dimension, (i.e. y).

Can be useful if you want to use this 2D vector to represent a 2D size. This property is only available for 2-dimensional vectors.

Type:

float

homogeneous(self: viren2d.Vec2d) tuple

Returns the homogeneous representation of this vector, i.e. a 3-element tuple, where the additional dimension is set to 1.

length(self: viren2d.Vec2d) float

Returns the length of this vector.

Corresponding C++ API: viren2d::Vec2d::Length.

length_squared(self: viren2d.Vec2d) float

Returns this vector’s squared length.

max_index(self: viren2d.Vec2d) int

Returns \(i = \arg_i \max(v_i)\).

Corresponding C++ API: viren2d::Vec2d::MaxIndex.

max_value(self: viren2d.Vec2d) float

Returns \(\max(v_i)\).

Corresponding C++ API: viren2d::Vec2d::MaxValue.

min_index(self: viren2d.Vec2d) int

Returns \(i = \arg_i \min(v_i)\).

Corresponding C++ API: viren2d::Vec2d::MinIndex.

min_value(self: viren2d.Vec2d) float

Returns \(\min(v_i)\).

Corresponding C++ API: viren2d::Vec2d::MinValue.

property ndim

Number of dimensions (read-only), i.e. 2.

Type:

int

perpendicular_ccw(self: viren2d.Vec2d) viren2d.Vec2d

Returns the 90° counterclockwise rotated vector.

This method assumes that the coordinate system is right-handed and is only supported for 2D vectors.

perpendicular_cw(self: viren2d.Vec2d) viren2d.Vec2d

Returns the 90° clockwise rotated vector.

This method assumes that the coordinate system is right-handed and is only supported for 2D vectors.

rotate_deg(self: viren2d.Vec2d, angle: float, rotation_center: viren2d.Vec2d = viren2d.Vec2d(0, 0)) viren2d.Vec2d

Returns a copy of this vector rotated around the reference point by the given angle.

This method assumes that the coordinate system is right-handed and is only supported for 2D vector specialization with floating point value type.

Parameters:
  • angle – Rotation angle in degrees.

  • rotation_center – Reference point for rotation as Vec2d.

rotate_rad(self: viren2d.Vec2d, angle: viren2d.Vec2d, rotation_center: float = viren2d.Vec2d(0, 0)) viren2d.Vec2d

Returns a copy of this vector rotated around the reference point by the given angle.

This method assumes that the coordinate system is right-handed and is only supported for 2D vector specialization with floating point value type.

Parameters:
  • angle – Rotation angle in radians.

  • rotation_center – Reference point for rotation as Vec2d.

unit_vector(self: viren2d.Vec2d) viren2d.Vec2d

Returns the corresponding unit vector as Vec2d.

property width

Provides alternative read-write access to the first dimension, (i.e. x).

Can be useful if you want to use this 2D vector to represent a 2D size. This property is only available for 2-dimensional vectors.

Type:

float

property x

Read-write access to the first dimension, i.e. same as vec[0].

Type:

float

property y

Read-write access to the second dimension, i.e. same as vec[1].

Type:

float

Floating point 3D: Vec3d

class viren2d.Vec3d

A 3D vector of float coordinates.

Corresponding C++ API: viren2d::Vec3d.

Methods:

__add__

Overloaded function.

__eq__

Returns True if the two vectors are approximately equal.

__getitem__

Allows accessing this vector's values via vec[i].

__getstate__

__iadd__

Overloaded function.

__init__

Overloaded function.

__mul__

Overloaded function.

__ne__

Returns True if the two vectors are approximately equal.

__neg__

Returns a Vec3d, where all values are negated.

__rmul__

Overloaded function.

__setitem__

Allows accessing this vector's values via vec[idx].

__setstate__

Vec3d instances can be pickled.

__sub__

Overloaded function.

__truediv__

Overloaded function.

all

Creates a vector where each coordinate is set to the given scalar.

angle_deg

Computes the angle \(\in [0, 180]\) between this and the other vector.

angle_rad

Computes the angle \(\in [0, \pi]\) between this and the other vector.

as_float

Returns a copy of this vector as Vec3d

as_int

Returns a Vec3i as the result of explicitly casting/clipping the values.

copy

Returns a deep copy.

cross

Computes the cross product.

direction_vector

Returns the Vec3d direction vector, other - self.

distance_l1

Returns the Manhattan distance between self and the other Vec3d.

distance_l2

Returns the Euclidean distance between self and the other Vec3d.

dot

Returns the dot product of self and the other Vec3d.

homogeneous

Returns the homogeneous representation of this vector, i.e. a 4-element tuple, where the additional dimension is set to 1.

length

Returns the length of this vector.

length_squared

Returns this vector's squared length.

max_index

Returns \(i = \arg_i \max(v_i)\).

max_value

Returns \(\max(v_i)\).

min_index

Returns \(i = \arg_i \min(v_i)\).

min_value

Returns \(\min(v_i)\).

unit_vector

Returns the corresponding unit vector as Vec3d.

Attributes:

dtype

Underlying data type (read-only).

ndim

Number of dimensions (read-only), i.e. 3.

x

Read-write access to the first dimension, i.e. same as vec[0].

y

Read-write access to the second dimension, i.e. same as vec[1].

z

Read-write access to the third dimension, i.e. same as vec[2].

__add__(*args, **kwargs)

Overloaded function.

  1. __add__(self: viren2d.Vec3d, scalar: int) -> viren2d.Vec3d

Element-wise addition: Vec3d = Vec3d + int.

  1. __add__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise addition: Vec3d = Vec3d + Vec3d.

  1. __add__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise addition: Vec3d = Vec3d + Vec3d.

  1. __add__(self: viren2d.Vec3d, rhs: float) -> viren2d.Vec3d

Element-wise addition: Vec3d = Vec3d + float.

__eq__(self: viren2d.Vec3d, other: viren2d.Vec3d) bool

Returns True if the two vectors are approximately equal.

Uses a combined test with both relative and absolute tolerance. Modulo special cases (NaN, infinity), two vectors \(x = (x_i)_{i=1}^3\) and \(y = (y_i)_{i=1}^3\) are considered approximately equal if for all their values

\(|x_i - y_i| \leq \epsilon_{\text{rel}} * \max(|x_i|, |y_i|) \quad\text{or}\quad |x_i - y_i| \leq \epsilon_{\text{abs}}\),

where \(\epsilon_{\text{rel}} = 1e-9\) and \(\epsilon_{\text{abs}} = 1e-12\).

Corresponding C++ API: viren2d::Vec3d::operator== and ::IsClose

__getitem__(self: viren2d.Vec3d, arg0: int) float

Allows accessing this vector’s values via vec[i].

__getstate__(self: viren2d.Vec3d) tuple
__iadd__(*args, **kwargs)

Overloaded function.

  1. __iadd__(self: viren2d.Vec3d, rhs: int) -> viren2d.Vec3d

In-place element-wise addition: Vec3d += int.

  1. __iadd__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

In-place element-wise addition: Vec3d += Vec3d.

  1. __iadd__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

In-place element-wise addition: Vec3d += Vec3d.

  1. __iadd__(self: viren2d.Vec3d, rhs: float) -> viren2d.Vec3d

In-place element-wise addition: Vec3d += float.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: viren2d.Vec3d) -> None

Initializes all values to 0.

  1. __init__(self: viren2d.Vec3d, vec_int: werkzeugkiste::geometry::Vec<int, 3ul>) -> None

Creates a double-precision vector from its 32-bit integral counterpart.

  1. __init__(self: viren2d.Vec3d, vec: viren2d.Vec3d) -> None

Creates a copy of the given Vec3d.

  1. __init__(self: viren2d.Vec3d, tpl: tuple) -> None

Creates a vector from a 3-element tuple.

  1. __init__(self: viren2d.Vec3d, lst: list) -> None

Creates a vector from a 3-element list.

  1. __init__(self: viren2d.Vec3d, arr: numpy.ndarray) -> None

Creates a vector from a 3-element numpy.array.

  1. __init__(self: viren2d.Vec3d, x: float, y: float, z: float) -> None

Explicit initialization from 3 separate values.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: viren2d.Vec3d, rhs: int) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = Vec3d * int.

  1. __mul__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = Vec3d * Vec3d.

  1. __mul__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = Vec3d * Vec3d.

  1. __mul__(self: viren2d.Vec3d, rhs: float) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = Vec3d * float.

__ne__(self: viren2d.Vec3d, other: viren2d.Vec3d) bool

Returns True if the two vectors are approximately equal.

Uses a combined test with both relative and absolute tolerance. Modulo special cases (NaN, infinity), two vectors \(x = (x_i)_{i=1}^3\) and \(y = (y_i)_{i=1}^3\) are considered approximately equal if for all their values

\(|x_i - y_i| \leq \epsilon_{\text{rel}} * \max(|x_i|, |y_i|) \quad\text{or}\quad |x_i - y_i| \leq \epsilon_{\text{abs}}\),

where \(\epsilon_{\text{rel}} = 1e-9\) and \(\epsilon_{\text{abs}} = 1e-12\).

Corresponding C++ API: viren2d::Vec3d::operator== and ::IsClose``Returns ``True if the two vectors differ sufficiently.

As this operator computes !(vec1 == vec2), refer to __eq__() for details.

__neg__(self: viren2d.Vec3d) viren2d.Vec3d

Returns a Vec3d, where all values are negated.

__rmul__(*args, **kwargs)

Overloaded function.

  1. __rmul__(self: viren2d.Vec3d, lhs: int) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = int * Vec3d.

  1. __rmul__(self: viren2d.Vec3d, lhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = Vec3d * Vec3d.

  1. __rmul__(self: viren2d.Vec3d, lhs: float) -> viren2d.Vec3d

Element-wise multiplication: Vec3d = float * Vec3d.

__setitem__(self: viren2d.Vec3d, arg0: int, arg1: float) None

Allows accessing this vector’s values via vec[idx].

__setstate__(self: viren2d.Vec3d, arg0: tuple) None

Vec3d instances can be pickled.

__sub__(*args, **kwargs)

Overloaded function.

  1. __sub__(self: viren2d.Vec3d, rhs: int) -> viren2d.Vec3d

Element-wise subtraction: Vec3d = Vec3d - int.

  1. __sub__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise subtraction: Vec3d = Vec3d - Vec3d.

  1. __sub__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise subtraction: Vec3d = Vec3d - Vec3d.

  1. __sub__(self: viren2d.Vec3d, rhs: float) -> viren2d.Vec3d

Element-wise subtraction: Vec3d = Vec3d - float.

__truediv__(*args, **kwargs)

Overloaded function.

  1. __truediv__(self: viren2d.Vec3d, rhs: int) -> viren2d.Vec3d

Element-wise division: Vec3d = Vec3d / int.

  1. __truediv__(self: viren2d.Vec3d, rhs: float) -> viren2d.Vec3d

Element-wise division: Vec3d = Vec3d / float.

  1. __truediv__(self: viren2d.Vec3d, rhs: viren2d.Vec3d) -> viren2d.Vec3d

Element-wise division: Vec3d = Vec3d / Vec3d.

static all(value: float) viren2d.Vec3d

Creates a vector where each coordinate is set to the given scalar.

Corresponding C++ API: viren2d::Vec3d::All.

angle_deg(self: viren2d.Vec3d, other: viren2d.Vec3d) float

Computes the angle \(\in [0, 180]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec3d

Returns:

The angle \(\in [0, 180]\) in degrees.

angle_rad(self: viren2d.Vec3d, other: viren2d.Vec3d) float

Computes the angle \(\in [0, \pi]\) between this and the other vector.

Parameters:

other – The second viren2d.Vec3d

Returns:

The angle \(\in [0, \pi]\) in radians.

as_float(self: viren2d.Vec3d) viren2d.Vec3d

Returns a copy of this vector as Vec3d

Corresponding C++ API: viren2d::Vec3d::ToDouble.

as_int(self: viren2d.Vec3d) werkzeugkiste::geometry::Vec<int, 3ul>

Returns a Vec3i as the result of explicitly casting/clipping the values.

Corresponding C++ API: viren2d::Vec3d::ToInteger.

copy(self: viren2d.Vec3d) viren2d.Vec3d

Returns a deep copy.

Corresponding C++ API: Copy constructor of viren2d::Vec3d.

cross(self: viren2d.Vec3d, other: viren2d.Vec3d) viren2d.Vec3d

Computes the cross product.

direction_vector(self: viren2d.Vec3d, other: viren2d.Vec3d) viren2d.Vec3d

Returns the Vec3d direction vector, other - self.

distance_l1(self: viren2d.Vec3d, other: viren2d.Vec3d) float

Returns the Manhattan distance between self and the other Vec3d.

distance_l2(self: viren2d.Vec3d, other: viren2d.Vec3d) float

Returns the Euclidean distance between self and the other Vec3d.

dot(self: viren2d.Vec3d, other: viren2d.Vec3d) float

Returns the dot product of self and the other Vec3d.

property dtype

Underlying data type (read-only).

Type:

numpy.dtype

homogeneous(self: viren2d.Vec3d) tuple

Returns the homogeneous representation of this vector, i.e. a 4-element tuple, where the additional dimension is set to 1.

length(self: viren2d.Vec3d) float

Returns the length of this vector.

Corresponding C++ API: viren2d::Vec3d::Length.

length_squared(self: viren2d.Vec3d) float

Returns this vector’s squared length.

max_index(self: viren2d.Vec3d) int

Returns \(i = \arg_i \max(v_i)\).

Corresponding C++ API: viren2d::Vec3d::MaxIndex.

max_value(self: viren2d.Vec3d) float

Returns \(\max(v_i)\).

Corresponding C++ API: viren2d::Vec3d::MaxValue.

min_index(self: viren2d.Vec3d) int

Returns \(i = \arg_i \min(v_i)\).

Corresponding C++ API: viren2d::Vec3d::MinIndex.

min_value(self: viren2d.Vec3d) float

Returns \(\min(v_i)\).

Corresponding C++ API: viren2d::Vec3d::MinValue.

property ndim

Number of dimensions (read-only), i.e. 3.

Type:

int

unit_vector(self: viren2d.Vec3d) viren2d.Vec3d

Returns the corresponding unit vector as Vec3d.

property x

Read-write access to the first dimension, i.e. same as vec[0].

Type:

float

property y

Read-write access to the second dimension, i.e. same as vec[1].

Type:

float

property z

Read-write access to the third dimension, i.e. same as vec[2].

Type:

float