datsexyanon

oh boy new thing

May 3rd, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1.     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))
  2.         local initialTheta = atan(vec.z/vec.x)
  3.         local initialPhi = atan((sqrt((vec.x)^2 + (vec.z)^2))/vec.y)
  4.         r = vec:magnitude()
  5.         --Calculate new values
  6.         local newLength = r + length
  7.         local newTheta = initialTheta + theta
  8.         local newPhi = initialPhi + phi
  9.         --Convert to Cartesian
  10.         local newX = newLength * sin(newPhi) * cos(newTheta)
  11.         local newY = newLength * cos(newPhi)
  12.         local newZ = newLength * sin(newPhi) * sin(newTheta)
  13.         --set vector
  14.         local resultant = vector():set(newX, newY, newZ)
  15.        
  16.         return resultant
  17.     end
Advertisement
Add Comment
Please, Sign In to add comment