Hi everybody,

some days ago I had a chat with a family member about objects and their projections in lower dimensions. For example, a cylinder in 3D can look either like a circle or a rectangle in 2D when projected along the main axes. So we wondered if there was an object which 2D projections look like a circle along all three axes, but which isn’t a sphere. We came up with an intersection of three cylinders of equal radius along the main axes. Turns out such an object is called Tricylinder.

Intersecting three cylinders with the boolean function in Blender leaves the resulting mesh a bit messy, so I though I’ll try to generate such an object a bit cleaner with Python. This is my first script of this kind, I learned quite a bit, it 's a fun object, so I thought maybe I should share it.

It’s found in the “Add” menu of the scripts window. If you want to have it showing up in the Add Mesh menu, change Line 5 from “Group: ‘Add’” to “Group: ‘AddMesh’”. I didn’t put it in by default, because I don’t want to clutter people’s menu.

Here’s an image (rendered with Yaf(a)Ray, click to enlarge):

And here’s the script:

``````
#!BPY
"""
Name: 'Tricylinder'
Blender: 245
"""
__author__ = 'Sanne'
__version__ = '0.1'
__bpydoc__	= """\
A Tricylinder is a Steinmetz Solid, an intersection of three cylinders of equal radii intersecting at right angles.
"""

import Blender
from Blender import Scene, Object, Mesh
from math import cos, sin, radians

"""Generate 1/24th segment of the tricylinder """

verts = []
faces = []
alpha = 45.0/(SUBDIVISION + 1.0)

v1 = 0
for n in range(SUBDIVISION + 1):
# not needed, keep for reference

if n &gt; 0:
# not needed, keep for reference
#verts.append([a1, a1, b1])
#verts.append([a1, -a1, b1])
verts.append([a2, -a2, b2])
verts.append([a2, a2, b2])

v2 = v1 + 1
v3 = v1 + 2
v4 = v1 + 3

faces.append([v2, v1, v3, v4])

v1 += 2

else:
verts.append([a2, -a2, b2])
verts.append([a2, a2, b2])

v2 = v1 + 1
v3 = v1 + 2

faces.append([v1, v2, v3])

v1 += 1

me.verts.extend(verts)
me.faces.extend(faces)

def makeTop(scn, ob):
"""
Generate the top side (1/6th) of the tricylinder out of four segments

The newly generated tricylinder segment is the currently selected onject.
The for loop generates three copies of this segment, rotates and joins them,
thusly building the top of the tricylinder.
"""

oblist = []
for i in range(3):
Object.Duplicate(mesh=1)
tmpob = Object.GetSelected()[0]
oblist.append(tmpob)

# join temporary objects with the original segment
# and delete the temporary objects from the scene
ob.join(oblist)
for item in oblist:
ob.select(1)

def makeBody(scn, ob):
"""Generate the whole body of the tricylinder out of the top side"""

# rotate top 180 degrees around x
Object.Duplicate(mesh=1)
tmpob = Object.GetSelected()[0]

ob.join([tmpob]) # newob1
ob.select(1)

# rotate joined object 90 degrees around x
Object.Duplicate(mesh=1)
tmpob = Object.GetSelected()[0]

# rotate last tmpob 90 degrees around Z
Object.Duplicate(mesh=1)
tmpob2 = Object.GetSelected()[0]

# join all objects and clean up
ob.join([tmpob, tmpob2])
ob.select(1)

"""Generate the whole mesh"""
limit = 0.001

scn = Scene.GetCurrent()
scn.objects.selected = []

me = Mesh.New("Tricylinder")

ob = scn.objects.new(me, 'Tricylinder')

makeTop(scn, ob)
me.remDoubles(limit)

makeBody(scn, ob)
me.remDoubles(limit)

Blender.Redraw()

def main():
"""GUI function"""

PREF_SUBDIVISION = Blender.Draw.Create(3)

# list for popup content
block = []

# inputs: title, button, min/max values, tooltip
block.append(("Subdivision: ", PREF_SUBDIVISION, 0, 50, "Subdivision of 1/24th tricylinder segment"))

return

# ---------- main program --------------------
main()

``````

It is eazily done in MOI3D

Also in Blender can be done by cutting a cylinder diagonally couple of times and then rotating two copies of the resulting mesh.

Anyway!
Very nice script!

Thanks Syziph, looks very nice in MOI3D. It’s Windows only, isn’t it? Would love to try it, I’m on Linux.

I also did the object manually a few times, similar to what you described, but I got tired of it soon. So I wanted to have it at the click of a button.

I know it’s nothing special, but it was a nice way for me to learn a bit scripting and how to duplicate a part of a mesh with all faces intact in Python.

Well modeling this shape in Blender is not so complex
It took me 2:30 min to record this video.
http://rapidshare.com/files/67452421/threecylinder_modeling.avi
(avi, XVID, 2,2 KB)
(If you’re not familliar with Blender hot keys - run the video on slow motion and observe the key input in the yellow box)

Your script is a great example for learning Python, thanks!