datsexyanon

Untitled

May 3rd, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1.     function buildUprightCircle( count, donutRadius, spiralRadius, spiralCount )
  2.             for x = 1, count do
  3.                     local angle = ( x / count ) * 2 * math.pi
  4.                     local vectorVec = vector():set( donutRadius * math.cos( angle ), 0, donutRadius * math.sin( angle ) )
  5.                     local vectorPos = vector():set( vectorVec )
  6.                     --vectorVec:set_length( 1 )
  7.                     vectorPos.x = vectorPos.x-- + ( spiralRadius * vectorVec.x * math.cos( angle * spiralCount ) )
  8.                     vectorPos.y = vectorPos.y-- + ( spiralRadius * math.sin( angle * spiralCount ) )
  9.                     vectorPos.z = vectorPos.z-- + ( spiralRadius * vectorVec.z * math.cos( angle * spiralCount ) )
  10.                     vector():set( vectorPos )
  11.                     vectorpos = cartesianTransform( vectorpos, 0, 0, ((math.pi/2) * sin(angle) )
  12.                     --Do thing at vector
  13.             end
  14.     end
  15.    
  16. function cartesianTransform (vec, length, theta, phi) --Takes in a vector representing a point, a length change, 2 angle changes (one in XZ plane, one representing the angle with the Y axis (0 = up, 90 = down, 45 = flat))
  17.     local initialTheta = math.atan(vec.z/vec.x)
  18.     local initialPhi = math.atan((math.sqrt((vec.x)^2 + (vec.z)^2))/vec.y)
  19.     r = vec:magnitude()
  20.     --Calculate new values
  21.     local newLength = r + length
  22.     local newTheta = initialTheta + theta
  23.     local newPhi = initialPhi + phi
  24.     --Convert to Cartesian
  25.     local newX = newLength * math.sin(newPhi) * math.cos(newTheta)
  26.     local newY = newLength * math.cos(newPhi)
  27.     local newZ = newLength * math.sin(newPhi) * math.sin(newTheta)
  28.     --set vector
  29.     local resultant = vector():set(newX, newY, newZ)
  30.  
  31.     return resultant
  32. end
Advertisement
Add Comment
Please, Sign In to add comment