坐标转换:Polar to Cartesian
发布时间:2020-12-17 04:11:29 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 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.
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 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 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |