Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kmarchais opened this issue May 24, 2024 · 1 comment · May be fixed by #1593
Open

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

kmarchais opened this issue May 24, 2024 · 1 comment · May be fixed by #1593
Labels
bug Something isn't working

Comments

@kmarchais
Copy link
Contributor

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)
@adam-urbanczyk adam-urbanczyk added the bug Something isn't working label May 24, 2024
@adam-urbanczyk
Copy link
Member

Yup, confirmed.
afbeelding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants