Putting text on the surface of a sphere


Before using the following routine you must set the sphere position and orientation with sphinit.

Text may be written to a sphere using the routine sphtext. For the examples below:
The background is set to some value by a statement like:
erase, 60
The sphere is initialized by a statement like:
sphinit, long=-30, lat=40, rad=1, fill=40, pa=30

At some point you may want to better understand how the sph* routines handle clipping and hidden lines.


The built-in help for sphtext is:
 Write text on a sphere.
 sphtext, text, rad, lng1, lng2, lat1, lat2
   text = text string to write.               in
   rad = radius of sphere.                    in
   lng1, lng2 = longitude range of text.      in
   lat1, lat2 = latitude range of text.       in
 Keywords:
   ANG=A text angle (deg CCW).
   COLOR=c  text color.
   LINESTYLE=s  text linestyle.
   /BACK  plot text on back of sphere.
There are several important points to note when using sphtext:

Wrapping text along parallels of latitude

  window, xs=300, ys=300
  !p.position=[0,0,1,1]
  set_isoxy, -1.1, 1.1, -1.1, 1.1

  erase, 80 
  sphinit, long=-30, lat=40, rad=1, fill=140, pa=30 

  for lat=-80,80,10 do $
    sphtext,'This is a text string',1,-90,20,lat,lat+8


Wrapping text along meridians of longitude

  window, xs=300, ys=300
  !p.position=[0,0,1,1]
  set_isoxy, -1.1, 1.1, -1.1, 1.1

  erase, 80 
  sphinit, long=-30, lat=40, rad=1, fill=140, pa=30 

  for lng=-80,80,10 do $
    sphtext,'This is a text string',1,lng,lng+8,-20,80,ang=90


Writing text on the back of a sphere

sphinit, long=-30, lat=20, rad=1, fill=140, pa=30
sphlat,0,1 & sphlat,0,1,/hidd
sphtext,'The front of the sphere',1,-90,0,0,10
sphtext,'The back of the sphere',1,-90+180,0+180,0,10,/back


Writing text radially from a point on a sphere

There is one easy way to write text radially from a point, just orient the sphere to place a pole at the desired point. Something much like this is done in the second figure above. The problem is that the text becomes seriously distorted close to the pole. A solution is to write text along the equator of the sphere, and orient the sphere so that multiple equators pass through the desired radial point. The algorithm below does this. Some routines from the S1R IDL library are used.

Window setup:

 window, xs=300, ys=300
 !p.position=[0,0,1,1]
 set_isoxy, -1.1, 1.1, -1.1, 1.1
 loadct, 4
 erase, 80
Define radial point:
 azr = angle of radial point from line of sight.
 par = position angle of radial point.
 step = text angle step size.

 azr = 30    ; All these angles are in degrees here.
 par = 60    ; Some may be converted to radians below.
 step = 20
Text angles:
 s = makex(0,360-step,step)                  ; Radial angles.
 n = n_elements(s)                           ; Count.
 polrec, 1, s, x, y, /deg                    ; Correct for
 recpol, x, y*cos(azr/!radeg), r, sf, /deg   ;   foreshortening.
Find sphere center points:
 rb2ll, 0, 0, azr/!radeg, 90-s, lng, lat
Erase inside sphere:
 sphinit, fill=140, rad=1
Write text string:
 for i=0, n-1 do begin &$
   sphinit, long=-lng(i), lat=lat(i), pa=sf(i)+90+par &$
   sphtext, 'Text angle = '+string(s(i),form='(I3.3)'), $
   1,20,70,-3,3 &$
 endfor


Just for fun

   sphinit, fill=140, rad=1, lat=30, long=-30, pa=-30
   da = 360./79
   n = 0
   for lat= -80, 80, 5 do $
     for lng= 0., 359, da do begin $
     sphtext, strtrim(n,2), 1, lng,lng+3, lat, lat+3 &$
     n = (n+1) mod 10 &$
   endfor


The above is not seamless.

Return the Spherical Sketch Pad Routines main menu