%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%22marimo%3E%3D0.23.9%22%2C%20%22numpy%3E%3D2.0%22%2C%20%22matplotlib%3E%3D3.9%22%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Rotating%20an%20ellipsoid%20about%20one%20axis%0A%0A%20%20%20%20%3E%20Marcos%20Duarte%2C%20Renato%20Naville%20Watanabe%3Cbr%3E%0A%20%20%20%20%3E%20%5BLaboratory%20of%20Biomechanics%20and%20Motor%20Control%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br%2F)%3Cbr%3E%0A%20%20%20%20%3E%20Federal%20University%20of%20ABC%2C%20Brazil%0A%0A%20%20%20%20%23%23%20How%20to%20use%20this%20guide%0A%0A%20%20%20%20An%20ellipsoid%20makes%20orientation%20visible%3A%20unlike%20a%20sphere%2C%20its%20unequal%20axes%20let%20us%20see%20a%20rotation.%20Predict%20the%20long-axis%20direction%20before%20running%20each%20plot%2C%20then%20compare%20a%20rotated%20point%20with%20the%20rotated%20surface.%20The%20Exercises%20have%20collapsed%20worked%20solutions%3B%20the%20independent%20Problems%20provide%20final%20answers%20only.%0A%0A%20%20%20%20**Opening%20challenge.**%20The%20surface%20is%20%24x%5E2%2B3y%5E2%2B15z%5E2%3D1%24.%20Which%20axis%20is%20longest%3F%20If%20it%20is%20rotated%20about%20%24x%24%2C%20does%20that%20longest%20axis%20move%3F%0A%0A%20%20%20%20%23%23%20Python%20setup%0A%0A%20%20%20%20NumPy%20builds%20the%20surface%20mesh%20and%20Matplotlib%20renders%20it.%20All%20coordinates%20are%20embedded%20in%20this%20file.%20No%20external%20files%20are%20needed.%20You%20need%20matrix%20multiplication%2C%20sines%20and%20cosines.%0A%0A%20%20%20%20%23%23%20From%20the%20equation%20to%20a%20surface%0A%0A%20%20%20%20Write%20the%20ellipsoid%20as%20%24(x%2Fa)%5E2%2B(y%2Fb)%5E2%2B(z%2Fc)%5E2%3D1%24.%20Its%20semiaxes%20are%20%24a%3D1%24%2C%20%24b%3D1%2F%5Csqrt3%24%20and%20%24c%3D1%2F%5Csqrt%7B15%7D%24.%20The%20sampled%20angles%20describe%20surface%20points%2C%20not%20the%20orientation%20angles%20of%20the%20whole%20body.%20A%20rotation%20acts%20on%20the%20stacked%20Cartesian%20coordinates.%0A%0A%20%20%20%20**Exercise%201.**%20Find%20the%20three%20positive%20axis%20intercepts%20and%20check%20one%20in%20the%20original%20equation.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Worked%20solution%20%E2%80%94%20Exercise%201%0A%0A%20%20%20%20The%20intercepts%20are%20%24(1%2C0%2C0)%24%2C%20%24(0%2C1%2F%5Csqrt3%2C0)%24%20and%20%24(0%2C0%2C1%2F%5Csqrt%7B15%7D)%24.%20For%20the%20second%2C%20%243(1%2F%5Csqrt3)%5E2%3D1%24.%20The%20%24x%24%20semiaxis%20is%20longest%2C%20and%20rotation%20about%20%24x%24%20leaves%20it%20fixed.%0A%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20%23%20'%25matplotlib%20notebook'%20command%20supported%20automatically%20in%20marimo%0A%20%20%20%20plt.rcParams%5B'figure.figsize'%5D%3D10%2C10%0A%20%20%20%20fig%20%3D%20plt.figure(figsize%3Dplt.figaspect(1))%20%20%23%20Square%20figure%0A%20%20%20%20ax%20%3D%20fig.add_subplot(111%2C%20projection%3D'3d')%0A%20%20%20%20ax.set_box_aspect((1%2C%201%2C%201))%0A%0A%20%20%20%20coefs%20%3D%20(1%2C%203%2C%2015)%20%20%23%20Coefficients%20in%20a0%2Fc%20x**2%20%2B%20a1%2Fc%20y**2%20%2B%20a2%2Fc%20z**2%20%3D%201%0A%20%20%20%20%23%20Radii%20corresponding%20to%20the%20coefficients%3A%0A%20%20%20%20rx%2C%20ry%2C%20rz%20%3D%201%2Fnp.sqrt(coefs)%0A%0A%20%20%20%20%23%20Set%20of%20all%20spherical%20angles%3A%0A%20%20%20%20u%20%3D%20np.linspace(0%2C%202%20*%20np.pi%2C%2030)%0A%20%20%20%20v%20%3D%20np.linspace(0%2C%20np.pi%2C%2030)%0A%0A%20%20%20%20%23%20Cartesian%20coordinates%20that%20correspond%20to%20the%20spherical%20angles%3A%0A%20%20%20%20%23%20(this%20is%20the%20equation%20of%20an%20ellipsoid)%3A%0A%20%20%20%20x%20%3D%20rx%20*%20np.outer(np.cos(u)%2C%20np.sin(v))%0A%20%20%20%20y%20%3D%20ry%20*%20np.outer(np.sin(u)%2C%20np.sin(v))%0A%20%20%20%20z%20%3D%20rz%20*%20np.outer(np.ones_like(u)%2C%20np.cos(v))%0A%0A%0A%20%20%20%20xr%20%3D%20np.reshape(x%2C%20(1%2C-1))%0A%20%20%20%20yr%20%3D%20np.reshape(y%2C%20(1%2C-1))%0A%20%20%20%20zr%20%3D%20np.reshape(z%2C%20(1%2C-1))%0A%0A%20%20%20%20alpha%20%3D%20np.pi%2F3%0A%0A%20%20%20%20RX%20%3D%20np.array(%5B%5B1%2C0%2C0%5D%2C%5B0%2Cnp.cos(alpha)%2C-np.sin(alpha)%5D%2C%5B0%2Cnp.sin(alpha)%2Cnp.cos(alpha)%5D%5D)%0A%20%20%20%20print(RX)%0A%20%20%20%20rRotx%20%3D%20RX%40np.vstack((xr%2Cyr%2Czr))%0A%0A%20%20%20%20%23%20Plot%3A%0A%20%20%20%20ax.plot_surface(np.reshape(rRotx%5B0%2C%3A%5D%2C(30%2C30))%2C%20np.reshape(rRotx%5B1%2C%3A%5D%2C(30%2C30))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20np.reshape(rRotx%5B2%2C%3A%5D%2C(30%2C30))%2C%20rstride%3D4%2C%20cstride%3D4%2C%20color%3D'b')%0A%0A%20%20%20%20plt.xlabel('X')%0A%20%20%20%20plt.ylabel('Y')%0A%20%20%20%20%23%20Adjustment%20of%20the%20axes%2C%20so%20that%20they%20all%20have%20the%20same%20span%3A%0A%20%20%20%20max_radius%20%3D%20max(rx%2C%20ry%2C%20rz)%0A%20%20%20%20for%20axis%20in%20'xyz'%3A%0A%20%20%20%20%20%20%20%20getattr(ax%2C%20'set_%7B%7Dlim'.format(axis))((-max_radius%2C%20max_radius))%0A%0A%20%20%20%20plt.show()%0A%20%20%20%20return%20(np%2C)%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20mm%20%3D%20np.array(%5B2.71%2C%2010.22%2C%2026.52%5D)%0A%20%20%20%20lm%20%3D%20np.array(%5B2.92%2C%2010.10%2C%2018.85%5D)%0A%20%20%20%20fh%20%3D%20np.array(%5B5.05%2C%2041.90%2C%2015.41%5D)%0A%20%20%20%20mc%20%3D%20np.array(%5B8.29%2C%2041.88%2C%2026.52%5D)%0A%20%20%20%20ajc%20%3D%20(mm%20%2B%20lm)%2F2%0A%20%20%20%20kjc%20%3D%20(fh%20%2B%20mc)%2F2%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Rotated%20points%20and%20anatomical%20landmarks%0A%0A%20%20%20%20The%20final%20cell%20also%20retains%20four%20anatomical%20landmark%20coordinates%20from%20the%20original%20example.%20The%20ankle%20and%20knee%20centres%20are%20the%20midpoints%20of%20the%20malleoli%20and%20condyles.%20These%20are%20positions%3B%20the%20difference%20of%20the%20centres%20is%20a%20direction%20from%20which%20a%20segment%20basis%20can%20be%20built.%0A%0A%20%20%20%20**Exercise%202.**%20At%20%2460%5E%5Ccirc%24%20about%20%24x%24%2C%20find%20the%20image%20of%20%24(0%2C0%2C1)%24%20and%20check%20its%20length.%20Then%20calculate%20the%20ankle%20centre%20from%20the%20supplied%20malleoli.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Worked%20solution%20%E2%80%94%20Exercise%202%0A%0A%20%20%20%20The%20last%20column%20of%20%24R_x%24%20is%20%24(0%2C-%5Csin60%5E%5Ccirc%2C%5Ccos60%5E%5Ccirc)%3D(0%2C-%5Csqrt3%2F2%2C1%2F2)%24%2C%20with%20squared%20length%20%243%2F4%2B1%2F4%3D1%24.%20The%20ankle%20centre%20is%20%24(2.815%2C10.160%2C22.685)%24%20cm.%20The%20knee%20centre%20is%20%24(6.670%2C41.890%2C20.965)%24%20cm%3B%20keep%20the%20centimetre%20units%20when%20comparing%20with%20other%20datasets.%0A%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Checkpoint%20questions%0A%0A%20%20%20%201.%20What%20properties%20distinguish%20a%20rotation%20from%20scaling%3F%0A%20%20%20%202.%20Does%20transposing%20a%20rotation%20undo%20it%3F%0A%20%20%20%203.%20Are%20three%20orthogonal%20unit%20vectors%20automatically%20right-handed%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%0A%20%20%20%201.%20A%20rotation%20preserves%20lengths%20and%20angles%20and%20has%20determinant%20%2B1.%20Scaling%20generally%20changes%20lengths.%202.%20Yes%2C%20for%20a%20proper%20orthogonal%20rotation%20matrix.%203.%20No%3B%20the%20determinant%20must%20also%20be%20%2B1.%0A%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%20Problems%0A%0A%20%20%20%201.%20Rotate%20%24(0%2C1%2C0)%24%20by%20%2460%5E%5Ccirc%24%20about%20the%20fixed%20positive%20%24x%24%20axis.%0A%20%20%20%202.%20Give%20the%20ellipsoid%E2%80%99s%20volume%20and%20say%20whether%20rotation%20changes%20it.%0A%20%20%20%203.%20Let%20%24R%3DR_z(90%5E%5Ccirc)R_x(90%5E%5Ccirc)%24.%20Give%20%24R(0%2C1%2C0)%24%20and%20compare%20it%20with%20the%20reversed%20order.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Final%20answers%20to%20the%20problems%0A%0A%20%20%20%201.%20%24(0%2C1%2F2%2C%5Csqrt3%2F2)%24.%0A%20%20%20%202.%20%244%5Cpi%2F(3%5Csqrt%7B45%7D)%5Capprox0.6244%24%20cubic%20coordinate%20units%3B%20unchanged.%0A%20%20%20%203.%20%24(0%2C0%2C1)%24%3B%20the%20reversed%20order%20gives%20%24(-1%2C0%2C0)%24.%0A%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%20Go%20deeper%0A%0A%20%20%20%20%5BTransformation3D%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Ftransformation_3d.py)%20develops%20active%2Fpassive%20conventions%20and%20sequence-dependent%20angles.%20%5BCoordinateSystem%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fcoordinate_system.py)%20connects%20the%20marker%20calculations%20below%20the%20surfaces%20to%20anatomical%20frames.%0A%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20%5BLynch%20and%20Park%3A%20rotation%20matrices%5D(https%3A%2F%2Fmodernrobotics.northwestern.edu%2Fnu-gm-book-resource%2F3-2-1-rotation-matrices-part-1-of-2%2F)%20explains%20the%20orthogonality%20and%20determinant%20tests%20used%20here.%0A%0A%20%20%20%20%23%23%20References%0A%0A%20%20%20%20-%20Lynch%20KM%2C%20Park%20FC%2C%20*Modern%20Robotics*%2C%20Chapter%203%3A%20rotation%20matrices%20and%20rigid%20configurations.%0A%0A%20%20%20%20-%20Original%20BMC%20ellipsoid%20and%20marker%20examples%2C%20preserved%20from%20the%20paired%20Jupyter%20notebook.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
9c371b19431764aa3e92e1859a5a7165