Home Forums Problems and solutions in GDL 3D modelling TUBE twisting Reply To: TUBE twisting

#3848

Hi,

The TUBE commands were designed for objects with much less twist, where some auto-correction of the profile rotation comes handy. We don’t want to fix that in the TUBE commands, that would break compatibility. There is a solution however: in a library update in version 21, the “gravity_tube” macro was added.

As you can read in the documentation, the W axis of a cross-section at each particular node of TUBE is tied to the Z axis. With a spatial helix, this makes no sense. Using “gravity_tube”, you can set this W axis freely. In your spatial helix, this gravity vector would be pointing from the path point to the axis of the helix.

Based on your example object, here is a sample code that models a bent helix nicely:

``````resol 16

! model a helix bent 180
mat = 45		! glass

rWire	= 0.002
rCoil	= 0.011
nCoil	= 18		! number of turns around axis
nTurn	= 36		! number of points in one turn
R	= 0.1		! radius of bending
dFi	= 180 / (nCoil * nTurn)

dim axis[]
dim helix[]
dim gravity[]
n = 0

for fi = 0 to 180 step dFi

n = n + 1

! compute points as a helix on a straight cylinder, then bend it
aCoil = fi / dFi * (360 / nTurn)	! angle around axis
xCoil = cos(aCoil) * rCoil		! x, y on cylinder
yCoil = sin(aCoil) * rCoil
rTurn = R - yCoil			! turn radius of vertical line on cylinder

! helix axis point
axis[n] = 0
axis[n] = cos(fi) * R
axis[n] = sin(fi) * R

! helix point
helix[n] = xCoil
helix[n] = cos(fi) * rTurn
helix[n] = sin(fi) * rTurn

! vector from helix to axis
gravity[n] = axis[n] - helix[n]
gravity[n] = axis[n] - helix[n]
gravity[n] = axis[n] - helix[n]

next fi

! show helix
for i = 1 to n - 1

lin_ helix[i], helix[i], helix[i],
helix[i + 1], helix[i + 1], helix[i + 1]

next i

! show helix axis and put helix as tube path
for i = 1 to n

hotspot axis[i], axis[i], axis[i]

put helix[i], helix[i], helix[i], 0

next i

! try TUBE
TUBE 2, n, 1 + 2 + 16 + 32,
0, 0, 901,
rWire, 360, 4001,
GET(NSP)

! try "gravity_tube"
add 4 * rCoil, 0, 0

! parameters for gravity_tube (derived from TUBE{2}):
!		top_material, bottom_material, cut_material,
!		u1, w1, s1, mat1,
!		...
!		un, wn, sn, matn,
!		x1, y1, z1, angle1, gravity1_x, gravity1_y, gravity1_z,
!		...
!		xm, ym, zm, anglem, gravitym_x, gravitym_y, gravitym_z

put mat, mat, mat,
2, n, 1 + 2 + 16 + 32,
0, 0, 901, mat,
rWire, 360, 4001, mat

for i = 1 to n

put helix[i], helix[i], helix[i], 0,
gravity[i], gravity[i], gravity[i]

next i

call "gravity_tube"

del 1
``````

PS. “gravity_tube” might give some warnings with strict error checking options, that will be corrected in the next main release.

Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE