2 from test_case
import TestCase
13 self.assertEqual(capsule.getNodeType(), coal.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 =
coal.Box(np.array([1.0, 2.0, 3.0]))
54 self.assertEqual(box.getNodeType(), coal.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()
80 self.assertEqual(box.getNodeType(), coal.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)
90 self.assertEqual(sphere.getNodeType(), coal.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()
110 self.assertEqual(cylinder.getNodeType(), coal.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()
123 Ix_ref = V_ref * (3 * cylinder.radius**2 + 4 * cylinder.halfLength**2) / 12.0
124 Iz_ref = V_ref * cylinder.radius**2 / 2.0
125 I0_ref = np.diag([Ix_ref, Ix_ref, Iz_ref])
127 Ic = cylinder.computeMomentofInertiaRelatedToCOM()
135 self.assertEqual(cone.getNodeType(), coal.NODE_TYPE.GEOM_CONE)
136 self.assertEqual(cone.radius, 1.0)
137 self.assertEqual(cone.halfLength, 1.0)
139 cone.halfLength = 4.0
140 self.assertEqual(cone.radius, 3.0)
141 self.assertEqual(cone.halfLength, 4.0)
142 com = cone.computeCOM()
143 self.
assertApprox(com, np.array([0.0, 0.0, -0.5 * cone.halfLength]))
144 V = cone.computeVolume()
145 V_ref = np.pi * cone.radius**2 * 2.0 * cone.halfLength / 3.0
147 I0 = cone.computeMomentofInertia()
148 Ix_ref = V_ref * (3.0 / 20.0 * cone.radius**2 + 0.4 * cone.halfLength**2)
149 Iz_ref = 0.3 * V_ref * cone.radius**2
150 I0_ref = np.diag([Ix_ref, Ix_ref, Iz_ref])
152 Ic = cone.computeMomentofInertiaRelatedToCOM()
153 Icx_ref = V_ref * 3.0 / 20.0 * (cone.radius**2 + cone.halfLength**2)
154 Ic_ref = np.diag([Icx_ref, Icx_ref, Iz_ref])
158 bvh = coal.BVHModelOBBRSS()
159 self.assertEqual(bvh.num_vertices, 0)
160 self.assertEqual(bvh.vertices().shape, (0, 3))
163 verts = coal.StdVec_Vec3s()
164 faces = coal.StdVec_Triangle()
175 verts.append(np.array([0, 0, 1]))
177 coal.Convex.convexHull(verts,
False,
None)
178 qhullAvailable =
True
179 except Exception
as e:
181 "Library built without qhull. Cannot build object of this type.",
str(e)
183 qhullAvailable =
False
186 coal.Convex.convexHull(verts,
False,
"")
187 coal.Convex.convexHull(verts,
True,
"")
190 coal.Convex.convexHull(verts[:3],
False,
None)
191 except Exception
as e:
193 "You shouldn't use this function with less than 4 points.",
str(e)
197 if __name__ ==
"__main__":