11.1. 模块 pySudoMath

pySudoMath module for basic math implementation

This module provides Python bindings for the SudoMath C++ library, which includes implementations of 2D and 3D vectors, 3x3 matrices, and quaternions. These mathematical objects are essential for various applications in physics simulations, computer graphics, and game development.

The module offers classes for vectors (Vector2i, Vector2f, Vector2r, Vector3i, Vector3f, Vector3r), matrices (Matrix3f, Matrix3r), and quaternions (Quaternionr, Quaterniond) with different scalar types (int, float, double) to suit various precision and performance needs.

class pySudoMath.Matrix3f
__init__(self: pySudoMath.Matrix3f) None

Create a 3x3 identity matrix.

determinant(self: pySudoMath.Matrix3f) float

Calculate the determinant of the matrix.

inverse(self: pySudoMath.Matrix3f) pySudoMath.Matrix3f

Calculate the inverse of the matrix.

property row0

The first row of the matrix.

property row1

The second row of the matrix.

property row2

The third row of the matrix.

transpose(self: pySudoMath.Matrix3f) pySudoMath.Matrix3f

Calculate the transpose of the matrix.

class pySudoMath.Matrix3r
__init__(self: pySudoMath.Matrix3r) None

Create a 3x3 identity matrix.

determinant(self: pySudoMath.Matrix3r) float

Calculate the determinant of the matrix.

inverse(self: pySudoMath.Matrix3r) pySudoMath.Matrix3r

Calculate the inverse of the matrix.

property row0

The first row of the matrix.

property row1

The second row of the matrix.

property row2

The third row of the matrix.

transpose(self: pySudoMath.Matrix3r) pySudoMath.Matrix3r

Calculate the transpose of the matrix.

class pySudoMath.Quaterniond

A class representing a quaternion (w, x, y, z) with double components.

Quaternions are used to represent rotations in 3D space. They offer advantages over other representations like Euler angles (e.g., no gimbal lock) and rotation matrices (e.g., more compact, efficient interpolation).

This class provides methods for common quaternion operations such as normalization, inversion, conjugation, and conversion to rotation matrices. It also supports quaternion multiplication and rotation of 3D vectors.

Example:

# Create a quaternion from individual components q = Quaterniond(1.0, 0.0, 0.0, 0.0) # Identity quaternion

# Create a quaternion from scalar and vector parts v = Vector3r(1.0, 2.0, 3.0) q = Quaterniond(2.0, v)

# Create a quaternion from angle and axis axis = Vector3r(0.0, 0.0, 1.0) # Z-axis angle = 3.14159 / 2 # 90 degrees in radians q = Quaterniond.from_angle_axis(angle, axis)

# Access components print(q.w, q.x, q.y, q.z)

# Normalize the quaternion q.normalize()

# Convert to rotation matrix matrix = q.to_rotation_matrix()

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Quaterniond) -> None

  2. __init__(self: pySudoMath.Quaterniond, w: typing.SupportsFloat, x: typing.SupportsFloat, y: typing.SupportsFloat, z: typing.SupportsFloat) -> None

Create a quaternion from four double components (w, x, y, z).

Parameters:

w (double): The scalar (real) part of the quaternion. x (double): The x-component of the vector (imaginary) part. y (double): The y-component of the vector (imaginary) part. z (double): The z-component of the vector (imaginary) part.

Example:

q = Quaterniond(1.0, 0.0, 0.0, 0.0) # Identity quaternion q = Quaterniond(0.707, 0.0, 0.0, 0.707) # 90-degree rotation around Z-axis

  1. __init__(self: pySudoMath.Quaterniond, w: typing.SupportsFloat, v: pySudoMath.Vector3r) -> None

Create a double scalar part and a 3D vector part.

Parameters:

w (double): The scalar (real) part of the quaternion. v (Quaterniond): A 3D vector representing the vector (imaginary) part.

Example:

