https://kavi.sblmnl.co.za/magnetically-modelling-magsafe/ Skip to content Search Search for: [ ] [Search] kavi's blog kavi's blog * instagram * facebook Menu * home * about * contact * subscribe Open Search Magnetically Modelling MagSafe [JPEG-image-447A-8BF9-00-0] MagSafe Magnets? How do they work? After writing my last post on MagSafe, I wanted to go deeper into the magnet array. What was it that had me so fascinated? It has this property, best described in video: I'd never seen this property of self alignment before and as my powers of imagination were failing me regarding how this all worked, it was time for a model.. [yogendra-singh-_c56tTiztfA-unsplash-1024x683] What? No no, wrong model (Photo credit) I'm (of course) referring to creating a magnetic model of the MagSafe magnet arrays, moving them around and seeing the magnetic fields and forces to infer what is going on. To start, I'd need to find some software to help me and that's when I came across this wonderful Python package called Magpylib: There really is a Python package for everything Setting up the MagSafe Array Digging once again into Apple's Accessory Design Guidelines (Release R21, p148), I took the measurements from the drawings, fired up Google Colab and built this model: [3d_magsafe_animation] 3D, fun Looking at the arrays edge-on, here are some pretty field lines: [2d_magsafe_field] White and black boxes show the position of the upper and lower MagSafe arrays and if we zoom into the red box and animate the upper array moving right: [2dmagfield] Squiggly wiggly field lines Now that all these cool visualizations were done, I assumed that it'd be pretty simple to calculate the forces. My assumption was wholly incorrect. There's no native way in magpylib to calculate forces! Instead of waiting for this issue to be resolved, I looked for another solution. magforce looked promising but I couldn't get it to work. Time to discard the accurate model.. Maths time, yay So with no easy way to do it, time to go back to the physics textbook and find an equation: [equation1-300x72] Oh no, way too complicated [equation2-1024x114] Ah, much better! If I simplify (using rotational symmetry) from a fancy, three-dimensional model to a 2D model and reduce the magnet dimensions to idealized "point" magnets, I can use that equation to find the forces. This isn't the best because it assumes the magnets are now hypothetical "point" magnets called magnetic dipoles. However, the model only needs to be good enough to show the self-centering property I saw in the intro video. This is kavi's blog after all, not Reviews of Modern Physics! Skipping over a bunch of Python and a helpful YouTube video, out pops this animation: [magforcesv2] Eureka, I can see the forces now! The red arrow is the one to look at. You can clearly see the force on the array pointing right when the upper array is slightly offset to the left and vice versa. That shows the forces responsible for that centering action. The black arrows show the forces on each dipole and the green arrow shows the torque direction. Enter p5.js Python was cool and all, but the animation method I used was janky as hell. I wanted something a little more interactive. That's when I found the awesome p5.js and it's incredibly cool live editor. After porting over the Python code to Javascript: [p5jsanimation] The array can be moved with the mouse or the sliders and the force lines are updated dynamically. I can't have all the fun myself though.. You can play with this too! To play around with the p5.js animation, click here (only works on desktop browsers, sorry!) To play with the Python versions (and all the source code used for making the models and animations) get them from GitHub here. Conclusion Clearly, this way of arranging magnets has some cool properties. Modelling the magnet array with visualized forces really shows the interplay between the magnets' repulsion and attraction and how it leads to the unique MagSafe attach experience. If you find other interesting properties that the model describes that you can replicate with physical devices, share it with me! Speaking of the layout of the magnets, it would be incredibly weird if no-one else has come up with this array before. That said, Apple does have this patent that appears to cover the MagSafe array for use in inductive charging. While digging, I also found this Apple patent that allows for "bimodal" devices to be built. Maybe we'll see devices that can attach to "A" or "B" devices soon! (see Magnet section here for reference). Perhaps a new USB-C MagSafe battery pack that can also be charged using MagSafe? You heard it here first folks. The Future With magpylib hopefully getting force calculations in the future, it would be cool to model the forces generated by the full 3D model. It would also be awesome to play around more with p5.js and add in proper physics simulation to the 2D version. Also, why not try modelling a "bimodal" device... If you have any questions/would like to share your experience with MagSafe, Python, JavaScript or the modelling of magnetic fields, leave a reply below. To receive an email when I publish a post, subscribe here. (Featured image remixed from this photo) Related [6a5ef554812] Published by kavi View all posts by kavi October 26, 2023 Coding googlecolab, magpylib, magsafe, python Post navigation Building the JoyAMP Portable Modular Audio Player Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment * [ ] Name * [ ] Email * [ ] Website [ ] [ ] Save my name, email, and website in this browser for the next time I comment. [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] This site uses Akismet to reduce spam. Learn how your comment data is processed. Search for: [ ] [Search] Recent Posts * Portable Modular Audio Player * Magnetically Modelling MagSafe * Building the JoyAMP * Raspberry Pi Internet Radio * Springboks at the Rugby World Cup Recent Comments * kavi on moOde Installation and Setup on Raspberry Pi * ian on moOde Installation and Setup on Raspberry Pi * kavi on Get Siri talking to Sonoff using Homebridge * Craig on Get Siri talking to Sonoff using Homebridge * Kessu on Moving from HDD to SSD Archives * October 2023 * September 2023 * July 2023 * June 2023 * April 2023 * March 2023 * November 2022 * October 2022 * September 2022 * August 2022 * December 2021 * October 2021 * September 2021 * June 2021 * May 2021 * March 2021 * January 2021 * November 2020 * October 2020 * September 2020 * August 2020 * July 2020 * June 2020 * January 2018 * November 2017 Categories * android * Apple * Audio * Automotive * Coding * DIY * Mobile Devices * Networking * Photography * Raspberry Pi * Smart Home * Uncategorized * Video * Web * Windows Meta * Log in * Entries feed * Comments feed * WordPress.org Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren. Up |