坐标转换:Polar to Cartesian

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def c2p
  puts "Enter x"
  x=gets.chomp
  x=x.to_f
  puts "Enter y"
  y=gets.chomp
  y=y.to_f
  r=Math.sqrt((x**2)+(y**2))
  t=Math.atan(y/x)
  deg=(180*t)/3.14
  puts "The coordinate in polar system is ("+r.to_s+","+deg.to_s+")"
end

def p2c
  puts "Enter r"
  r=gets.chomp
  r=r.to_f
  puts "Enter angle in degree"
  t=gets.chomp
  t=t.to_f
  x=r*Math.cos((t*3.14)/180)
  y=r*Math.sin((t*3.14)/180)
  puts "The coordinate in the cartesian system is ("+x.to_s+","+y.to_s+")"
end