-
-
Notifications
You must be signed in to change notification settings - Fork 46.1k
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
adding new physics algorithm: center of mass #10743
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks super cool! Nice addition. Please consider adding either namedtuples
or dataclasses
for Particle
and Coord3D
(please change those names to suit your use case). This would make the function signature:
def center_of_mass(particles: list[Particle]) -> Coord3D:
Here is a bit of code for creating and using namedtuples
:
>>> from collections import namedtuple
>>> Particle = namedtuple("Particle", "x y z mass")
>>> p = Particle(1, 2, 3, 4)
>>> p
Particle(x=1, y=2, z=3, mass=4)
>>> p.mass
4
>>> total_mass = sum(particle.mass for particle in particles)
>>> Coord3D = namedtuple("Coord3D", "x y z")
>>> Coord3D(6, 7, 8)
Coord3D(x=6, y=7, z=8)
I went back to |
* adding new physics algorithm: center of mass * Add changes requested by the reviewer * Add changes requested by the reviewer * Update center_of_mass.py * Update center_of_mass.py --------- Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Checklist: