
begin procedure draw-region
  define integer n
  let n size(xarea)
  define real poly[n,2]
  let poly[1] xarea
  let poly[2] yarea
  g\poly poly /var /fill dark_grey
end procedure draw-region

@ window_tools
@ window_init

define double plotsize mapxsize mapysize
if exist(xarea)  del /var xarea yarea
define double xarea[9] yarea[9] /global
define char*15 myra mydec

! === First PDF ========================================================

let aspect_ratio yes
let aspect 1
let inter 0.2 0.3

let mapxsize 10*pi/180
let mapysize  6*pi/180
let xarea -mapxsize 0 +mapxsize +mapxsize +mapxsize 0 -mapxsize -mapxsize -mapxsize  ! [rad]
let yarea +mapysize +mapysize +mapysize 0 -mapysize -mapysize -mapysize 0 +mapysize  ! [rad]

let myra 20 /sexa h d
let mydec 50 /sexa d d

g\set mark 5 4 0.3 0
g\set char 0.7
pen /we 2

! --- First plot: (x,y) projected plane --------------------------------

clear
@ window_xy 2 2 1

let plotsize 15*pi/180
limits -plotsize plotsize -plotsize plotsize /rev x
g\set char 0.4
box /unit d
label "x [deg]" /x
label "y [deg]" /y 2.5
g\draw text 0 0.3 "2D projected plane" /box 8

@ draw-region

! x=0 and y=0 axes
pen /col blue
g\draw text -1.1*pi/180 1.1*pi/180 "(x\d0,y\d0)=(0,0)" 6 /user
g\set mark * * 0.6 *
g\draw mark 0 0 /user
g\set mark * * 0.3 *
g\draw relo -plotsize 0 /user
g\draw line +plotsize 0 /user
g\draw relo 0 -plotsize /user
g\draw line 0 +plotsize /user
pen /col foreground

! --- Second plot: (phi,theta) native sphere ---------------------------

! clear
@ window_xy 2 2 2

let plotsize 70
limits -plotsize plotsize -plotsize plotsize deg /rev x
box n n n /unit d
g\set char 0.4
g\draw text 0 0.3 "3D native sphere" /box 8

set system eq 2000
projection 0 0 /type ortho
g\convert 0 0 /type cartes /var xarea yarea /unit rad /system eq 2000
@ draw-region

projection 0 0 0 /type ortho
grid 20
pen /col web_green
grid 210  ! Draw only the Equator and 0-meridian
g\draw mark 0 0 /user
g\draw text -0.1 0.1 "(\gf\d0,\gq\d0)=(0,0)" 6 /user
g\set char 0.7
g\draw text 1.1 0 "\gf" /user
g\draw text 0 1.1 "\gq" /user
pen /col foreground

! --- Third plot: (alpha,delta) celestial sphere (non rotated) ---------

! clear
@ window_xy 2 2 3

let plotsize 70
limits -plotsize plotsize -plotsize plotsize deg /rev x
box n n n /unit d
g\set char 0.4
g\draw text 0 0.3 "3D celestial sphere" /box 8

@ draw-region

projection myra mydec 20 /type ortho
grid 20
pen /col web_green
g\draw mark 0 0 /user
pen /col red
grid 210  ! Draw only the Equator and 0-meridian
g\set char 0.7
g\draw text 1.05 -0.4 "\ga" /user
g\draw text -0.1 0.4 "\gd" /user
pen /col foreground

! --- Fourth plot: (alpha,delta) celestial sphere (rotated) ------------

! clear
@ window_xy 2 2 4

let plotsize 70
limits -plotsize plotsize -plotsize plotsize deg /rev x
box n n n /unit d
g\set char 0.4
g\draw text 0 0.3 "3D celestial sphere" /box 8

! Draw the area rotated from native sphere to celestial
set system eq 2000
projection 0 0 0 /type ortho
g\convert myra mydec 20 /type ortho /var xarea yarea /unit rad /system eq 2000
@ draw-region

! Compute the reference position
define double xref yref
let xref 0
let yref 0
g\convert myra mydec 20 /type ortho /var xref yref /unit rad /system eq 2000

projection 0 0 0 /type ortho
grid 20
pen /col red
grid 300  ! Draw only the Equator and 0-meridian
g\draw mark xref yref /user
g\draw text xref+0.1 yref "(\ga\d0,\gd\d0)" 4 /user
g\draw text -0.2 0.1 "(0,0)" /user
g\set char 0.7
g\draw text 1.1 0 "\ga" /user
g\draw text 0 1.1 "\gd" /user
pen /col foreground

