-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawCirclePack.py
More file actions
53 lines (49 loc) · 1.39 KB
/
DrawCirclePack.py
File metadata and controls
53 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import bpy
import math
CirclePoints = 12
#Construct Circle points
thetainc = 2*math.pi/float(CirclePoints)
cpositions = []
theta = 0.0
faces = []
for i in range(CirclePoints):
pos = (math.cos(theta),math.sin(theta))
cpositions.append(pos)
theta += thetainc
## if i == CirclePoints-1:
## face = (i,0,CirclePoints)
## faces.append(face)
## else:
## face = (i,i+1,CirclePoints)
## faces.append(face)
## expects already named object cpack
## that is a circle packing dictionary object
cpvertices = []
cpfaces = []
i = 0
for c in cpack:
center, radius = cpack[c]
cx = center.real
cy = center.imag
circiter = (CirclePoints+1)*i
centerposi = (CirclePoints+1)*(i+1)-1
j = 0
for pos in cpositions:
cpvertices.append((pos[0]*radius+cx,pos[1]*radius+cy, 0.0))
if j == CirclePoints-1:
face = (circiter+j,circiter,centerposi)
cpfaces.append(face)
else:
face = (circiter+j,circiter+j+1,centerposi)
cpfaces.append(face)
j += 1
cpvertices.append((cx,cy,0.0))
i += 1
meshName = "CirclePacking"
obName = "CirclePackingObj"
me = bpy.data.meshes.new(meshName)
ob = bpy.data.objects.new(obName, me)
ob.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(ob)
me.from_pydata(cpvertices,[],cpfaces)
me.update(calc_edges=True)