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

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[][3]
dim helix[][3]
dim gravity[][3]
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][1] = 0
axis[n][2] = cos(fi) * R
axis[n][3] = sin(fi) * R
! helix point
helix[n][1] = xCoil
helix[n][2] = cos(fi) * rTurn
helix[n][3] = sin(fi) * rTurn
! vector from helix to axis
gravity[n][1] = axis[n][1] - helix[n][1]
gravity[n][2] = axis[n][2] - helix[n][2]
gravity[n][3] = axis[n][3] - helix[n][3]
next fi
! show helix
for i = 1 to n - 1
lin_ helix[i][1], helix[i][2], helix[i][3],
helix[i + 1][1], helix[i + 1][2], helix[i + 1][3]
next i
! show helix axis and put helix as tube path
for i = 1 to n
hotspot axis[i][1], axis[i][2], axis[i][3]
put helix[i][1], helix[i][2], helix[i][3], 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,
! n, m, mask,
! 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][1], helix[i][2], helix[i][3], 0,
gravity[i][1], gravity[i][2], gravity[i][3]
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**