i missed my practicals pt.2


Works on pygame.

Install pygame using cmd: 

    pip install pygame

Download and run the code.

This is an application of Biot-Savarts law on each side using the result- 

                    B = μoNI(sinA + sinB)/4πD

     (direction is in/out of the plane)

Code finds cursor's position on the Cartesian plane and calculates the value of A, B and D accordingly from each side of polygon.

I have also converted the screen point system into cartesian system such that the center of the window now behaves as origin (0,0). Each side is 100 units and positions of vertex are found by taking parametric positions of circumcircle of the polygon (parameter being multiple of central angle (360/n)).

                  circum radius = a/sqrt(2-2cosA)


                : a = side length and A = 360/n
                : n = no of sides.

(Yes i derived this, i wasted so many goddammed hours on it, i should have just googled it, though it was a good mental exercise, got a revision of geometry, trigonometry and magnetic fields)

This idea clicked to me when i was solving questions of Magnetic Field. Well, this is what too much math and physics does to a person.

Simulation also has two buttons for increment and decrement of no. of sides.

Note: It only creates polygon which has number of sides as factor of 360. Else everything becomes a mess, also who the hell likes a heptagons🤮. 

Pro tip: 1 Gauss = 10^-4 Tesla & pi radian = 180 degrees.


(i have used Chat GPT for help with pygame, i keep forgetting how to use GUI)

(there is no actual practical for this thing)


dm

Comments

Ayush Anand said…
Jai shree krishna wow
Ekdam coder lage che
Wow..