Convert the Cartesian point (x,y) to polar (magnitude, angle) coordinates : Math « Development « Ruby






Convert the Cartesian point (x,y) to polar (magnitude, angle) coordinates


def polar(x,y)
  return Math.hypot(y,x), Math.atan2(y,x)
end

 








Related examples in the same category

1.Math functions from the Math module
2.The Math Object
3.The Math.exp function returns Euler to the power of x.
4.Call to the class method sqrt from the Math module
5.do natural logarithms (base E or Euler) and base-10 logarithms.
6.Taking Logarithms
7.Random number
8.Random seeds
9.Convert polar coordinates to Cartesian coordinates