#!/usr/bin/env python # coding: utf-8 # # Zeroth and First Moments of Mass Example # # Find the distance $\mu$ such that the mass center is closest to the line $\hat{\mathbf{n}}$. # In[1]: import sympy as sm import sympy.physics.mechanics as me me.init_vprinting() # In[2]: m, u = sm.symbols('m, mu') # In[3]: A = me.ReferenceFrame('A') # Locations of each particle: # In[4]: p1 = A.y + A.z p2 = A.x + A.z p3 = A.x + A.y # Mass center vector: # In[5]: p_star = (m*p1 + 2*m*p2 + u*p3)/(m + 2*m + u) p_star # Define the line: # In[6]: n = (A.x + A.y + A.z)/sm.sqrt(3) n # Form a vector that has a magnitude equal to the distance of interest: # In[7]: D = p_star - (p_star.dot(n)*n) D.simplify() # In[8]: D_mag = D.magnitude().simplify() D_mag # Find $\mu$ such that # In[9]: D_mag.diff(u) # In[10]: sm.solve(D_mag.diff(u), u)[0]