Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot polar coordinates in R?

Suppose that (x(t),y(t)) has polar coordinates(√t,2πt). Plot (x(t),y(t)) for t∈[0,10].

There is no proper function in R to plot with polar coordinates. I tried normal plot by giving, x=√t & y=2πt. But resultant graph was not as expected.

I got this question from "Introduction to Scientific Programming  and Simulation using r"and the book is telling the plot should be spiral.

like image 974
Athul Avatar asked Mar 22 '15 10:03

Athul


People also ask

How do you find polar coordinates in r?

To convert from Cartesian Coordinates (x,y) to Polar Coordinates (r,θ): r = √ ( x2 + y2 ) θ = tan-1 ( y / x )

What does r equal in polar coordinates?

The coordinate r is the length of the line segment from the point (x,y) to the origin and the coordinate θ is the angle between the line segment and the positive x-axis.


1 Answers

Make a sequence:

t <- seq(0,10, len=100)  # the parametric index
# Then convert ( sqrt(t), 2*pi*t ) to rectilinear coordinates
x = sqrt(t)* cos(2*pi*t) 
y = sqrt(t)* sin(2*pi*t)
png("plot1.png");plot(x,y);dev.off()

enter image description here

That doesn't display the sequential character, so add lines to connect adjacent points in the sequence:

png("plot2.png");plot(x,y, type="b");dev.off()

enter image description here

like image 98
IRTFM Avatar answered Sep 21 '22 07:09

IRTFM