@@ -321,18 +321,37 @@ def test_truncated(count=10):
321321 assert all (s .volume > 0 for s in split )
322322
323323
324+ def test_revolve_lowres ():
325+ line = g .np .array ([[1.0 , 0.0 ], [1.0 , 1.0 ], [1.0 , 2.0 ], [1.0 , 3.0 ]])
326+ t = g .trimesh .creation .revolve (line , cap = False , sections = 6 )
327+ assert t .vertices .shape == (24 , 3 )
328+ assert t .faces .shape == (36 , 3 )
329+
330+
324331def test_revolve ():
325- # create a cross section and revolve it to form some volumes
326- cross_section = [[0 , 0 ], [10 , 0 ], [10 , 10 ], [0 , 10 ]]
332+ # create a cross section of a cylinder and revolve it
333+ r = 10.0
334+ h = 20.0
335+ cross_section = [[0 , 0 ], [r , 0 ], [r , h ], [0 , h ]]
336+
337+ # use a fine-grained revolution so the area and volume are closer
338+ mesh = g .trimesh .creation .revolve (cross_section , sections = 100 )
339+
340+ # area of one end-cap
341+ area_cap = g .np .pi * r ** 2
342+ # area of a cylinder
343+ area = g .np .pi * 2 * r * h + (area_cap * 2 )
344+
345+ # volume should match a theoretical cylinder
346+ assert g .np .isclose (mesh .volume , area_cap * h , rtol = 0.01 )
347+ # area should match a theoretical cylinder
348+ assert g .np .isclose (mesh .area , area , rtol = 0.1 ), f"{ mesh .area } != { area } "
327349
328- # high sections needed so volume is close to theoretical value for perfect revoulution
329- mesh360 = g .trimesh .creation .revolve (cross_section , 2 * g .np .pi , sections = 360 )
330- mesh360_volume = g .np .pi * 10 ** 2 * 10
331- assert g .np .isclose (mesh360 .volume , mesh360_volume , rtol = 0.1 )
332- assert mesh360 .is_volume , "mesh360 should be a valid volume"
350+ # should be a watertight solid
351+ assert mesh .is_volume , "mesh360 should be a valid volume"
333352
334353 mesh180 = g .trimesh .creation .revolve (cross_section , g .np .pi , sections = 180 , cap = True )
335- assert g .np .isclose (mesh180 .volume , mesh360 .volume / 2 , rtol = 0.1 ), (
354+ assert g .np .isclose (mesh180 .volume , mesh .volume / 2 , rtol = 0.1 ), (
336355 "mesh180 should be half of mesh360 volume"
337356 )
338357 assert mesh180 .is_volume , "mesh180 should be a valid volume"
@@ -388,4 +407,5 @@ def test_torus():
388407
389408
390409if __name__ == "__main__" :
391- test_torus ()
410+ # test_torus()
411+ test_revolve ()
0 commit comments