Visual Meshes vs. Collision Primitives
The first time I imported a detailed CAD assembly of a robot arm into a physics simulator, my frame rate dropped from real-time to a slideshow. The culprit wasn't the physics math — it was asking the collision engine to test every bolt hole and chamfer on a 50,000-triangle mesh every millisecond.
Core ideas covered in this module
- Visual vs. collision geometry
- Convex primitives (capsules, spheres, boxes)
- Contact-check performance trade-offs
Two faces for every link: one for your eyes, one for physics
Think about how a video game character works. What you see on screen might have jacket folds, shoelaces, and detailed armor plates, while the physics engine quietly treats that character as a smooth vertical pill so it slides cleanly past doorways without snagging on a belt buckle.
Robots in simulation do the exact same thing. Inside every `<link>` block in a URDF or MJCF file, there are separate `<visual>` and `<collision>` blocks. The `<visual>` block points to a high-poly `.obj` or `.stl` mesh so engineers and camera sensors see realistic hardware. The `<collision>` block replaces that intricate shape with a handful of simple convex primitives.
Why capsules, spheres, and boxes win on speed
Checking whether two arbitrary triangle meshes overlap requires inspecting thousands of triangle pairs. Checking whether two capsules overlap comes down to a single line-segment-to-line-segment distance formula:
- Spheres: fastest possible check — just compare center distance against the sum of radii `r₁ + r₂`.
- Capsules (swept spheres): a line segment with a radius around it. Ideal for forearms, shins, and robot legs because they have zero sharp corners to catch on edges.
- Boxes: clean for flat grippers, table tops, and rectangular battery torsos.
Interactive lab
URDF & Collision Capsule Inspector
Three.js· Live<robot name="planar_manipulator">
<link name="base_link">
<visual><geometry><mesh filename="meshes/base.stl"/></geometry></visual>
<collision><geometry><box size="0.18 0.18 0.12"/></geometry></collision>
</link>
<joint name="shoulder_pitch" type="revolute">
<parent link="base_link"/>
<child link="upper_arm"/>
<origin xyz="0 0 0.12" rpy="0 0 0"/>
<axis xyz="0 1 0"/>
<limit lower="-2.40" upper="2.40" effort="85" velocity="3.2"/>
</joint>
<link name="upper_arm">
<visual><geometry><mesh filename="meshes/upper_arm.obj"/></geometry></visual>
<collision>
<origin xyz="0.210 0 0" rpy="0 1.5708 0"/>
<geometry><cylinder length="0.42" radius="0.055"/></geometry>
</collision>
</link>
<joint name="elbow_pitch" type="revolute">
<parent link="upper_arm"/>
<child link="forearm"/>
<origin xyz="0.42 0 0" rpy="0 0 0"/>
<limit lower="-2.60" upper="2.60" effort="55" velocity="4.0"/>
</joint>
<link name="forearm">
<collision>
<origin xyz="0.180 0 0" rpy="0 1.5708 0"/>
<geometry><cylinder length="0.36" radius="0.055"/></geometry>
</collision>
</link>
</robot>Tight envelopes, safe margins, and self-collision
When fitting collision primitives around a visual link, you want them slightly conservative — hugging the real hardware closely enough that the arm can reach into bins, yet padded by a few millimeters so cables and screw heads don't graze obstacles.
Once those capsules are in place, collision checking isn't only for tables and walls. Simulators and motion planners also run self-collision checks between non-adjacent links on the same robot (for example, making sure a quadruped's front shin never clips through its own belly) thousands of times per second.
Capsule-to-capsule clearance test
clearance = min_dist(segment_A, segment_B) − (r_A + r_B)
If `clearance <= 0`, the two capsules are touching or penetrating. Computing segment-to-segment distance takes a few dozen floating-point operations instead of thousands of triangle tests.
You are simulating 4,096 parallel quadruped robots on a GPU to train a walking policy. What happens if you point `<collision>` directly at the 40,000-triangle CAD meshes instead of capsules?
Modern GPU simulators like MuJoCo MJX and Isaac Lab rely heavily on primitive collision geoms (especially spheres and capsules) so thousands of environments can step physics in parallel without blowing up contact buffers.
Hands-On Python Notebook
02 · Visual Meshes vs. Collision Capsules Lab
Implement exact point-to-capsule distance checks and benchmark primitive contact checks against dense polygon vertices.
Try this on your own inside the notebook
- Compute minimum clearance between two moving capsules in 2D
- Fit an enclosing capsule radius around a sampled link mesh
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-2/02_visual_vs_collision_primitives.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.