Advertisement
rodrigosantosbr

(Physics) Centre of Mass 3 particles

Mar 27th, 2024 (edited)
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. # Define the masses and positions
  2. mass1 = 5  # Mass in kilograms
  3. mass2 = 4
  4. mass3 = 3
  5. position1 = (0, 0)  # Position in meters (x, y)
  6. position2 = (1, 2)  
  7. position3 = (2, 0)
  8.  
  9. # Calculate the center of mass (Xcm, Ycm)
  10. total_mass = mass1 + mass2 + mass3
  11. Xcm = (mass1 * position1[0] + mass2 * position2[0] + mass3 * position3[0]) / total_mass
  12. Xcm = round(Xcm, 2)
  13. Ycm = (mass1 * position1[1] + mass2 * position2[1] + mass3 * position3[1]) / total_mass
  14. Ycm = round(Ycm, 2)
  15.  
  16. # Print the results
  17. print(f"Center of Mass: ({Xcm}, {Ycm})")
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement