strange math problem involving trig and circles

Hello

I’m trying to write a script in python, and got as far as trying to make a circle of 36 points, but I’m having problems, because either I’ve got the math wrong or cos and sin don’t work.

here’s the script I wrote:

from Blender import *
from math import *
me = NMesh.GetRaw()

for dg in range(0,360,10):
    x = 3*cos(dg)
    y = sqrt(3**2 - x**2)
    z = dg/100.00
    v = NMesh.Vert(x,y,z)
    me.verts.append(v)

NMesh.PutRaw(me, "circle", 1)
Redraw()

It doesn’t throw any exceptions, but it doesn’t graph a circle either. It graphs a half-circle strangely enough, and not by degrees of 10, but in a strange pattern:

http://www.49dollarlaser.com/untitled.JPG

and from the front(I made each point a bit higher in the loop, so you can see what order they were plotted):

http://www.49dollarlaser.com/untitled2.JPG

Well I don’t know what went wrong but that is freakin COOL! :slight_smile:

y = sqrt(32 - x2) is ALWAYS going to produce a positive number.
Do it properly with sin.

Indeed, but thats only half of the problem.

In math, sine and cosine expect radians, not degrees…

So:

x = radius * cos(angle_deg * pi/180)
y = radius * sin(angle_deg * pi/180)

will give a full circle

ok, I’ll try that in a minute

is there any way to switch it to degrees instead of radians?

ok, so I got the circles working, thanks for that, and I pretty well did what I was trying to do there, but I accidentally created this at one point, kind of interesting:

http://www.49dollarlaser.com/crazy.jpg

and another view:
http://www.49dollarlaser.com/crazy2.jpg
heh isn’t math fun?

and here’s what I was going for, a 3d parabola (kinda disappointing after that last one):
http://www.49dollarlaser.com/3dpara.jpg

and the code if anyone is interested (almost works, but you can’t see that in the picture):

from Blender import *
from math import *

me = NMesh.GetRaw()
d = 16

for dg in range(0,360,10):
    for dz in range(d):
        x = dz*cos(dg*pi/180)
        y = dz*sin(dg*pi/180)
        z = 0.1*dz**2
        v = NMesh.Vert(x,y,z)
        me.verts.append(v)
    

for h in range(d-1):
    for i in range(35):
        f = NMesh.Face()
        f.v.append(me.verts[i*d+h])
        f.v.append(me.verts[i*d+1+h])
        f.v.append(me.verts[(i+1)*d+1+h])
        f.v.append(me.verts[i*d+d+h])
        me.faces.append(f)

NMesh.PutRaw(me, "circle", 1)
Redraw()

I could fix it up but I’m to tired right now.

again, thanks everyone for the help!

When you imported the math-module, you dont have to multiply with PI()/180 anymore, i thought you could use eg math.cos(math.radians(360)), which is supposed to churn out 6,28 (which is 2*Pi)
Well, that is how it works in normal python. Haven’t programmed for blender at all…