v = Vector3r(1.0, 2.0, 3.0) q = Quaterniond(2.0, v) # Creates quaternion with w=2.0, x=1.0, y=2.0, z=3.0

conjugate(self: pySudoMath.Quaterniond) pySudoMath.Quaterniond

Return the conjugate of the quaternion.

The conjugate of a quaternion (w, x, y, z) is (w, -x, -y, -z).

Returns:

Quaternion<double>: A new quaternion representing the conjugate.

Example:

q = Quaterniond(1.0, 2.0, 3.0, 4.0) q_conj = q.conjugate() # Returns Quaterniond(1.0, -2.0, -3.0, -4.0)

static from_angle_axis(angle: SupportsFloat, axis: pySudoMath.Vector3r) pySudoMath.Quaterniond

Create a double angle (in radians) and an axis of rotation.

This constructor creates a unit quaternion representing a rotation of 'angle' radians around the specified 'axis'.

Parameters:

angle (double): The angle of rotation in radians. axis (Quaterniond): The unit vector representing the axis of rotation.

Example:

axis = Vector3r(0.0, 0.0, 1.0) # Z-axis angle = 3.14159 / 2 # 90 degrees in radians q = Quaterniond.from_angle_axis(angle, axis)

inverse(self: pySudoMath.Quaterniond) pySudoMath.Quaterniond

Return the inverse of the quaternion.

The inverse is the conjugate divided by the norm squared. For a unit quaternion, the inverse is the same as the conjugate.

Returns:

Quaternion<double>: A new quaternion representing the inverse.

Example:

q = Quaterniond(1.0, 0.0, 0.0, 0.0) # Unit quaternion q_inv = q.inverse() # Same as conjugate for unit quaternions

norm(self: pySudoMath.Quaterniond) float

Calculate the squared norm (magnitude squared) of the quaternion.

Returns:

double: The squared norm (w*w + x*x + y*y + z*z).

Example:

q = Quaterniond(1.0, 2.0, 3.0, 4.0) n = q.norm() # Returns 1*1 + 2*2 + 3*3 + 4*4 = 30.0

normalize(self: pySudoMath.Quaterniond) None

Normalize the quaternion in-place.

This modifies the quaternion so that its norm becomes 1.0. This is often necessary for unit quaternions representing rotations.

Example:

q = Quaterniond(1.0, 2.0, 3.0, 4.0) q.normalize() # Modifies q in-place to have unit norm

to_rotation_matrix(self: pySudoMath.Quaterniond) pySudoMath.Matrix3r

Convert the quaternion to a 3x3 rotation matrix.

Returns:

matrix3<double>: A 3x3 matrix representing the same rotation.

Example:

q = Quaterniond.from_angle_axis(3.14159/2, Vector3r(0.0, 0.0, 1.0)) matrix = q.to_rotation_matrix() # 90-degree rotation matrix around Z-axis

property w

The scalar (real) part of the quaternion.

property x

The x-component of the vector (imaginary) part.

property y

The y-component of the vector (imaginary) part.

property z

The z-component of the vector (imaginary) part.

class pySudoMath.Quaternionr

A class representing a quaternion (w, x, y, z) with float components.

Quaternions are used to represent rotations in 3D space. They offer advantages over other representations like Euler angles (e.g., no gimbal lock) and rotation matrices (e.g., more compact, efficient interpolation).

This class provides methods for common quaternion operations such as normalization, inversion, conjugation, and conversion to rotation matrices. It also supports quaternion multiplication and rotation of 3D vectors.

Example:

# Create a quaternion from individual components q = Quaternionr(1.0, 0.0, 0.0, 0.0) # Identity quaternion

# Create a quaternion from scalar and vector parts v = Vector3f(1.0, 2.0, 3.0) q = Quaternionr(2.0, v)

# Create a quaternion from angle and axis axis = Vector3f(0.0, 0.0, 1.0) # Z-axis angle = 3.14159 / 2 # 90 degrees in radians q = Quaternionr.from_angle_axis(angle, axis)

# Access components print(q.w, q.x, q.y, q.z)

