[R] 3d polar coordinates in rgl function view3d()

Duncan Murdoch murdoch.duncan at gmail.com
Tue Oct 9 02:56:43 CEST 2012

On 12-10-08 7:12 PM, Peter Rossi wrote:
> Dear all:
> I'm enjoying using rgl and I want to set a specific viewpoint.
> I understand that view3d()  will do so by setting the 3d polar
> coordinate angles, theta and phi.

That's incorrect, see below.

> In standard polar coordinates, theta is the angle away from the X axis
> in the X-Y plane and phi (inclination angle) is the angle between the
> Z axis and the radius vector
> It appears that when you use view3d()  theta is defined as the angle
> away from the x axis in the X-Z plane and phi is the angle between the
> Y axis and the radius vector.

Those descriptions are both incomplete.  Rotations in 3D don't commute, 
so you need to give them in order:  e.g. "first rotate by x about y, 
then rotate by z about w."

I don't remember what theta and phi correspond to in those terms, but if 
you want to get fine control, set the userMatrix member of par3d() 

> When I use view3d(theta=0, phi=15), my image is flipped on the side
> with the Y axis pointing upward and the Z axis pointing toward me.
> This seems contrary to the standard definition of polar coordinates.
> I have read the rgl help files but these do not define theta or phi.
> I also looked at documentation on the rgl site to no avail.

You could also read the source code -- it's open source.

> I wonder if someone out there could enlighten me s to what I've got
> wrong or how to translate properly between rgl definition and standard
> polar coordinates.

You can't, it's not polar coordinates.  It's a sequence of rotations.

Duncan Murdoch

More information about the R-help mailing list