MCPcopy Create free account
hub / github.com/Simple-Robotics/Simple / register_line

Function register_line

sandbox/viz_utils.py:64–89  ·  view source on GitHub ↗
(
    viz: MeshcatVisualizer,
    pt1: np.ndarray,
    pt2: np.ndarray,
    line_name: str,
    linewidth: float = 0.01,
    color: np.ndarray = BLACK,
)

Source from the content-addressed store, hash-verified

62
63
64def register_line(
65 viz: MeshcatVisualizer,
66 pt1: np.ndarray,
67 pt2: np.ndarray,
68 line_name: str,
69 linewidth: float = 0.01,
70 color: np.ndarray = BLACK,
71) -> int:
72 height = np.linalg.norm(pt2 - pt1)
73 if height > 1e-6:
74 axis_ref = np.array([0.0, 0.0, 1.0])
75 axis = (pt2 - pt1) / height # - np.array([0., 0., 1.])
76 num = np.outer(axis_ref + axis, axis_ref + axis)
77 den = np.dot(axis_ref + axis, axis_ref + axis)
78 if den > 1e-6:
79 R = 2 * num / den - np.eye(3)
80 else:
81 R = np.array([[1, 0, 0], [0, -1, 0], [0, 0, -1]])
82 t = pt1
83 translation = pin.SE3(np.eye(3), np.array([0.0, 0.0, height / 2]))
84 M = pin.SE3(R, t)
85 Mtot = M * translation
86 cylinder = hppfcl.Cylinder(linewidth, height)
87 meshcat_shape = load_primitive(cylinder)
88 viz.viewer[line_name].set_object(meshcat_shape, meshcat_material(*color))
89 viz.viewer[line_name].set_transform(Mtot.homogeneous)
90
91
92def register_arrowed_line(

Callers 1

register_arrowed_lineFunction · 0.85

Calls 2

load_primitiveFunction · 0.85
meshcat_materialFunction · 0.85

Tested by

no test coverage detected