Created
April 23, 2012 18:22
-
-
Save icodejs/2472873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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