! ----------------------------------------------------------------------

hard greg-projections-formalism.pdf /dev epdf /over

pause

! === Second PDF =======================================================

let aspect_ratio yes
let aspect 1
let inter 0.25 0.3

let mapxsize 10*pi/180
let mapysize  6*pi/180
let xarea -mapxsize 0 +mapxsize +mapxsize +mapxsize 0 -mapxsize -mapxsize -mapxsize  ! [rad]
let yarea +mapysize +mapysize +mapysize 0 -mapysize -mapysize -mapysize 0 +mapysize  ! [rad]

let myra 50 /sexa h d
let mydec 0 /sexa d d

g\set mark 5 4 0.3 0
g\set char 0.7
pen /we 2

! --- First plot: (x,y) GLS projected plane ----------------------------

clear
@ window_xy 2 2 1

let plotsize 40*pi/180
limits -plotsize plotsize -plotsize plotsize /rev x
g\set char 0.4
box /unit d
label "x\\dGLS\\u [deg]" /x
label "y\\dGLS\\u [deg]" /y 3
g\draw text 0 0.3 "2D GLS projected plane" /box 8

@ draw-region

! x=0 and y=0 axes
pen /col blue
g\draw text -2.5 2.5 "(0,0)" 6 /user deg
g\set mark * * 0.5 *
g\draw mark 0 0 /user
g\set mark * * 0.3 *
g\draw relo -plotsize 0 /user
g\draw line +plotsize 0 /user
g\draw relo 0 -plotsize /user
g\draw line 0 +plotsize /user
pen /col foreground


! --- Second plot: (x,y) SFL projected plane ---------------------------

@ window_xy 2 2 2

define real delta0
let delta0 30*pi/180

let plotsize 40*pi/180
limits -plotsize plotsize -plotsize+delta0 +plotsize+delta0 /rev x
g\set char 0.4
box /unit d
label "x\\dSFL,0\\u [deg]" /x
label "y\\dSFL,0\\u [deg]" /y 3
g\draw text 0 0.3 "2D SFL projected plane" /box 8

let yarea yarea+delta0
@ draw-region

! x=0 and y=0 axes
pen /col blue
g\draw text -2.5 2.5 "(0,0)" 6 /user deg
g\set mark * * 0.5 *
g\draw mark 0 0 /user
g\set mark * * 0.3 *
g\draw relo user_xmin 0 /user
g\draw line user_xmax 0 /user
g\draw relo 0 user_ymin /user
g\draw line 0 user_ymax /user
pen /col foreground

! --- Third plot: (phi,theta) native sphere ----------------------------

@ window_xy 2 2 3

let plotsize 70
limits -plotsize plotsize -plotsize plotsize deg /rev x
box n n n /unit d
g\set char 0.4
g\draw text 0 0.3 "3D native sphere" /box 8

set system eq 2000
projection 0 0 /type ortho
g\convert 0 0 /type cartes /var xarea yarea /unit rad /system eq 2000
@ draw-region

projection 0 0 0 /type ortho
grid 20
pen /col web_green
grid 210  ! Draw only the Equator and 0-meridian
g\draw mark 0 0 /user
g\draw text -0.1 0.1 "(\gf\d0,\gq\d0)=(0,0)" 6 /user
g\set char 0.7
g\draw text 1.1 0 "\gf" /user
g\draw text 0 1.1 "\gq" /user
pen /col foreground

! --- Third plot: (alpha,delta) celestial sphere (non rotated) ---------

! clear
@ window_xy 2 2 4

let plotsize 70
limits -plotsize plotsize -plotsize plotsize deg /rev x
box n n n /unit d
g\set char 0.4
g\draw text 0 0.3 "3D celestial sphere" /box 8

@ draw-region

projection myra mydec 0 /type ortho
grid 20
pen /col web_green
g\draw mark 0 0 /user
pen /col red
grid 210  ! Draw only the Equator and 0-meridian
g\draw text -0.05 0.1 "(\ga\d0,0)" 6 /user
g\set char 0.7
g\draw text 1.1 0 "\ga" /user
g\draw text 0 1.1 "\gd" /user
pen /col foreground

! ----------------------------------------------------------------------

hard greg-projections-gls2sfl.pdf /dev epdf /over
