Implementation:Haosulab ManiSkill GeometryUtils
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Simulation, 3D Geometry |
| Last Updated | 2026-02-15 08:00 GMT |
Overview
Concrete tool for 3D geometry operations including sampling, rotation, bounding box computation, and coordinate transformations for physics objects.
Description
The geometry.py module provides a collection of geometry utility functions used across ManiSkill for spatial reasoning, bounding volume computation, and coordinate transformations.
Sampling:
sample_on_unit_sphere(rng)-- Uniformly samples a point on the unit sphere using Gaussian sampling.sample_on_unit_circle(rng)-- Uniformly samples a point on the unit circle.
Rotation/Angle:
rotation_between_vec(a, b)-- Computes the scipy Rotation from vector a to vector b.angle_between_vec(a, b)-- Computes the angle in radians between two vectors.angle_distance(q0, q1)-- Angular distance between two sapien.Pose quaternions (normalized to [0, 1]).rotate_2d_vec_by_angle(vec, theta)-- Rotates a 2D vector by angle theta.wxyz_to_xyzw()/xyzw_to_wxyz()-- Quaternion convention converters.
Bounding volumes:
get_axis_aligned_bbox_for_articulation(art)-- AABB for an entire articulation.get_axis_aligned_bbox_for_actor(actor)-- AABB for a single actor entity.get_local_axis_aligned_bbox_for_link(link)-- AABB in link-local frame.get_local_aabc_for_actor(actor)-- Axis-aligned bounding cylinder in local frame.get_oriented_bounding_box_for_2d_points(points_2d)-- OBB via PCA for 2D point sets.
Transformations:
transform_points(H, pts)-- Batched transformation of 3D points by 4x4 matrices.invert_transform(H)-- Invert a batch of 4x4 transformation matrices.rotate_vector(v, q)-- Rotate a vector by a quaternion (pulled from SAPIEN).
Usage
Import specific functions for spatial reasoning in task reward computation, object manipulation planning, and scene understanding.
Code Reference
Source Location
- Repository: Haosulab_ManiSkill
- File: mani_skill/utils/geometry/geometry.py
Signature
def sample_on_unit_sphere(rng) -> np.ndarray: ...
def rotation_between_vec(a, b) -> Rotation: ...
def angle_between_vec(a, b) -> float: ...
def get_axis_aligned_bbox_for_articulation(art: PhysxArticulation) -> tuple[np.ndarray, np.ndarray]: ...
def get_axis_aligned_bbox_for_actor(actor: sapien.Entity) -> tuple[np.ndarray, np.ndarray]: ...
def transform_points(H: torch.Tensor, pts: torch.Tensor) -> torch.Tensor: ...
def invert_transform(H: np.ndarray) -> np.ndarray: ...
def get_oriented_bounding_box_for_2d_points(points_2d: np.ndarray, resolution=0.0) -> dict: ...
Import
from mani_skill.utils.geometry.geometry import (
sample_on_unit_sphere,
get_axis_aligned_bbox_for_articulation,
transform_points,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| rng | np.random.RandomState | Yes | Random number generator (for sampling functions) |
| art | PhysxArticulation | Yes | Articulation for AABB computation |
| H | torch.Tensor (N, 4, 4) | Yes | Batch of transformation matrices |
| pts | torch.Tensor (N, 3) | Yes | Points to transform |
Outputs
| Name | Type | Description |
|---|---|---|
| mins, maxs | np.ndarray (3,) | AABB minimum and maximum corners |
| transformed | torch.Tensor (N, 3) | Transformed points |
Usage Examples
Basic Usage
import numpy as np
from mani_skill.utils.geometry.geometry import (
sample_on_unit_sphere,
get_axis_aligned_bbox_for_actor,
angle_between_vec,
)
# Sample a random direction
rng = np.random.RandomState(42)
direction = sample_on_unit_sphere(rng)
# Compute angle between two vectors
angle = angle_between_vec(np.array([1, 0, 0]), np.array([0, 1, 0]))
# angle ~= pi/2
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment