[colug-432] python arrays help
Vince Herried
Vince at PlanetVince.com
Mon Dec 22 17:40:25 EST 2014
for some strange reason I want to create a trefoil knot.
http://en.wikipedia.org/wiki/Trefoil_knot
In blender environment I want to create vertices and edges.
I got part of it working to create the vertices but not the edges.
27 #############
28 pi=3.141592654
29 Vector = mathutils.Vector
30 width = 16
31 height = 9
32
33 verts = []
34 edges = []
35 faces = []
36
37 start=0.0
38 end=pi/2
39
40 samples = 35
41 sampsize=(end-start)/samples
42
43
44 print("samples=",samples)
45 print("start=",start)
46 print("end=",end);
47
48
49 # create the vertices and edge loops for cosine
50 for t in range (samples+1):
51 x = sin(t) + 2*sin(2*t)
52 y = cos(t) - 2*cos(2*t)
53 z = -sin(3*t)
54 print("x=",x,"y=",y,"z=",z)
55 v=[Vector(((x * scale_x), (y * scale_y), (z *
scale_z)))]
56 print("length of v=",len(v))
57 #verts.append(v)
58 verts+=v
59 print("length of verts=",len(verts))
60 if (t % 2==1):
61 edges+=[verts[t-1], verts[t]]
62 #edges.append((verts[t-1], verts[t]))
63
64 print("created the verts and edges")
65 print("len of verts=",len(verts),"len of edges=",len(edges))
line 60 - 63 ain't right. I don't know how to add the edges.
if I run it to create the mesh without the edges all is happy
if I add in the edges in the mesh add statement blender complains loudly.
An edge is of course the line between two vertices edge(0) =vert(0)-vert(1)
or is it edge[0] = vert[0]-vert[1].
Blender add mesh statement looks like:
67 mesh = bpy.data.meshes.new(name="Trefoil Knot")
68 mesh.from_pydata(verts,[],faces)
or mesh.from_pydata(verts,edges,faces) <<--- complains loudly
More information about the colug-432
mailing list