# Normalize the quaternion q.normalize()

# Convert to rotation matrix matrix = q.to_rotation_matrix()

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Quaternionr) -> None

  2. __init__(self: pySudoMath.Quaternionr, w: typing.SupportsFloat, x: typing.SupportsFloat, y: typing.SupportsFloat, z: typing.SupportsFloat) -> None

Create a quaternion from four float components (w, x, y, z).

Parameters:

w (float): The scalar (real) part of the quaternion. x (float): The x-component of the vector (imaginary) part. y (float): The y-component of the vector (imaginary) part. z (float): The z-component of the vector (imaginary) part.

Example:

q = Quaternionr(1.0, 0.0, 0.0, 0.0) # Identity quaternion q = Quaternionr(0.707, 0.0, 0.0, 0.707) # 90-degree rotation around Z-axis

  1. __init__(self: pySudoMath.Quaternionr, w: typing.SupportsFloat, v: pySudoMath.Vector3f) -> None

Create a float scalar part and a 3D vector part.

Parameters:

w (float): The scalar (real) part of the quaternion. v (Quaternionr): A 3D vector representing the vector (imaginary) part.

Example:

v = Vector3f(1.0, 2.0, 3.0) q = Quaternionr(2.0, v) # Creates quaternion with w=2.0, x=1.0, y=2.0, z=3.0

conjugate(self: pySudoMath.Quaternionr) pySudoMath.Quaternionr

Return the conjugate of the quaternion.

The conjugate of a quaternion (w, x, y, z) is (w, -x, -y, -z).

Returns:

Quaternion<float>: A new quaternion representing the conjugate.

Example:

q = Quaternionr(1.0, 2.0, 3.0, 4.0) q_conj = q.conjugate() # Returns Quaternionr(1.0, -2.0, -3.0, -4.0)

static from_angle_axis(angle: SupportsFloat, axis: pySudoMath.Vector3f) pySudoMath.Quaternionr

Create a float angle (in radians) and an axis of rotation.

This constructor creates a unit quaternion representing a rotation of 'angle' radians around the specified 'axis'.

Parameters:

angle (float): The angle of rotation in radians. axis (Quaternionr): The unit vector representing the axis of rotation.

Example:

axis = Vector3f(0.0, 0.0, 1.0) # Z-axis angle = 3.14159 / 2 # 90 degrees in radians q = Quaternionr.from_angle_axis(angle, axis)

inverse(self: pySudoMath.Quaternionr) pySudoMath.Quaternionr

Return the inverse of the quaternion.

The inverse is the conjugate divided by the norm squared. For a unit quaternion, the inverse is the same as the conjugate.

Returns:

Quaternion<float>: A new quaternion representing the inverse.

Example:

q = Quaternionr(1.0, 0.0, 0.0, 0.0) # Unit quaternion q_inv = q.inverse() # Same as conjugate for unit quaternions

norm(self: pySudoMath.Quaternionr) float

Calculate the squared norm (magnitude squared) of the quaternion.

Returns:

float: The squared norm (w*w + x*x + y*y + z*z).

Example:

q = Quaternionr(1.0, 2.0, 3.0, 4.0) n = q.norm() # Returns 1*1 + 2*2 + 3*3 + 4*4 = 30.0

normalize(self: pySudoMath.Quaternionr) None

Normalize the quaternion in-place.

This modifies the quaternion so that its norm becomes 1.0. This is often necessary for unit quaternions representing rotations.

Example:

q = Quaternionr(1.0, 2.0, 3.0, 4.0) q.normalize() # Modifies q in-place to have unit norm

to_rotation_matrix(self: pySudoMath.Quaternionr) pySudoMath.Matrix3f

Convert the quaternion to a 3x3 rotation matrix.

Returns:

matrix3<float>: A 3x3 matrix representing the same rotation.

Example:

q = Quaternionr.from_angle_axis(3.14159/2, Vector3f(0.0, 0.0, 1.0)) matrix = q.to_rotation_matrix() # 90-degree rotation matrix around Z-axis

