@@ -75,7 +75,7 @@ def draw_capsule(
7575 p2 : NDArray ,
7676 radius : float = 0.05 ,
7777 rgba : NDArray | None = None ,
78- is_cylinder : bool = False ,
78+ cylinder : bool = False ,
7979):
8080 """Draw a capsule (pill) or cylinder between two points.
8181
@@ -85,31 +85,18 @@ def draw_capsule(
8585 p2: End point [3,]
8686 radius: The thickness of the geom in [m].
8787 rgba: The color of the object.
88- is_cylinder: If True, draws a flat-ended cylinder.
89- If False, draws a pill-shaped capsule.
88+ cylinder: If True, draws a flat-ended cylinder. If False, draws a pill-shaped capsule.
9089 """
9190 if sim .viewer is None :
9291 return
9392
94- # 1. Calculate Midpoint (Center of the geom)
95- pos = (p1 + p2 ) / 2.0
96-
97- # 2. Calculate Half-length (MuJoCo uses half-extents)
98- dist = np .linalg .norm (p2 - p1 )
99- half_length = dist / 2.0
100-
101- # 3. Define Size: [radius, radius, half_length]
102- # Note: For capsules, size[2] is the half-length of the *cylindrical* part.
103- # MuJoCo adds the hemispherical caps on top of this.
93+ pos = (p1 + p2 ) / 2.0 # Center of the geom
94+ half_length = np .linalg .norm (p2 - p1 ) / 2.0 # MuJoCo uses half-extents
10495 size = np .array ([radius , half_length , 0 ])
105-
106- # 4. Get Rotation (Align Z-axis to the vector p2-p1)
107- # Using your existing helper (wrapped in a list for the reshape)
96+ # Align the z-axis of the geom to the vector from p1 to p2
10897 mat = _rotation_matrix_from_points (p1 [None , :], p2 [None , :]).as_matrix ().flatten ()
109-
110- geom_type = mujoco .mjtGeom .mjGEOM_CYLINDER if is_cylinder else mujoco .mjtGeom .mjGEOM_CAPSULE
111- rgba = rgba if rgba is not None else np .array ([0 , 1.0 , 0 , 1 ])
112-
98+ geom_type = mujoco .mjtGeom .mjGEOM_CYLINDER if cylinder else mujoco .mjtGeom .mjGEOM_CAPSULE
99+ rgba = rgba if rgba is not None else np .array ([1 , 0 , 0 , 1.0 ])
113100 sim .viewer .viewer .add_marker (type = geom_type , pos = pos , size = size , mat = mat , rgba = rgba )
114101
115102
0 commit comments