1

I am new to Blender. I have been wondering how to draw a parametric column or cylinder with varying radius using a python script. The radius is a function of cylinder height (polynomial function). Could anyone provide examples for me to look at? Thank you.

I also wonder if the add_mesh_3d_function_surface.py will help. Thanks.

HSChan
  • 49
  • 7

1 Answers1

3

Using bmesh and screw

Make a simple bmesh edge on zx plane using poly function, then spin it around the z axis. I've added a screw modifier to do the spinning, and commented out the bmesh spin operator.

enter image description here

import bpy
import bmesh
from math import radians

def poly(x):
    return   0.2 * x * x - x + 1.3

bm = bmesh.new()

# draw on zx plane
v0 = bm.verts.new((poly(0), 0, 0))
for dz in range(1, 100):
    z = dz / 50
    v = bm.verts.new((poly(z), 0, z))
    edge = bm.edges.new((v0, v))
    v0 = v
# could spin here I've added screw mod instead
#bmesh.ops.spin(bm, geom=bm.edges, axis=(0, 0, 1), angle=radians(360), steps=16) 

bpy.ops.mesh.primitive_cube_add()
ob = bpy.context.object
me = ob.data
bm.to_mesh(me)
me.update()   
# default screw modifier spins 360 on z
screw = ob.modifiers.new("Screw", 'SCREW')
batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • Wow, nice. Thank you so much for the solution! Do you think I can do it with bezier curve? I found this smooth curve function in Blender but it looks much more intricate. – HSChan Jul 17 '18 at 21:13