property w

The scalar (real) part of the quaternion.

property x

The x-component of the vector (imaginary) part.

property y

The y-component of the vector (imaginary) part.

property z

The z-component of the vector (imaginary) part.

class pySudoMath.Vector2f

A class representing a 2D vector (x, y) with float components.

This class provides methods for common 2D vector operations such as addition, subtraction, scalar multiplication, dot product, and the 2D "cross product" (perp dot product).

Example:

# Create a vector with both components set to the same value v = Vector2f(1.0)

# Create a vector from individual components v = Vector2f(1.0, 2.0)

# Vector operations v1 = Vector2f(1.0, 2.0) v2 = Vector2f(3.0, 4.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) # 2D cross product v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector2f, value: typing.SupportsFloat) -> None

Create a 2D vector with both components set to the same float value.

Parameters:

value (float): The value for x and y components.

Example:

v = Vector2f(1.0) # Creates vector (1.0, 1.0)

  1. __init__(self: pySudoMath.Vector2f, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None

Create a 2D vector from individual x and y float components.

Parameters:

x (float): The x-component of the vector. y (float): The y-component of the vector.

Example:

v = Vector2f(1.0, 2.0) # Creates vector (1.0, 2.0)

cross(self: pySudoMath.Vector2f, other: pySudoMath.Vector2f) float

Calculate the 2D "cross product" (perp dot product) with another vector.

This is equivalent to dot(perp(), other) where perp() is (-y, x).

Parameters:

other (Vector2f): The other vector.

Returns:

float: The perp dot product (this.x*other.y - this.y*other.x).

Example:

v1 = Vector2f(1.0, 0.0) v2 = Vector2f(0.0, 1.0) cross_product = v1.cross(v2) # Returns 1*1 - 0*0 = 1.0

dot(self: pySudoMath.Vector2f, other: pySudoMath.Vector2f) float

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector2f): The other vector.

Returns:

float: The dot product (this.x*other.x + this.y*other.y).

Example:

v1 = Vector2f(1.0, 2.0) v2 = Vector2f(3.0, 4.0) dot_product = v1.dot(v2) # Returns 1*3 + 2*4 = 11.0

norm(self: pySudoMath.Vector2f) float

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

float: The norm (sqrt(x*x + y*y)).

Example:

v = Vector2f(3.0, 4.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector2f) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector2f(3.0, 4.0) v.normalize() # v is now Vector2f(0.6, 0.8)

normalized(self: pySudoMath.Vector2f) pySudoMath.Vector2f

Return a normalized copy of the vector.

Returns:
Vector2f: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector2f(3.0, 4.0) v2 = v.normalized() # Returns Vector2f(0.6, 0.8)

# v is unchanged

squared_norm(self: pySudoMath.Vector2f) float

Calculate the squared norm (magnitude squared) of the vector.

Returns:

float: The squared norm (x*x + y*y).

Example:

v = Vector2f(3.0, 4.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 = 9 + 16 = 25)

class pySudoMath.Vector2i

A class representing a 2D vector (x, y) with int components.

This class provides methods for common 2D vector operations such as addition, subtraction, scalar multiplication, dot product, and the 2D "cross product" (perp dot product).

Example:

# Create a vector with both components set to the same value v = Vector2i(1.0)

# Create a vector from individual components v = Vector2i(1.0, 2.0)

# Vector operations v1 = Vector2i(1.0, 2.0) v2 = Vector2i(3.0, 4.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) # 2D cross product v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector2i, value: typing.SupportsInt) -> None

Create a 2D vector with both components set to the same int value.

Parameters:

value (int): The value for x and y components.

Example:

v = Vector2i(1.0) # Creates vector (1.0, 1.0)

  1. __init__(self: pySudoMath.Vector2i, x: typing.SupportsInt, y: typing.SupportsInt) -> None

Create a 2D vector from individual x and y int components.

Parameters:

