geometry
Geometric operations: bounding boxes, rotations, point transforms, vertex normals, and spherical sampling.
Functions:
-
axis_aligned_bounding_box–Compute the axis aligned bounding box of a set of points,
-
transform_points–Transform points using a \(4 \times 4\) transformation matrix.
-
rotate–Apply a rotation matrix to a 3D tensor.
-
cross_product_matrix–Constructs a skew-symmetric matrix (also known as a cross-product matrix)
-
rodrigues_rotation_matrix–Computes a 3D rotation matrix using Rodrigues' rotation formula.
-
vertex_normals–Compute the vertex normal of a mesh.
-
random_spherical_points–Generate random points inside a sphere or a spherical shell based on radius limits.
-
spherical_points_gradient–Creation of kernel points via optimization of potentials for a single kernel.
-
spherical_points_lloyd–Generate kernel points using Lloyd's algorithm on a sphere.
axis_aligned_bounding_box
¶
Compute the axis aligned bounding box of a set of points, parameterized by \((c_x, c_y, c_z)\) and \((d_x, d_y, d_z)\) where \((c_x, c_y, c_z)\) is the center point of the box, and \(d_x\) is the x-axis length of the box.
Parameters:
-
pos(Tensor) –Points of shape \((N, 3)\), in XYZ order.
Returns:
-
Tensor–The axis aligned bounding box of shape \((6,)\).
transform_points
¶
Transform points using a \(4 \times 4\) transformation matrix.
This function applies a \(4 \times 4\) transformation matrix to a set of points. The transformation matrix is assumed to be in the form:
Where \(R\) is a \(3 \times 3\) rotation matrix and \(t\) is a \(3 \times 1\) translation vector.
Parameters:
-
points(Tensor) –Points of shape \((N, 3)\), in XYZ order.
-
transform(Tensor) –A \(4 \times 4\) transformation matrix.
Returns:
-
Tensor–The transformed points of shape \((N, 3)\).
Examples:
rotate
¶
Apply a rotation matrix to a 3D tensor.
Parameters:
-
x(Tensor) –Input tensor of shape \((\ldots, 3)\).
-
R(Tensor) –Rotation matrix of shape \((3, 3)\).
Returns:
-
Tensor–Rotated tensor with the same shape as
x.
cross_product_matrix
¶
Constructs a skew-symmetric matrix (also known as a cross-product matrix) for a given 3D vector \(k = [k_1, k_2, k_3]\). The function returns a \(3 \times 3\) skew-symmetric matrix \(M(k)\) of the form:
Parameters:
-
k(Tensor) –A tensor of shape \((3,)\) representing the 3D vector.
Returns:
-
Tensor–A \(3 \times 3\) skew-symmetric matrix corresponding to the cross-product operation.
Examples:
rodrigues_rotation_matrix
¶
Computes a 3D rotation matrix using Rodrigues' rotation formula.
This function rotates a vector in 3D space around a specified axis by a given angle in radians. The rotation matrix is computed using:
Where:
- \(I\) is the identity matrix.
- \(K\) is the skew-symmetric matrix (cross-product matrix) derived from the axis of rotation.
- \(\theta\) is the rotation angle in radians.
Parameters:
-
axis(Tensor) –A 3D vector representing the axis of rotation.
-
theta(float) –The angle of rotation in radians. Pass
math.radians(deg)to convert from degrees.
Returns:
-
Tensor–A \(3 \times 3\) rotation matrix that rotates a vector around the specified axis by the specified angle.
Raises:
-
Warning–If \(\theta > 2\pi\), which likely indicates degrees were passed instead of radians.
vertex_normals
¶
Compute the vertex normal of a mesh.
Parameters:
-
vertices(Tensor) –The vertices of the mesh. Shape: \((V, 3)\).
-
face(Tensor) –The face of the mesh. Shape: \((F, 3)\).
Returns:
-
Tensor–The vertex normal of the mesh. Shape: \((V, 3)\).
Examples:
random_spherical_points
¶
random_spherical_points(
radius: float,
num_points: int,
bounds: Union[float, Tuple[float, float]] = 1.0,
) -> Tensor
Generate random points inside a sphere or a spherical shell based on radius limits.
Parameters:
-
radius(float) –The radius of the sphere.
-
num_points(int) –The number of points to generate.
-
bounds(Union[float, Tuple[float, float]], default:1.0) –A float or tuple of floats defining the inner and outer bounds of the sphere. If a single float is provided, it is treated as the outer limit, with the inner limit as 0. Defaults to 1.0.
Returns:
-
Tensor–Generated points of shape (num_points, dimension).
spherical_points_gradient
¶
spherical_points_gradient(
radius: float,
num_points: int,
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
ratio: float = 0.66,
max_steps: int = 10000,
step_size: float = 0.01,
step_decay: float = 0.9995,
convergence_threshold: float = 1e-05,
max_step_size: Optional[float] = None,
return_grad_norms: Literal[False] = False,
) -> Tensor
spherical_points_gradient(
radius: float,
num_points: int,
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
ratio: float = 0.66,
max_steps: int = 10000,
step_size: float = 0.01,
step_decay: float = 0.9995,
convergence_threshold: float = 1e-05,
max_step_size: Optional[float] = None,
return_grad_norms: Literal[True] = True,
) -> Tuple[Tensor, Tensor]
spherical_points_gradient(
radius: float,
num_points: int,
fixed_position: Literal[
"none", "center", "vertical"
] = "center",
ratio: float = 0.66,
max_steps: int = 10000,
step_size: float = 0.01,
step_decay: float = 0.9995,
convergence_threshold: float = 1e-05,
max_step_size: Optional[float] = None,
return_grad_norms: bool = False,
) -> Union[Tensor, Tuple[Tensor, Tensor]]
Creation of kernel points via optimization of potentials for a single kernel.
Parameters:
-
radius(float) –Radius of the kernel.
-
num_points(int) –Number of points composing the kernel.
-
fixed_position(Literal['none', 'center', 'vertical'], default:'center') –Fix position of certain kernel points ('none', 'center', or 'vertical').
-
ratio(float, default:0.66) –Ratio of the radius where you want the kernel points to be placed.
-
max_steps(int, default:10000) –Maximum number of optimization steps.
-
step_size(float, default:0.01) –Step size for moving points based on gradient norms.
-
step_decay(float, default:0.9995) –Decay factor for reducing the step size over time.
-
convergence_threshold(float, default:1e-05) –Threshold for stopping the optimization when gradient norm changes are small.
-
max_step_size(Optional[float], default:None) –Maximum distance a point can move in a single step.
-
return_grad_norms(bool, default:False) –Whether to also return the gradient norms recorded during the optimization.
Returns:
-
Union[Tensor, Tuple[Tensor, Tensor]]–Optimized kernel points of shape \((\text{num\_points}, 3)\), or a tuple of the kernel points and the recorded gradient norms when
return_grad_norms=True.
spherical_points_lloyd
¶
spherical_points_lloyd(
radius: float,
num_points: int,
fixed_position: Literal[
"none", "center", "vertical"
] = "none",
approximation: Literal[
"discretization", "monte-carlo"
] = "discretization",
approx_n: int = 5000,
max_iter: int = 500,
momentum: float = 0.9,
) -> Tensor
Generate kernel points using Lloyd's algorithm on a sphere.
Parameters:
-
radius(float) –Radius of the sphere.
-
num_points(int) –Number of kernel points (Voronoi cells).
-
fixed_position(str, default:'none') –Fix the position of specific kernel points. Defaults to 'none'. Options: - 'none': No kernel points are fixed. All points move freely during optimization. - 'center': The first kernel point is fixed at the center of the sphere. - 'vertical': (3D only) The first three kernel points are fixed along the z-axis: - The first point is fixed at the center. - The second point is placed above the center along the positive z-axis. - The third point is placed below the center along the negative z-axis.
-
approximation(str, default:'discretization') –Approximation method for Lloyd's algorithm. Defaults to 'discretization'. Options: - 'discretization': Approximates the Voronoi cells using a regular grid of points within the sphere. - 'monte-carlo': Approximates the Voronoi cells by randomly sampling points within the sphere.
-
approx_n(int, default:5000) –Number of points used for approximation. Defaults to 5000.
-
max_iter(int, default:500) –Maximum number of iterations. Defaults to 500.
-
momentum(float, default:0.9) –Momentum factor for smoothing kernel point positions. Defaults to 0.9.
Returns:
-
Tensor(Tensor) –Tensor of shape [num_points, dimension] with the final kernel points on the sphere.