Python Forum
Code for a circular wire??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code for a circular wire??
#1
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)
Reply
#2
Google: 'python matplotlib' + 'Biot-Savart law'
Reply
#3
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!
Reply
#4
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.
Reply
#5
Just merged threads after realizing this is the same topic. Please don't create new threads when the content is almost identical.
Reply
#6
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).
Reply
#7
Are you trying to make ASCII-art? Produce a tuple? A class? That's not specific enough.
Reply
#8
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)
Reply
#9
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/...ld-of.html
Reply
#10
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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a circular matrix with one input omnisierra 18 5,593 Oct-02-2020, 01:51 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020