Skip to content
Prev 77436 / 398502 Next

distance to eye in persp()

On 19-Sep-05 Robin Hankin wrote:
Wonderfully put! That's what statistics is about!

I think you may have to write your own. This is possible given
the values for the parameters xlim, ylim, zlim, r, theta, phi
(default as defined in ?persp, or explicitly user-defined),
since you can then determine the 3D coordinates of the "Eye"
relative to the (X,Y,Z) axes being plotted, after which the
distance to a particular (x,y,z) point is trivial.

E.g.

1. Coordinates of Eye relative to the centre of the box

   xE <- r*sin(theta + pi)*cos(phi)
   yE <- r*cos(theta + pi)*cos(phi)
   zE <- r*sin(phi)

2. Centre of box relative to real (0,0,0)

   xC <- mean(xlim); yC <-mean(ylim); xC <- mean(zlim)

3. Coordinates of (x,y,z) relative to Eye

   x1 <- x - xE - xC; y1 <- y - yE - yC; z1 <- z - zE - zC

4. Distance from Eye to (x,y,z)

   d = sqrt(x1^2 + y1^2 + z1^2)

(Hoping I've not got anything the wrong way round there!)

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 19-Sep-05                                       Time: 10:17:55
------------------------------ XFMail ------------------------------