Creating circles with same edge length.

I’m trying to create a bunch of circles with different numbers of vertices in each circle, but with the same edge length. The only way I can think to do this is through the definition of the diameter, but I can’t get anything to work. Can anyone help me? (My attempt is around line 26) Here is my script so far:

 
#Test
import Blender as b
import math
#Just initializing the variables
maxverts = 0
#This is th the length I'd like for all of my edges.
sidelength = 1
scn = b.Scene.GetCurrent()
#Until the user gives an acceptable number of max verts (in the range that Blender allows),
while (maxverts > 100) or (maxverts < 3):
 #keep asking for the maximum number of vertices.
 maxverts = input("What's the max number of verts you want?" )
#Create an empty mesh.
mesh = b.Mesh.New()
obj = scn.objects.new(mesh)
 
#Now make the meshes
#The first numer of vertices is three.
vertnumber = 3
#At this point, I make a list of all of the objects in the scene.
objectlist = []
while vertnumber <= maxverts:
 #This is a formula from geometry, look it up on google if you forgot.
 angle = ((180.0 * (vertnumber - 2))/ vertnumber)
 #This is my best guess at something that I think should work (but doesn't)
 diameter = math.cos(angle / 2) * sidelength
 print math.cos(angle/2)
 print "ANGLE =", angle, "and the vertnumber is", vertnumber, ". OH! Also, the diameter is", diameter
 #make a new circle mesh.
 mesh2 = b.Mesh.Primitives.Circle(vertnumber, diameter) 
 #make it an object, 
 obj2 = scn.objects.new(mesh2)
 #and append it to the list of created objects.
 objectlist.append(obj2)
 #Also, increase the number of vertices created for the next circle.
 vertnumber = vertnumber + 1 
#Merge all of the objects in the object list into one object,
obj.join(objectlist)
#and then delete all of the individual objects.
for object in objectlist:
 scn.objects.unlink(object)
b.Redraw()
print "DOne"

Thanks.

you could use the add primitive circle where all edges are same lenght too

and probably easier to use also ?

hope it helps

Perhaps use the parametric form of the circle eg, and if you are using math angle is radians not degrees


import math

npoints = 5 # number of vertices in circle
r = 1 # radius
for i in range(npoints):
    angle = math.pi*2*i/npoints
    x = r*math.cos(angle)
    y = r*math.sin(angle)
    vertices.append((x,y,0))




@somen:
I’ll try and see if I can get that to work. Thanks for the radians tip.

@RickyBlender:
I don’t understand. What do you mean? I already can make a circle with all its edges the same length, I need to create multiple circles, with different numbers of vertices, that all have the same edge length.

Just in case anyone ever needs to do the same thing in the future (unlikely, but possible), here’s the new version that finally works.

 
#Test
import Blender as b
import math
#Just initializing the variables
maxverts = 0
#This is th the length I'd like for all of my edges.
sidelength = 1
scn = b.Scene.GetCurrent()
#d
while (maxverts > 100) or (maxverts < 3):
 maxverts = input("What's the max number of verts you want?" )
mesh = b.Mesh.New()
obj = scn.objects.new(mesh)
 
#Now make the meshes
vertnumber = 3
objectlist = []
while vertnumber <= maxverts:
 #get the average angle in radians
 angle = ((180.0 * (vertnumber - 2))/ vertnumber) * (math.pi / 180.0)
 
 diameter =  2 * math.sqrt(((sidelength / 2.0) ** 2) + ((math.tan(angle / 2.0) * (sidelength / 2.0)) ** 2))
 print math.cos(angle/2.0), "cos(angle / 2)"
 print "ANGLE =", (angle / 2), "and the vertnumber is", vertnumber, ". OH! Also, the diameter is", diameter
 mesh2 = b.Mesh.Primitives.Circle(vertnumber, diameter)  
 obj2 = scn.objects.new(mesh2)
 objectlist.append(obj2)
 vertnumber = vertnumber + 1 
obj.join(objectlist)
for object in objectlist:
 scn.objects.unlink(object)
b.Redraw()
print "DOne"

Here’s the work that led me to that definition of the diameter. In these equations, i subdivided each exterior edge of a shape, so that the shape would be made up of many right triangles. x is the interior side created by the subdivision.

(edgelength / 2) ^ 2 + (x ^ 2) = (radius ^ 2)
((edgelength / 2) ^ 2) - (radius ^ 2) = - (x ^ 2)

x = tan(angle / 2) * (edgelength / 2)
((edgelength / 2) ^ 2) - (radius ^ 2) = - ((tan(angle / 2) * (edgelength / 2)) ^ 2)
radius ^ 2 = ((tan(angle / 2) * (edgelength / 2)) ^ 2) / ((edgelength / 2) ^ 2)
radius = sqrt(((tan(angle / 2) * (edgelength / 2)) ^ 2) / ((edgelength / 2) ^ 2))
diameter = 2 * radius

if you taking about polygon then you ca add a primitive where you can specify the radius and number of segment

i think this would be easier to calculate then doing circle edge per edge

anyway do you know how tio add a prinitive circle or polygon in python

Thanks

Yeah, I already knew that. But I needed the circles to have the same edge lengths, so I had to do all of that math. If the radius was constant, the edge lengths would change depending on the number of vertices in the circle, which I didn’t want.

there is a simple relationship between the radius and the side lenght for regular polygon

so i tough it would easy to calculate this and the add the primitive circle!

salutations

marky, you are doting the things far more complicated than they really are… Why do you need x (the red line on the drawing below), tan function, square roots, etc…?

http://www.geocities.com/elonsie/Blender/Circle.png

Suppose you number of sides is n and required total length is L, then you simply have:

angle = 2pi()/n
b = L/n
d = 2
r = b/sin(angle/2)

Regards,