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"
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.
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.
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…?
Suppose you number of sides is n and required total length is L, then you simply have: