# GLBasic forum

## Codesnippets => 3D-snippets => Topic started by: Hemlos on 2006-Oct-10

Title: Creates a helix aka. spiral object
Post by: Hemlos 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, colLOCAL 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_OBJENDENDFUNCTION`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, colLOCAL 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_OBJENDENDFUNCTION`
Quote
ORIGINAL POST BY GERNOT, I moved it from another thread. -Hemlos