MCPcopy
hub / github.com/CadQuery/cadquery / CombinedCenter

Method CombinedCenter

cadquery/occ_impl/shapes.py:769–784  ·  view source on GitHub ↗

Calculates the center of mass of multiple objects. :param objects: A list of objects with mass

(objects: Iterable[Shape])

Source from the content-addressed store, hash-verified

767
768 @staticmethod
769 def CombinedCenter(objects: Iterable[Shape]) -> Vector:
770 """
771 Calculates the center of mass of multiple objects.
772
773 :param objects: A list of objects with mass
774 """
775 total_mass = sum(Shape.computeMass(o) for o in objects)
776 weighted_centers = [
777 Shape.centerOfMass(o).multiply(Shape.computeMass(o)) for o in objects
778 ]
779
780 sum_wc = weighted_centers[0]
781 for wc in weighted_centers[1:]:
782 sum_wc = sum_wc.add(wc)
783
784 return Vector(sum_wc.multiply(1.0 / total_mass))
785
786 @staticmethod
787 def _mass_calc_function(obj: Shape) -> Any:

Callers 2

workplaneMethod · 0.80

Calls 5

VectorClass · 0.85
computeMassMethod · 0.80
centerOfMassMethod · 0.80
multiplyMethod · 0.45
addMethod · 0.45

Tested by 1