# Example of Coordinates

class Coordinates1

    def set_xy(x, y)
	@x = x
	@y = y
    end

    def set_rt(radius, theta)
	@x = radius * Math.cos(theta)
	@y = radius * Math.sin(theta)
    end

    def get_xy
	return [@x, @y]
    end

    def get_rt
	r = Math.sqrt((@x ** 2) + (@y ** 2))
	t = Math.acos(@x / r)
	if @y < 0
	    t = Math::PI * 2 - t
	end
	return [r, t]
    end

end

class Coordinates2

    def set_rt(radius, theta)
	@r = radius
	@t = theta
    end

    def set_xy(x, y)
	@r = Math.sqrt((x ** 2) + (y ** 2))
	@t = Math.acos(x / @r)
	if y < 0
	    @t = Math::PI * 2 - @t
	end
    end

    def get_rt
	return [@r, @t]
    end

    def get_xy
	x = @r * Math.cos(@t)
	y = @r * Math.sin(@t)
	return [x, y]
    end

end

#####
a = Coordinates1.new
a.set_xy(1.0, 2.0)
p(a)
p(a.get_xy)
p(a.get_rt)

puts

b = Coordinates1.new
b.set_rt(2.0, 4.0)
p(b)
p(b.get_xy)
p(b.get_rt)

puts

#####
a = Coordinates2.new
a.set_xy(1.0, 2.0)
p(a)
p(a.get_xy)
p(a.get_rt)

puts

b = Coordinates2.new
b.set_rt(2.0, 4.0)
p(b)
p(b.get_xy)
p(b.get_rt)