x (int): The x-component of the vector. y (int): The y-component of the vector.

Example:

v = Vector2i(1.0, 2.0) # Creates vector (1.0, 2.0)

cross(self: pySudoMath.Vector2i, other: pySudoMath.Vector2i) int

Calculate the 2D "cross product" (perp dot product) with another vector.

This is equivalent to dot(perp(), other) where perp() is (-y, x).

Parameters:

other (Vector2i): The other vector.

Returns:

int: The perp dot product (this.x*other.y - this.y*other.x).

Example:

v1 = Vector2i(1.0, 0.0) v2 = Vector2i(0.0, 1.0) cross_product = v1.cross(v2) # Returns 1*1 - 0*0 = 1.0

dot(self: pySudoMath.Vector2i, other: pySudoMath.Vector2i) int

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector2i): The other vector.

Returns:

int: The dot product (this.x*other.x + this.y*other.y).

Example:

v1 = Vector2i(1.0, 2.0) v2 = Vector2i(3.0, 4.0) dot_product = v1.dot(v2) # Returns 1*3 + 2*4 = 11.0

norm(self: pySudoMath.Vector2i) int

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

int: The norm (sqrt(x*x + y*y)).

Example:

v = Vector2i(3.0, 4.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector2i) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector2i(3.0, 4.0) v.normalize() # v is now Vector2i(0.6, 0.8)

normalized(self: pySudoMath.Vector2i) pySudoMath.Vector2i

Return a normalized copy of the vector.

Returns:
Vector2i: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector2i(3.0, 4.0) v2 = v.normalized() # Returns Vector2i(0.6, 0.8)

# v is unchanged

squared_norm(self: pySudoMath.Vector2i) int

Calculate the squared norm (magnitude squared) of the vector.

Returns:

int: The squared norm (x*x + y*y).

Example:

v = Vector2i(3.0, 4.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 = 9 + 16 = 25)

class pySudoMath.Vector2r

A class representing a 2D vector (x, y) with double components.

This class provides methods for common 2D vector operations such as addition, subtraction, scalar multiplication, dot product, and the 2D "cross product" (perp dot product).

Example:

# Create a vector with both components set to the same value v = Vector2r(1.0)

# Create a vector from individual components v = Vector2r(1.0, 2.0)

# Vector operations v1 = Vector2r(1.0, 2.0) v2 = Vector2r(3.0, 4.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) # 2D cross product v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector2r, value: typing.SupportsFloat) -> None

Create a 2D vector with both components set to the same double value.

Parameters:

value (double): The value for x and y components.

Example:

v = Vector2r(1.0) # Creates vector (1.0, 1.0)

  1. __init__(self: pySudoMath.Vector2r, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None

Create a 2D vector from individual x and y double components.

Parameters:

x (double): The x-component of the vector. y (double): The y-component of the vector.

Example:

v = Vector2r(1.0, 2.0) # Creates vector (1.0, 2.0)

cross(self: pySudoMath.Vector2r, other: pySudoMath.Vector2r) float

Calculate the 2D "cross product" (perp dot product) with another vector.

This is equivalent to dot(perp(), other) where perp() is (-y, x).

Parameters:

other (Vector2r): The other vector.

Returns:

double: The perp dot product (this.x*other.y - this.y*other.x).

Example:

v1 = Vector2r(1.0, 0.0) v2 = Vector2r(0.0, 1.0) cross_product = v1.cross(v2) # Returns 1*1 - 0*0 = 1.0

dot(self: pySudoMath.Vector2r, other: pySudoMath.Vector2r) float

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector2r): The other vector.

Returns:

double: The dot product (this.x*other.x + this.y*other.y).

Example:

v1 = Vector2r(1.0, 2.0) v2 = Vector2r(3.0, 4.0) dot_product = v1.dot(v2) # Returns 1*3 + 2*4 = 11.0

norm(self: pySudoMath.Vector2r) float

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

double: The norm (sqrt(x*x + y*y)).

Example:

