坐标转换:Polar to Cartesian

2015-02-03 0 935
坐标转换:Polar to Cartesian
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

遇见资源网 ruby 坐标转换:Polar to Cartesian http://www.ox520.com/16257.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务