3 from pathlib 
import Path
 
    5 import meshcat.geometry 
as g
 
    7 import pinocchio 
as pin
 
   11 pinocchio_model_dir = Path(__file__).parent.parent / 
"models" 
   13 model_path = pinocchio_model_dir / 
"example-robot-data/robots" 
   14 mesh_dir = pinocchio_model_dir
 
   16 urdf_filename = 
"panda.urdf" 
   17 urdf_model_path = model_path / 
"panda_description/urdf" / urdf_filename
 
   19 robot, collision_model, visual_model = pin.buildModelsFromUrdf(
 
   20     urdf_model_path, mesh_dir
 
   22 data = robot.createData()
 
   27     viz.initViewer(open=
True)
 
   28 except ImportError 
as err:
 
   30         "Error while initializing the viewer. " 
   31         "It seems you should install Python meshcat" 
   39 q0 = (robot.upperPositionLimit.T + robot.lowerPositionLimit.T) / 2
 
   41 frame = robot.getFrameId(
 
   53         robot, q0, horizon, frame, n_samples, facet_dims
 
   62         from CGAL.CGAL_Polyhedron_3 
import Polyhedron_3
 
   63     except ModuleNotFoundError:
 
   64         print(
"To compute non convex Polytope CGAL library needs to be installed.")
 
   68         return v.x(), v.y(), v.z()
 
   82         Compute the alpha shape of a set of points. (Code thanks to A. Skuric) 
   83         Retrieved from http://blog.thehumangeo.com/2014/05/12/drawing-boundaries-in-python/ 
   85         :param coords : Coordinates of points 
   86         :param alpha: List of alpha values to influence the gooeyness of the border. 
   87         Smaller numbers don't fall inward as much as larger numbers. 
   88         Too large, and you lose everything! 
   89         :return: Shapely.MultiPolygons which is the hull of the input set of points 
   92             bbox_diag = np.linalg.norm(np.max(coords, 0) - np.min(coords, 0))
 
   93             alpha_value = bbox_diag / 5
 
   95             alpha_value = np.mean(alpha)
 
   97         points = [Point_3(pt[0], pt[1], pt[2]) 
for pt 
in coords]  
 
  100         _a = alpha_wrap_3(points, alpha_value, 0.01, Q)  
 
  102         alpha_shape_vertices = np.array(
 
  105         alpha_shape_faces = np.array(
 
  109         return alpha_shape_vertices, alpha_shape_faces
 
  116     verts = faces.reshape(-1, 3)
 
  117     faces = np.arange(len(verts)).reshape(-1, 3)
 
  119 print(
"------------------- Display Vertex")
 
  123 poly = g.TriangularMeshGeometry(vertices=verts, faces=faces)
 
  124 viz.viewer[
"poly"].set_object(
 
  125     poly, g.MeshBasicMaterial(color=0x000000, wireframe=
True, linewidth=12, opacity=0.2)
 
  130     viz.viewer[
"poly"].set_object(
 
  132         g.MeshBasicMaterial(color=0x000000, wireframe=
True, linewidth=2, opacity=0.2),