       return
       
     r = @tubeRadius
+
+    x0 = xy0[i]
+    y0 = xy0[i]
     for xy, iz in xys
       z = iz*@stepZ
       x=xy[i]
       y=xy[i+1]
+
+      #vectr from the previous point to this
+      dx = x-x0
+      dy = y-y0
+      dz = @stepZ
+      x0 = x
+      y0 = y
+
+      #compute normals
+      # noraml of form
+      # xn1, 0, zn1
+      # xn1 dx + zn1 dz = 0
+      # xn1 dx = - zn1 dz
+      # zn1 = - (dx/dz) xn1
+      # #
+      # xn1^2 ( 1 + (dx/dz)^2 ) = 1
+      # xn1^2 = 1/( 1 + (dx/dz)^2 )
+      # xn1^2 = dz^2 / (dx^2+dz^2)
+      # 
+      # xn1 =   dz / sqrt(dx^2+dz^2)
+      # zn1 = - dx / sqrt(dx^2+dz^2)
+
+      qdxdz = r / Math.sqrt( dx*dx+dz*dz)
+      xn1 = dz * qdxdz
+      zn1 = -dx * qdxdz
+      
+      qdydz = r / Math.sqrt( dy*dy+dz*dz)
+      yn2 = dz * qdydz
+      zn2 = -dy * qdydz
+      
+            
       vindex = curV / 3 | 0
 
-      pushXYZ x-r,y,z
-      pushXYZ x,y+r,z
-      pushXYZ x+r,y,z
-      pushXYZ x,y-r,z
+      pushXYZ x-xn1,y,z-zn1
+      pushXYZ x,y+yn2,z+zn2
+      pushXYZ x+xn1,y,z+zn1
+      pushXYZ x,y-yn2,z-zn2
       if iz >0
         for j in [0...4]
           j1 = (j+1)%4

  container = document.getElementById("container")
  
  #
  camera = new THREE.PerspectiveCamera(27, window.innerWidth / window.innerHeight, 1, 4000)
  camera.position.z = 2750
  scene = new THREE.Scene()
  #scene.fog = new THREE.Fog 0x050505, 2000, 3500
  scene.add new THREE.AmbientLight 0x444444 

  controls = new THREE.TrackballControls  camera


    tube.addAttribute 'position', new THREE.BufferAttribute(vs, 3)
    tube.addAttribute 'index', new THREE.BufferAttribute(ixs, 1)

    #tube.offsets.push {start: 0;index: 0; count: vs.length}

    tube.computeBoundingSphere()
    return  tube
    
  step: (dz) ->
