Python Forum
Code for a circular wire?? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Code for a circular wire?? (/thread-6609.html)

Pages: 1 2


Code for a circular wire?? - hiphopopot0mous - Nov-29-2017

Hey everyone, so I'm trying to create a code for a circular wire carrying a current from which I can then apply the Biot-Savart law to. However, due to my lack of coding knowledge I'm stumped on how to exactly define my wire (which has a radius of 1). Below was my thought process.

theta = range(0, 2*math.pi)
r = 1.0 #Radius
x = r*math.cos(theta)
y = r*math.sin(theta)
wire = 2*math.pi*math.sqrt((x**2)+(y**2))

This may appear instantly wrong to those of you with decent coding experience. Any suggestions would be greatly appreciated! (I just need a defined circumference representing my wire but I don't know how to properly code theta to include points between 0 and 2pi)


[split2] Code for a circular wire?? - Larz60+ - Nov-29-2017

Google: 'python matplotlib' + 'Biot-Savart law'


How to define a grid? - hiphopopot0mous - Nov-30-2017

I'm trying place a circular ring at the origin of (0,0,0) on a grid ranging from (-2,-2,-2) to (2,2,2). *Without the use of numpy*

def wire(radius, theta):
for theta in range(0, 2*math.pi):
r = 1.0
x = r*math.cos(theta)
y = r*math.sin(theta)
radius = math.sqrt((x**2)+(y**2))

return wire

Due to my lack of experience coding I'm not sure how to implement this grid. Any feedback would be greatly appreciated!


RE: How to define a grid? - micseydel - Nov-30-2017

What exactly do you want your result to be? I don't know what it means to "place a circular ring" or "define a grid" in Python. If this is homework, posting the verbatim assignment will probably help us to help you.


RE: Code for a circular wire?? - micseydel - Nov-30-2017

Just merged threads after realizing this is the same topic. Please don't create new threads when the content is almost identical.


RE: Code for a circular wire?? - hiphopopot0mous - Nov-30-2017

A circular ring of radius one unit with the center of the loop at (0,0,0). The ring is flat in the X-Y plane. Place this ring on a grid range from (-2,-2,-2) to (2,2,2).


RE: Code for a circular wire?? - micseydel - Nov-30-2017

Are you trying to make ASCII-art? Produce a tuple? A class? That's not specific enough.


RE: Code for a circular wire?? - hiphopopot0mous - Nov-30-2017

What I'm trying to do is apply the Biot-Savart law to my ring (which would carry 1 unit of current). First I need to define this ring to my desired grid range so I can ultimately save the data and present the magnetic field as a vector field. Right now I just need to create an image of this ring on the grid. (Sorry for my lack of basic coding knowledge)


RE: Code for a circular wire?? - Larz60+ - Nov-30-2017

Google: 'python matplotlib' + 'Biot-Savart law'
you will find lots o examlpes
like: https://gist.github.com/mick001/5c805433046fa31aec36
and with graphics: http://firsttimeprogrammer.blogspot.com/2015/05/biot-savart-law-magnetic-field-of.html


RE: Code for a circular wire?? - sparkz_alot - Nov-30-2017

I'm still confused, if your 'ring' is flat on an x, y grid, your coordinates are wrong. The 'x' axis would be -2, 0, 2 and the 'y' axis would be 2, 0, -2.  From the way you describe it, it sounds as if you are trying to create a 'unit circle'. This is a good place to start in order to get the the formula(s) involved: The Unit Circle. You will then need to convert the formula(s) to a form recognizable by Python. This can be done without Numpy. Displaying the grid on the other hand would not be as easy, For instance, Matplotlib uses Numpy. You could, I suppose, with a little work, use Python's builtin Turtle  Tongue