v = Vector2r(3.0, 4.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector2r) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector2r(3.0, 4.0) v.normalize() # v is now Vector2r(0.6, 0.8)

normalized(self: pySudoMath.Vector2r) pySudoMath.Vector2r

Return a normalized copy of the vector.

Returns:
Vector2r: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector2r(3.0, 4.0) v2 = v.normalized() # Returns Vector2r(0.6, 0.8)

# v is unchanged

squared_norm(self: pySudoMath.Vector2r) float

Calculate the squared norm (magnitude squared) of the vector.

Returns:

double: The squared norm (x*x + y*y).

Example:

v = Vector2r(3.0, 4.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 = 9 + 16 = 25)

class pySudoMath.Vector3f

A class representing a 3D vector (x, y, z) with float components.

This class provides methods for common 3D vector operations such as addition, subtraction, scalar multiplication, dot product, cross product, and normalization.

Example:

# Create a vector with all components set to the same value v = Vector3f(1.0)

# Create a vector from individual components v = Vector3f(1.0, 2.0, 3.0)

# Vector operations v1 = Vector3f(1.0, 2.0, 3.0) v2 = Vector3f(4.0, 5.0, 6.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector3f, value: typing.SupportsFloat) -> None

Create a 3D vector with all components set to the same float value.

Parameters:

value (float): The value for x, y, and z components.

Example:

v = Vector3f(1.0) # Creates vector (1.0, 1.0, 1.0)

  1. __init__(self: pySudoMath.Vector3f, x: typing.SupportsFloat, y: typing.SupportsFloat, z: typing.SupportsFloat) -> None

Create a 3D vector from individual x, y, and z float components.

Parameters:

x (float): The x-component of the vector. y (float): The y-component of the vector. z (float): The z-component of the vector.

Example:

v = Vector3f(1.0, 2.0, 3.0) # Creates vector (1.0, 2.0, 3.0)

cross(self: pySudoMath.Vector3f, other: pySudoMath.Vector3f) pySudoMath.Vector3f

Calculate the cross product of this vector with another vector.

Parameters:

other (Vector3f): The other vector.

Returns:

Vector3f: A new vector representing the cross product.

Example:

v1 = Vector3f(1.0, 0.0, 0.0) # X-axis v2 = Vector3f(0.0, 1.0, 0.0) # Y-axis cross_product = v1.cross(v2) # Returns (0.0, 0.0, 1.0) - Z-axis

dot(self: pySudoMath.Vector3f, other: pySudoMath.Vector3f) float

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector3f): The other vector.

Returns:

float: The dot product (this.x*other.x + this.y*other.y + this.z*other.z).

Example:

v1 = Vector3f(1.0, 2.0, 3.0) v2 = Vector3f(4.0, 5.0, 6.0) dot_product = v1.dot(v2) # Returns 1*4 + 2*5 + 3*6 = 32.0

norm(self: pySudoMath.Vector3f) float

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

float: The norm (sqrt(x*x + y*y + z*z)).

Example:

v = Vector3f(3.0, 4.0, 0.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4 + 0*0) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector3f) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector3f(3.0, 4.0, 0.0) v.normalize() # v is now Vector3f(0.6, 0.8, 0.0)

normalized(self: pySudoMath.Vector3f) pySudoMath.Vector3f

Return a normalized copy of the vector.

Returns:
Vector3f: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector3f(3.0, 4.0, 0.0) v2 = v.normalized() # Returns Vector3f(0.6, 0.8, 0.0)

# v is unchanged

squared_norm(self: pySudoMath.Vector3f) float

Calculate the squared norm (magnitude squared) of the vector.

Returns:

float: The squared norm (x*x + y*y + z*z).

Example:

v = Vector3f(3.0, 4.0, 0.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 + 0*0 = 9 + 16 + 0 = 25)

class pySudoMath.Vector3i

A class representing a 3D vector (x, y, z) with int components.

