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

Shape.compute_mass() for Compounds not reliable. #907

Open
slobberingant opened this issue Feb 20, 2025 · 0 comments
Open

Shape.compute_mass() for Compounds not reliable. #907

slobberingant opened this issue Feb 20, 2025 · 0 comments

Comments

@slobberingant
Copy link
Contributor

In Compounds with parts of sufficient complexity, the Shape.compute_mass() function returns an incorrect value.
Sample code below.

b1 = Cylinder(100,1000) - Cylinder(80, 1000) - Cylinder(90, 200).move(Rot(90)) 
b2 = Box(100,100,100)
b2.move(Pos(1000,1000,1000)) # way out of the way so no intersection.

c1 = Compound(children=[b1,b2])
print('Comparison between volume and compute_mass in Compound with 2 parts.')
print(f'b1 : {b1.volume == Shape.compute_mass(b1)}') # True
print(f'b2 : {b2.volume == Shape.compute_mass(b2)}') # True
print(f'c1 : {c1.volume == Shape.compute_mass(b1) + Shape.compute_mass(b2)}') # True
print(f'c1 : {c1.volume == Shape.compute_mass(c1)}') # False

c2 = Compound(children=[b1,])
print('Comparison between volume and compute_mass for single entity Compound.')
print(f'b1 : {b1.volume == Shape.compute_mass(b1)}') # True
print(f'b2 : {b2.volume == Shape.compute_mass(b2)}') # True
print(f'c1 : {c2.volume == Shape.compute_mass(c2)}') # True
print(f'c1 : {c2.volume == Shape.compute_mass(b1)}') # True

This only occurs when calling Shape.compute_mass() directly on a Compound. Other sections of build123d code, seem to iterate over solids or parts within a Compound and return correct values. Unfortunately the iterative process does not consider parts that intersect and may over estimate the volume if two parts occupy the same space.

Considerations:

  • Any solution should allow for a density value to be easily added so that a part weight can be returned.
  • Intersections should be clearly handled. Either with a warning or clear documentation.
  • There should be a function that will return the total volume of all parts in a Compound rather than the first level only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant