Hello,
I am trying to create a tetrahedron frame, consisting of cylinders.
Any ideas?
Richard
creating a tetrahedron frame
Moderators: jesterKing, stiv

 Posts: 7
 Joined: Mon Dec 24, 2012 12:55 pm
 Location: Breda, the Netherlands
At least I can tell you how to make tetrahedra.
There's a script named add_mesh_solid.py in scripts\addons. When the addon is active, you can create a tetrahedron with
Look at the source code so you understand how to get the right vertices. I think you'll need something like this (taken from add_mesh_solid.py)so you can use v as a basis to create cylinders withArticle of primitive_cylinder_add() in the Blender API documentation
There's a script named add_mesh_solid.py in scripts\addons. When the addon is active, you can create a tetrahedron with
Code: Select all
bpy.ops.mesh.primitive_solid_add(source='4')
Look at the source code so you understand how to get the right vertices. I think you'll need something like this (taken from add_mesh_solid.py)
Code: Select all
s = sqrt(2)/3.0
t = 1/3
u = sqrt(6)/3
v = [(0,0,1),(2*s,0,t),(s,u,t),(s,u,t)]
Code: Select all
bpy.ops.mesh.primitive_cylinder_add()

 Posts: 7
 Joined: Mon Dec 24, 2012 12:55 pm
 Location: Breda, the Netherlands
Thanks, I will take a look.
I was trying along another path, having found the code to create a tetrahedron and also some code to create a cylinder between 2 points.
But combining then does not give the correct result:
import math
import bpy
from mathutils import Vector
def doCils():
X1, Y1, Z1 = 0, 1 / math.sqrt(3),0
X2, Y2, Z2 = 0.5, 1 / (2 * math.sqrt(3)), 0
X3, Y3, Z3 = 0.5, 1 / (2 * math.sqrt(3)), 0
X4, Y4, Z4 = 0, 0, math.sqrt(2 / 3)
D1x, D1y, D1z = X2X1, Y2Y1, Z2Z1
doIt(D1x, D1y, D1z)
D2x, D2y, D2z = X3X2, Y3Y2, Z3Z2
doIt(D2x, D2y, D2z)
D3x, D3y, D3z = X4X3, Y4Y3, Z4Z3
doIt(D3x, D3y, D3z)
D4x, D4y, D4z = X4X1, Y4Y1, Z4Z1
doIt(D4x, D4y, D4z)
def doIt(dx,dy,dz):
Vaxis = Vector((dx, dy, dz)).normalized() # versor
Vobj = Vector((0,0,1)) # z axis versor
Vrot = Vobj.cross(Vaxis) # rotation axis: normal to both vecs
angle = math.acos(Vobj.dot(Vaxis)) # angle between Vaxis and Vobj
Cone = bpy.ops.mesh.primitive_cylinder_add(radius=.1)
bpy.ops.transform.rotate(value=(angle,),axis=Vrot) # rotate
doCils()
I was trying along another path, having found the code to create a tetrahedron and also some code to create a cylinder between 2 points.
But combining then does not give the correct result:
import math
import bpy
from mathutils import Vector
def doCils():
X1, Y1, Z1 = 0, 1 / math.sqrt(3),0
X2, Y2, Z2 = 0.5, 1 / (2 * math.sqrt(3)), 0
X3, Y3, Z3 = 0.5, 1 / (2 * math.sqrt(3)), 0
X4, Y4, Z4 = 0, 0, math.sqrt(2 / 3)
D1x, D1y, D1z = X2X1, Y2Y1, Z2Z1
doIt(D1x, D1y, D1z)
D2x, D2y, D2z = X3X2, Y3Y2, Z3Z2
doIt(D2x, D2y, D2z)
D3x, D3y, D3z = X4X3, Y4Y3, Z4Z3
doIt(D3x, D3y, D3z)
D4x, D4y, D4z = X4X1, Y4Y1, Z4Z1
doIt(D4x, D4y, D4z)
def doIt(dx,dy,dz):
Vaxis = Vector((dx, dy, dz)).normalized() # versor
Vobj = Vector((0,0,1)) # z axis versor
Vrot = Vobj.cross(Vaxis) # rotation axis: normal to both vecs
angle = math.acos(Vobj.dot(Vaxis)) # angle between Vaxis and Vobj
Cone = bpy.ops.mesh.primitive_cylinder_add(radius=.1)
bpy.ops.transform.rotate(value=(angle,),axis=Vrot) # rotate
doCils()
I didn't look closely at your code so I don't know why it doesn't work but it's way too complicated. Here's the code I made:And next time please use the [code]Tags.
Code: Select all
import bpy
from math import sqrt
from mathutils import Vector
def cylinder(a, b, radius=1.0):
depth = (ab).length
location = a.lerp(b, 0.5)
rotation = Vector((0, 0, 1)).rotation_difference(ab).to_euler()
bpy.ops.mesh.primitive_cylinder_add(
depth=depth,
location=location,
rotation=rotation,
radius=radius)
def tetrahedron_frame(radius=0.1):
s = sqrt(2)/3
t = 1/3
u = sqrt(6)/3
v = [(0, 0, 1), (2*s, 0, t), (s, u, t), (s, u, t)]
cylinder(Vector(v[0]), Vector(v[1]), radius=radius)
cylinder(Vector(v[0]), Vector(v[2]), radius=radius)
cylinder(Vector(v[0]), Vector(v[3]), radius=radius)
cylinder(Vector(v[1]), Vector(v[2]), radius=radius)
cylinder(Vector(v[2]), Vector(v[3]), radius=radius)
cylinder(Vector(v[3]), Vector(v[1]), radius=radius)
tetrahedron_frame()

 Posts: 7
 Joined: Mon Dec 24, 2012 12:55 pm
 Location: Breda, the Netherlands
BTW: You can add an option to scale the frame while creating.
Replacewith
cu
Mr.Yeah
Replace
Code: Select all
def tetrahedron_frame(radius=0.1):
s = sqrt(2)/3
t = 1/3
u = sqrt(6)/3
v = [(0, 0, 1), (2*s, 0, t), (s, u, t), (s, u, t)]
Code: Select all
def tetrahedron_frame(radius=0.1, scale=1.0):
s = sqrt(2)/3*scale
t = 1/3*scale
u = sqrt(6)/3*scale
v = [(0, 0, scale), (2*s, 0, t), (s, u, t), (s, u, t)]
cu
Mr.Yeah
Who is online
Users browsing this forum: Yahoo [Bot] and 4 guests