This class provides methods for common 3D vector operations such as addition, subtraction, scalar multiplication, dot product, cross product, and normalization.

Example:

# Create a vector with all components set to the same value v = Vector3i(1.0)

# Create a vector from individual components v = Vector3i(1.0, 2.0, 3.0)

# Vector operations v1 = Vector3i(1.0, 2.0, 3.0) v2 = Vector3i(4.0, 5.0, 6.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector3i, value: typing.SupportsInt) -> None

Create a 3D vector with all components set to the same int value.

Parameters:

value (int): The value for x, y, and z components.

Example:

v = Vector3i(1.0) # Creates vector (1.0, 1.0, 1.0)

  1. __init__(self: pySudoMath.Vector3i, x: typing.SupportsInt, y: typing.SupportsInt, z: typing.SupportsInt) -> None

Create a 3D vector from individual x, y, and z int components.

Parameters:

x (int): The x-component of the vector. y (int): The y-component of the vector. z (int): The z-component of the vector.

Example:

v = Vector3i(1.0, 2.0, 3.0) # Creates vector (1.0, 2.0, 3.0)

cross(self: pySudoMath.Vector3i, other: pySudoMath.Vector3i) pySudoMath.Vector3i

Calculate the cross product of this vector with another vector.

Parameters:

other (Vector3i): The other vector.

Returns:

Vector3i: A new vector representing the cross product.

Example:

v1 = Vector3i(1.0, 0.0, 0.0) # X-axis v2 = Vector3i(0.0, 1.0, 0.0) # Y-axis cross_product = v1.cross(v2) # Returns (0.0, 0.0, 1.0) - Z-axis

dot(self: pySudoMath.Vector3i, other: pySudoMath.Vector3i) int

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector3i): The other vector.

Returns:

int: The dot product (this.x*other.x + this.y*other.y + this.z*other.z).

Example:

v1 = Vector3i(1.0, 2.0, 3.0) v2 = Vector3i(4.0, 5.0, 6.0) dot_product = v1.dot(v2) # Returns 1*4 + 2*5 + 3*6 = 32.0

norm(self: pySudoMath.Vector3i) int

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

int: The norm (sqrt(x*x + y*y + z*z)).

Example:

v = Vector3i(3.0, 4.0, 0.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4 + 0*0) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector3i) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector3i(3.0, 4.0, 0.0) v.normalize() # v is now Vector3i(0.6, 0.8, 0.0)

normalized(self: pySudoMath.Vector3i) pySudoMath.Vector3i

Return a normalized copy of the vector.

Returns:
Vector3i: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector3i(3.0, 4.0, 0.0) v2 = v.normalized() # Returns Vector3i(0.6, 0.8, 0.0)

# v is unchanged

squared_norm(self: pySudoMath.Vector3i) int

Calculate the squared norm (magnitude squared) of the vector.

Returns:

int: The squared norm (x*x + y*y + z*z).

Example:

v = Vector3i(3.0, 4.0, 0.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 + 0*0 = 9 + 16 + 0 = 25)

class pySudoMath.Vector3r

A class representing a 3D vector (x, y, z) with double components.

This class provides methods for common 3D vector operations such as addition, subtraction, scalar multiplication, dot product, cross product, and normalization.

Example:

# Create a vector with all components set to the same value v = Vector3r(1.0)

# Create a vector from individual components v = Vector3r(1.0, 2.0, 3.0)

# Vector operations v1 = Vector3r(1.0, 2.0, 3.0) v2 = Vector3r(4.0, 5.0, 6.0) v3 = v1 + v2 dot_product = v1.dot(v2) cross_product = v1.cross(v2) v1.normalize() # Normalize in-place

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pySudoMath.Vector3r, value: typing.SupportsFloat) -> None

Create a 3D vector with all components set to the same double value.

Parameters:

value (double): The value for x, y, and z components.

Example:

v = Vector3r(1.0) # Creates vector (1.0, 1.0, 1.0)

  1. __init__(self: pySudoMath.Vector3r, x: typing.SupportsFloat, y: typing.SupportsFloat, z: typing.SupportsFloat) -> None

