trusty.affine¶
Affine (articulated) bodies.
VelocityPenaltyMode
¶
add_affine_body
¶
add_affine_body(
world: World,
V: ndarray[float64, (N, 3)],
F: ndarray[int32, (N, 3)],
density: float = 1000.0,
stiffness: float = 100000000.0,
*,
friction_mu: float = 0.0,
) -> int
Add a near-rigid affine body from a closed, outward-wound triangle surface mesh (V: (n,3), F: (m,3)). stiffness (Pa) is the orthogonality rigidity -- large values are effectively rigid. friction_mu is the body's surface Coulomb coefficient (>= 0); 0 is frictionless.
add_affine_curve
¶
add_affine_curve(
world: World,
V: ndarray[float64, (N, 3)],
E: ndarray[int32, (N, 2)],
radius: float,
density: float = 1000.0,
stiffness: float = 100000000.0,
*,
friction_mu: float = 0.0,
) -> int
Add a near-rigid affine body shaped as a tube of radius (m) around a curve: centerline vertices V (n,3) joined by edges E (m,2) into open polylines or closed loops (a chain link). Its mass is the tube's, and contact holds other surfaces radius off the centerline. stiffness (Pa) is the orthogonality rigidity -- large values are effectively rigid. friction_mu is the body's surface Coulomb coefficient (>= 0); 0 is frictionless.
add_spherical_joint
¶
add_spherical_joint(
world: World,
body_i: int,
anchor: tuple[float, float, float],
body_j: int | None = None,
stiffness: float = 100000000.0,
) -> int
Spherical (ball) joint: pin anchor (rest world coords) on body_i to body_j, or to its fixed rest position if body_j is omitted. Free relative rotation.
add_revolute_joint
¶
add_revolute_joint(
world: World,
body_i: int,
axis_p0: tuple[float, float, float],
axis_p1: tuple[float, float, float],
body_j: int | None = None,
stiffness: float = 100000000.0,
) -> int
Revolute (hinge) joint: pin the axis line through axis_p0/axis_p1 between body_i and body_j (grounded if omitted). One rotational DOF about that axis.
add_fixed_joint
¶
add_fixed_joint(
world: World,
body_i: int,
origin: tuple[float, float, float],
axis_u: tuple[float, float, float],
axis_v: tuple[float, float, float],
body_j: int | None = None,
stiffness: float = 1000000.0,
) -> int
Fixed (weld) joint: rigidly weld body_i to body_j (grounded if omitted), fully constraining their relative rigid pose. Pins the 3-point frame origin, origin + axis_u, origin + axis_v (rest world coords; axis_u, axis_v are non-collinear offset vectors). The welded pair is auto-excluded from contact. Each affine body keeps its residual deformation DOF, so a soft body welded under a stiff one stays pose-locked but still deformable.
add_prismatic_joint
¶
add_prismatic_joint(
world: World,
body_i: int,
anchor: tuple[float, float, float],
axis: tuple[float, float, float],
body_j: int | None = None,
stiffness: float = 100000000.0,
) -> int
Prismatic (slider) joint: lock body_i's orientation relative to body_j (the world if omitted) and let anchor slide only along a rail with direction axis fixed in body_j's frame. anchor and axis are rest world coordinates. The joint coordinate (a joint drive's target and position, limits) is the slide in m along the rail, measured in body_j's frame, 0 at rest. A body-body pair is excluded from contact.
add_universal_joint
¶
add_universal_joint(
world: World,
body_i: int,
body_j: int,
anchor: tuple[float, float, float],
axis_i: tuple[float, float, float],
axis_j: tuple[float, float, float],
stiffness: float = 100000000.0,
) -> int
Universal (Hooke) joint: pin anchor on body_i to body_j and let them turn about two perpendicular axes, axis_i fixed in body_i and axis_j fixed in body_j (rest world directions). Read its angles with universal_joint_angles; limit either with add_joint_limit(..., axis=). It has no drives, velocity limits or damping. The pair is excluded from contact.
universal_joint_angles
¶
A universal joint's angles (q0, q1) at the last accepted step (rad): q0 about axis_i, q1 about axis_j, 0 where the bodies were added.
add_joint_limit
¶
add_joint_limit(
world: World,
joint: int,
lo: float,
hi: float,
margin: float = 0.05,
stiffness: float = 1000.0,
axis: int = 0,
) -> int
Add a joint-limit barrier (C2 clamped log-barrier) to a revolute, prismatic or universal joint, confining its coordinate to [lo, hi] (revolute or universal angle in rad, must be within (-pi, pi); prismatic slide in m). axis picks the universal joint's coordinate, 0 or 1; it is 0 for every other joint. margin is the activation distance from each limit. Stops over-travel without a wrap-through; spherical joints are unsupported.
add_joint_velocity_limit
¶
add_joint_velocity_limit(
world: World,
joint: int,
omega_max: float,
stiffness: float = 1000000.0,
mode: VelocityPenaltyMode = VelocityPenaltyMode.Barrier,
barrier_width_fraction: float = 0.25,
) -> int
Add a velocity limit to a revolute, prismatic, or spherical joint, capping its rate at omega_max (revolute rad/s, prismatic m/s, spherical angular-velocity magnitude rad/s) on the integrator-consistent joint velocity. mode is VelocityPenaltyMode.Barrier (the default HARD cap), .Quadratic (a soft cap: firmer than Cubic, no asymptote), .Cubic (C2 but soft near the cap). The barrier is a clamped log-barrier that activates barrier_width_fraction * omega_max below the wall and carries an analytic step filter, so Newton sees the cap before it steps through it, and the rate never exceeds omega_max. Fixed (weld) joints are unsupported.
bodies
¶
Every affine body in the world, as a set -- there is no i-th body. Iterate it, or hold the handle add_affine_body returned.
surface_positions
¶
Current world-space positions (V, 3) of affine body body's surface vertices, the rows trusty.surface.mesh(world, body) indexes: a curve body's centerline vertices. The rest surface before the first step.
center_of_mass
¶
Rest-frame centre of mass (3,) of affine body body, in meters. Computed from its rest shape at creation and constant for the body's life; the body's 12 affine DOFs are taken about it.
set_velocity
¶
set_velocity(
world: World,
body: int,
v: ndarray[float64, (3,)],
omega: ndarray[float64, (3,)] | None = None,
) -> None
Set affine body body's rigid velocity: centre-of-mass velocity v (m/s, world) and angular velocity omega about the centre of mass (rad/s, world; None = no spin). A material point at x moves at v + omega x (x - c), c the body's current centre of mass; any deformation rate is zeroed. Applied at the next step(); only this body's history is rewritten, and the integrator is unchanged.
set_project_positive_definite
¶
PSD-project this module's Hessians on every Newton iteration (default off). Call before the first step().