Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
- local initialTheta = atan(vec.z/vec.x)
- local initialPhi = atan((sqrt((vec.x)^2 + (vec.z)^2))/vec.y)
- r = vec:magnitude()
- --Calculate new values
- local newLength = r + length
- local newTheta = initialTheta + theta
- local newPhi = initialPhi + phi
- --Convert to Cartesian
- local newX = newLength * sin(newPhi) * cos(newTheta)
- local newY = newLength * cos(newPhi)
- local newZ = newLength * sin(newPhi) * sin(newTheta)
- --set vector
- local resultant = vector():set(newX, newY, newZ)
- return resultant
- end
Advertisement
Add Comment
Please, Sign In to add comment