Create a 3D vector from individual x, y, and z double components.

Parameters:

x (double): The x-component of the vector. y (double): The y-component of the vector. z (double): The z-component of the vector.

Example:

v = Vector3r(1.0, 2.0, 3.0) # Creates vector (1.0, 2.0, 3.0)

cross(self: pySudoMath.Vector3r, other: pySudoMath.Vector3r) pySudoMath.Vector3r

Calculate the cross product of this vector with another vector.

Parameters:

other (Vector3r): The other vector.

Returns:

Vector3r: A new vector representing the cross product.

Example:

v1 = Vector3r(1.0, 0.0, 0.0) # X-axis v2 = Vector3r(0.0, 1.0, 0.0) # Y-axis cross_product = v1.cross(v2) # Returns (0.0, 0.0, 1.0) - Z-axis

dot(self: pySudoMath.Vector3r, other: pySudoMath.Vector3r) float

Calculate the dot product of this vector with another vector.

Parameters:

other (Vector3r): The other vector.

Returns:

double: The dot product (this.x*other.x + this.y*other.y + this.z*other.z).

Example:

v1 = Vector3r(1.0, 2.0, 3.0) v2 = Vector3r(4.0, 5.0, 6.0) dot_product = v1.dot(v2) # Returns 1*4 + 2*5 + 3*6 = 32.0

norm(self: pySudoMath.Vector3r) float

Calculate the Euclidean norm (magnitude) of the vector.

Returns:

double: The norm (sqrt(x*x + y*y + z*z)).

Example:

v = Vector3r(3.0, 4.0, 0.0) n = v.norm() # Returns 5.0 (sqrt(3*3 + 4*4 + 0*0) = sqrt(25) = 5)

normalize(self: pySudoMath.Vector3r) None

Normalize the vector in-place.

This modifies the vector so that its norm becomes 1.0. If the vector is zero, it remains unchanged.

Example:

v = Vector3r(3.0, 4.0, 0.0) v.normalize() # v is now Vector3r(0.6, 0.8, 0.0)

normalized(self: pySudoMath.Vector3r) pySudoMath.Vector3r

Return a normalized copy of the vector.

Returns:
Vector3r: A new vector with the same direction but unit norm.

If this vector is zero, the zero vector is returned.

Example:

v = Vector3r(3.0, 4.0, 0.0) v2 = v.normalized() # Returns Vector3r(0.6, 0.8, 0.0)

# v is unchanged

squared_norm(self: pySudoMath.Vector3r) float

Calculate the squared norm (magnitude squared) of the vector.

Returns:

double: The squared norm (x*x + y*y + z*z).

Example:

v = Vector3r(3.0, 4.0, 0.0) n = v.squared_norm() # Returns 25.0 (3*3 + 4*4 + 0*0 = 9 + 16 + 0 = 25)

class pySudoMath.test
__init__(self: pySudoMath.test) None

Create a new test object.

Example:

t = test()

list_to_vec_quaternion(self: pySudoMath.test, arg0: collections.abc.Sequence[pySudoMath.Quaternionr]) None

Convert a list of Quaternionr objects to a C++ vector of Quaternion<float> and print them.

Parameters:

list: A list of Quaternionr objects.

Example:

t = test() quaternions = [Quaternionr(1.0, 0.0, 0.0, 0.0), Quaternionr(0.0, 1.0, 0.0, 0.0)] t.list_to_vec_quaternion(quaternions)

list_to_vec_vec3(self: pySudoMath.test, arg0: collections.abc.Sequence[pySudoMath.Vector3f]) None

Convert a list of Vector3f objects to a C++ vector of vec3<float> and print them.

Parameters:

list: A list of Vector3f objects.

Example:

t = test() vectors = [Vector3f(1.0, 2.0, 3.0), Vector3f(4.0, 5.0, 6.0)] t.list_to_vec_vec3(vectors)