Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buildUprightCircle( count, donutRadius, spiralRadius, spiralCount )
- for x = 1, count do
- local angle = ( x / count ) * 2 * math.pi
- local vectorVec = vector():set( donutRadius * math.cos( angle ), 0, donutRadius * math.sin( angle ) )
- local vectorPos = vector():set( vectorVec )
- --vectorVec:set_length( 1 )
- vectorPos.x = vectorPos.x-- + ( spiralRadius * vectorVec.x * math.cos( angle * spiralCount ) )
- vectorPos.y = vectorPos.y-- + ( spiralRadius * math.sin( angle * spiralCount ) )
- vectorPos.z = vectorPos.z-- + ( spiralRadius * vectorVec.z * math.cos( angle * spiralCount ) )
- vector():set( vectorPos )
- vectorpos = cartesianTransform( vectorpos, 0, 0, ((math.pi/2) * sin(angle) )
- --Do thing at vector
- end
- end
- 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 = math.atan(vec.z/vec.x)
- local initialPhi = math.atan((math.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 * math.sin(newPhi) * math.cos(newTheta)
- local newY = newLength * math.cos(newPhi)
- local newZ = newLength * math.sin(newPhi) * math.sin(newTheta)
- --set vector
- local resultant = vector():set(newX, newY, newZ)
- return resultant
- end
Advertisement
Add Comment
Please, Sign In to add comment