### Author Topic: Creates a helix aka. spiral object  (Read 3186 times)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Creates a helix aka. spiral object
« on: 2006-Oct-10 »
Some simple helix variants:

Code: GLBasic [Select]
// ------------------------------------------------------------- //
// -=#  CREATEHELIX  #=-
// Creates a helix aka. spiral object
// R1    : Raduis of Helix
// R2    : Radius of Helix Intersection
// Nu    : Number of elemtents along helix
// Nv    : Number of elements around intersection
// cycles: Number or spiral repetitions
// height: Complete length of the helix
// col   : Color of Helix-Material
// ------------------------------------------------------------- //
FUNCTION CreateHelix: num, R1, R2, Nu, Nv, cycles, height, col
LOCAL du, dv, u, v, x, y, z, tx, ty, q, nu, nv
du = cycles * 360 / Nu
dv = 360 / Nv

X_OBJSTART num
FOR i=0 TO Nu-1
u = i * du
FOR j=0 TO Nv-1
v = j * dv
FOR q = 0 TO 3
nu=0; nv=0 // Use next u/next v

IF q=0 OR q=3 THEN nu=1
IF q>1 THEN nv=1
nu = MOD(q, 2)
nv=INTEGER(q / 2)
qu = u+nu*du
qv = v+nv*dv

x = R1 * COS(qu) * (1 + COS(qv) * R2/R1)
z = R1 * SIN(qu) * (1 + COS(qv) * R2/R1)
y = SIN(qv)*R2 + qu*height/(360 * cycles)
tx = (i+nu)/Nu * cycles
ty = (j+nv)/Nv
X_OBJADDVERTEX x, y, z, tx, ty, col
NEXT
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
Helicoid
Code: GLBasic [Select]
// ------------------------------------------------------------- //
// -=#  CREATEHELICOID  #=-
// Creates a helicoid - minimal surface of a helix
// R1    : Raduis of Helix
// Nu    : Number of elemtents along helix
// Nv    : Number of elements around intersection
// cycles: Number or spiral repetitions
// height: Complete length of the helix
// col   : Color of Helix-Material
// ------------------------------------------------------------- //
FUNCTION CreateHelicoid: num, R1, Nu, Nv, cycles, height, col
LOCAL du, dv, u, v, x, y, z, tx, ty, q, nu, nv
du = cycles*360 / Nu
dv = R1 / Nv

X_OBJSTART num
FOR i=0 TO Nu-1
u = i * du
FOR j=0 TO Nv-1
v = j * dv
FOR q = 0 TO 3
nu=0; nv=0 // Use next u/next v

IF q=0 OR q=3 THEN nu=1
IF q>1 THEN nv=1
nu = MOD(q, 2)
nv=INTEGER(q / 2)
qu = u+nu*du
qv = v+nv*dv

x = qv * COS(qu)
z = qv * SIN(qu)
y = qu/(cycles*360) * height
tx = (i+nu)/Nu * cycles
ty = (j+nv)/Nv
X_OBJADDVERTEX x, y, z, tx, ty, col
NEXT
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
Quote
ORIGINAL POST BY GERNOT, I moved it from another thread. -Hemlos
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)