# Coordinate conversion:Polar to Cartesian and vice versa

Page 1 of 1

## 0 Replies - 323 Views - Last Post: 20 March 2009 - 02:23 PM

### #1 atik97

• ???

Reputation: 144
• Posts: 715
• Joined: 16-September 08

# Coordinate conversion:Polar to Cartesian and vice versa

Posted 20 March 2009 - 02:23 PM

Description:
```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

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }