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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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 [source] ΒΆ
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.