cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Problem of center of mass when a cylinder is generated with a non-default direction

Open kmarchais opened this issue 1 year ago • 1 comments
trafficstars

Hello, I think I am having a bug when I create a cylinder from a workplane.

>>> cq.Shape.centerOfMass(cq.Workplane("XY").cylinder(radius=1, height=10, direct=cq.Vector(1, 0, 0)).val()) 
Vector: (5.0, 6.263935600236486e-18, -5.0)
>>> cq.Shape.centerOfMass(cq.Workplane("XY").cylinder(radius=1, height=10, direct=cq.Vector(0, 1, 0)).val()) 
Vector: (-6.263935600236486e-18, 5.0, -5.0)
>>> cq.Shape.centerOfMass(cq.Workplane("XY").cylinder(radius=1, height=10, direct=cq.Vector(0, 0, 1)).val()) 
Vector: (-1.554937844271053e-16, -2.7947979049946595e-17, 0.0)

The center of mass is centered in 0 only when the direction of the cylinder is the default one (0, 0, 1). In other cases, it is not well located. I guess it comes from the following part in the Workplane.cylinder method that does not take care of the direction vector.

offset = Vector()
if not centered[0]:
    offset += Vector(radius, 0, 0)
if not centered[1]:
    offset += Vector(0, radius, 0)
if centered[2]:
    offset += Vector(0, 0, -height / 2)

s = Solid.makeCylinder(radius, height, offset, direct, angle)

kmarchais avatar May 24 '24 14:05 kmarchais

Yup, confirmed. afbeelding

adam-urbanczyk avatar May 24 '24 16:05 adam-urbanczyk