2 from test_case
import TestCase
9 capsule = hppfcl.Capsule(1.0, 2.0)
10 self.assertIsInstance(capsule, hppfcl.Capsule)
11 self.assertIsInstance(capsule, hppfcl.ShapeBase)
12 self.assertIsInstance(capsule, hppfcl.CollisionGeometry)
13 self.assertEqual(capsule.getNodeType(), hppfcl.NODE_TYPE.GEOM_CAPSULE)
14 self.assertEqual(capsule.radius, 1.0)
15 self.assertEqual(capsule.halfLength, 1.0)
17 capsule.halfLength = 4.0
18 self.assertEqual(capsule.radius, 3.0)
19 self.assertEqual(capsule.halfLength, 4.0)
20 com = capsule.computeCOM()
22 V = capsule.computeVolume()
23 V_cylinder = capsule.radius * capsule.radius * np.pi * 2.0 * capsule.halfLength
24 V_sphere = 4.0 * np.pi / 3 * capsule.radius**3
25 V_ref = V_cylinder + V_sphere
27 I0 = capsule.computeMomentofInertia()
28 Iz_cylinder = V_cylinder * capsule.radius**2 / 2.0
29 Iz_sphere = 0.4 * V_sphere * capsule.radius * capsule.radius
30 Iz_ref = Iz_cylinder + Iz_sphere
32 V_cylinder * (3 * capsule.radius**2 + 4 * capsule.halfLength**2) / 12.0
34 V_hemi = 0.5 * V_sphere
35 I0x_hemi = 0.5 * Iz_sphere
36 com_hemi = 3.0 * capsule.radius / 8.0
38 I0x_hemi - V_hemi * com_hemi * com_hemi
41 Icx_hemi + V_hemi * (capsule.halfLength + com_hemi) ** 2
43 Ix_ref = Ix_cylinder + 2 * Ix_hemi
44 I0_ref = np.diag([Ix_ref, Ix_ref, Iz_ref])
46 Ic = capsule.computeMomentofInertiaRelatedToCOM()
50 box = hppfcl.Box(np.array([1.0, 2.0, 3.0]))
51 self.assertIsInstance(box, hppfcl.Box)
52 self.assertIsInstance(box, hppfcl.ShapeBase)
53 self.assertIsInstance(box, hppfcl.CollisionGeometry)
54 self.assertEqual(box.getNodeType(), hppfcl.NODE_TYPE.GEOM_BOX)
55 self.assertTrue(np.array_equal(box.halfSide, np.array([0.5, 1.0, 1.5])))
56 box.halfSide = np.array([4.0, 5.0, 6.0])
57 self.assertTrue(np.array_equal(box.halfSide, np.array([4.0, 5.0, 6.0])))
58 com = box.computeCOM()
60 V = box.computeVolume()
61 x = float(2 * box.halfSide[0])
62 y = float(2 * box.halfSide[1])
63 z = float(2 * box.halfSide[2])
66 I0 = box.computeMomentofInertia()
67 Ix = V_ref * (y * y + z * z) / 12.0
68 Iy = V_ref * (x * x + z * z) / 12.0
69 Iz = V_ref * (y * y + x * x) / 12.0
70 I0_ref = np.diag([Ix, Iy, Iz])
72 Ic = box.computeMomentofInertiaRelatedToCOM()
76 box = hppfcl.Box(1.0, 2.0, 3)
77 self.assertIsInstance(box, hppfcl.Box)
78 self.assertIsInstance(box, hppfcl.ShapeBase)
79 self.assertIsInstance(box, hppfcl.CollisionGeometry)
80 self.assertEqual(box.getNodeType(), hppfcl.NODE_TYPE.GEOM_BOX)
81 self.assertEqual(box.halfSide[0], 0.5)
82 self.assertEqual(box.halfSide[1], 1.0)
83 self.assertEqual(box.halfSide[2], 1.5)
86 sphere = hppfcl.Sphere(1.0)
87 self.assertIsInstance(sphere, hppfcl.Sphere)
88 self.assertIsInstance(sphere, hppfcl.ShapeBase)
89 self.assertIsInstance(sphere, hppfcl.CollisionGeometry)
90 self.assertEqual(sphere.getNodeType(), hppfcl.NODE_TYPE.GEOM_SPHERE)
91 self.assertEqual(sphere.radius, 1.0)
93 self.assertEqual(sphere.radius, 2.0)
94 com = sphere.computeCOM()
96 V = sphere.computeVolume()
97 V_ref = 4.0 * np.pi / 3 * sphere.radius**3
99 I0 = sphere.computeMomentofInertia()
100 I0_ref = 0.4 * V_ref * sphere.radius * sphere.radius * np.identity(3)
102 Ic = sphere.computeMomentofInertiaRelatedToCOM()
106 cylinder = hppfcl.Cylinder(1.0, 2.0)
107 self.assertIsInstance(cylinder, hppfcl.Cylinder)
108 self.assertIsInstance(cylinder, hppfcl.ShapeBase)
109 self.assertIsInstance(cylinder, hppfcl.CollisionGeometry)
110 self.assertEqual(cylinder.getNodeType(), hppfcl.NODE_TYPE.GEOM_CYLINDER)
111 self.assertEqual(cylinder.radius, 1.0)
112 self.assertEqual(cylinder.halfLength, 1.0)
113 cylinder.radius = 3.0
114 cylinder.halfLength = 4.0
115 self.assertEqual(cylinder.radius, 3.0)
116 self.assertEqual(cylinder.halfLength, 4.0)
117 com = cylinder.computeCOM()
119 V = cylinder.computeVolume()
120 V_ref = cylinder.radius * cylinder.radius * np.pi * 2.0 * cylinder.halfLength
122 I0 = cylinder.computeMomentofInertia()
124 V_ref * (3 * cylinder.radius**2 + 4 * cylinder.halfLength**2) / 12.0
126 Iz_ref = V_ref * cylinder.radius**2 / 2.0
127 I0_ref = np.diag([Ix_ref, Ix_ref, Iz_ref])
129 Ic = cylinder.computeMomentofInertiaRelatedToCOM()
133 cone = hppfcl.Cone(1.0, 2.0)
134 self.assertIsInstance(cone, hppfcl.Cone)
135 self.assertIsInstance(cone, hppfcl.ShapeBase)
136 self.assertIsInstance(cone, hppfcl.CollisionGeometry)
137 self.assertEqual(cone.getNodeType(), hppfcl.NODE_TYPE.GEOM_CONE)
138 self.assertEqual(cone.radius, 1.0)
139 self.assertEqual(cone.halfLength, 1.0)
141 cone.halfLength = 4.0
142 self.assertEqual(cone.radius, 3.0)
143 self.assertEqual(cone.halfLength, 4.0)
144 com = cone.computeCOM()
145 self.
assertApprox(com, np.array([0.0, 0.0, -0.5 * cone.halfLength]))
146 V = cone.computeVolume()
147 V_ref = np.pi * cone.radius**2 * 2.0 * cone.halfLength / 3.0
149 I0 = cone.computeMomentofInertia()
150 Ix_ref = V_ref * (3.0 / 20.0 * cone.radius**2 + 0.4 * cone.halfLength**2)
151 Iz_ref = 0.3 * V_ref * cone.radius**2
152 I0_ref = np.diag([Ix_ref, Ix_ref, Iz_ref])
154 Ic = cone.computeMomentofInertiaRelatedToCOM()
155 Icx_ref = V_ref * 3.0 / 20.0 * (cone.radius**2 + cone.halfLength**2)
156 Ic_ref = np.diag([Icx_ref, Icx_ref, Iz_ref])
160 verts = hppfcl.StdVec_Vec3f()
161 faces = hppfcl.StdVec_Triangle()
169 faces.append(hppfcl.Triangle(0, 1, 2))
170 convex = hppfcl.Convex(verts, faces)
172 verts.append(np.array([0, 0, 1]))
174 convexHull = hppfcl.Convex.convexHull(verts,
False,
None)
175 qhullAvailable =
True 176 except Exception
as e:
178 str(e),
"Library built without qhull. Cannot build object of this type." 180 qhullAvailable =
False 183 convexHull = hppfcl.Convex.convexHull(verts,
False,
"")
184 convexHull = hppfcl.Convex.convexHull(verts,
True,
"")
187 convexHull = hppfcl.Convex.convexHull(verts[:3],
False,
None)
188 except Exception
as e:
190 str(e),
"You shouldn't use this function with less than 4 points." 194 if __name__ ==
"__main__":
def assertApprox(self, a, b, epsilon=1e-6)