Skip to content

Instantly share code, notes, and snippets.

@icodejs
Created April 23, 2012 18:22
Show Gist options
  • Save icodejs/2472873 to your computer and use it in GitHub Desktop.
Save icodejs/2472873 to your computer and use it in GitHub Desktop.
# Define a method to convert Cartesian (x,y) coordinates to Polar
def polar(x,y)
theta = Math.atan2(y,x) # Compute the angle
r = Math.hypot(x,y) # Compute the distance
[r, theta] # The last expression is the return value
end
# Here's how we use this method with parallel assignment
distance, angle = polar(2,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment