#liborth.m4
#
# library for Orthographical Projections.
#
# Alan Robert Clark a.clark@ee.wits.ac.za 16 March 2001
#
# Electromagnetic idiots use a lot of 3D projection stuff. However, we
# generally use the olde fashioned orthogonal projection. This means that
# the z-axis is oriented upwards (sky), the y-axis is oriented towards the
# right, (horizon) and the x-axis is towards the viewer. For presentation
# purposes, the x-axis is placed at 45 degrees, and distances along it are
# foreshortened *by half* for perspective reasons.
#
# lib3D which accompanies the Circuit Macros does a very good job of
# *proper* projections and transformations, but does not seem to handle
# kludgy, ``wrong'', non-mathematical projections like the orthogonal
# projection.
#
# Of course the orthogonal projection is extensively used in much of
# engineering too. The only plane that is completely true is the yz plane
# which is **always** in the plane of the paper.
#
# Hence an attempt at a few ``bolt-on'' macros for typical electromagnetic
# work. We also largely work in so-called ``spherical co-ordinates'' of (r,
# theta, phi) where theta is the angle to the z-axis (sky) and phi is the
# angle from the x-axis **to the projection** in the xy plane.
#
# Lines are drawn at 1 degree increments, hence dashed and dotted don't
# work. Not sure how to overcome this.
#
# All orthog macros need to be called from the origin. This allows 
# different origins etc. ie The first action by all macros is Orig:Here.
# As a result, all macros promise not to move the position Here after exit!
# with the obvious exception of orthogmove :-)
#
# Remember that the yaxis is traditionally rightward of the origin. In a 
# standard mathematical arrangement that would be the ***x*** axis. Hence
# another cause for confusion. :-)

divert(-1)
  libcct.m4

* Circuit_macros Version 5.0, copyright (c) 2001 J. D. Aplevich.       *
* The files of this distribution can be redistributed or modified,     *
* provided that this copyright notice is included, and provided that   *
* modifications are clearly marked to distinguish them from this       *
* distribution.  There is no warranty whatsoever for these files.      *

                                Installation directory.  You can set this to
                                the null string if you use an environment
                                variable to tell m4 where to search:
ifdef(`HOMELIB_',,
  `define(`HOMELIB_',`')')
#  `define(`HOMELIB_',`/u/aplevich/lib/')')

                                Default pic processor: gpic.
                                To make dpic -p the default, change gpic.m4
                                to pstricks.m4.
ifdef(`gpic_',,
  `ifdef(`pstricks_',,
  `ifdef(`mfpic_',,
  `include(HOMELIB_`'gpic.m4)')')')dnl
divert(-1)

ifdef(`right_',,`include(HOMELIB_`'libgen.m4)')dnl
divert(-1)

                                                  `orthogaxes(axislength)'
define(`orthogaxes',{Orig:Here; line-> up_ $1; right_ ; "$z$" above_ ;
  line -> from Orig right_ $1; " $y$" ljust_ ; 
  proj = 0.5 * 0.707 * $1 ; 
  line -> from Orig down_ proj left_ proj; right_ ; "$x$ " rjust_ below_})

                                  `orthogphicirc(r,theta,phistart,phiend)'
define(`orthogphicirc',{Orig:Here; r=$1; theta=$2; phistart=$3; phiend=$4 ;
  actualz = r * cos(theta) ; 
  onedegree = (phiend - phistart) / (360 / 2 * pi); 
  startx = 0.5* r * cos(phistart) * sin(theta); 
  starty = r * sin(phistart) * sin(theta); 
  move to Orig+(starty,actualz) ;
  move to Here - (0.707 * startx, 0.707 * startx);
  for phi = phistart to phiend by onedegree do {
    actualx = 0.5 * r * cos(phi) * sin(theta); 
    actualy = r * sin(phi) * sin(theta);
    line to Orig+(actualy,actualz) - (0.707 * actualx, 0.707 * actualx);
  }
})

                           `orthogthetacirc(r, phi, thetastart, thetaend)'
define(`orthogthetacirc',{Orig:Here;r=$1;phi=$2;thetastart=$3;thetaend=$4; 
  actualz = r * cos(thetastart) ;
  onedegree = (thetaend - thetastart) / (360 / 2 * pi);
  startx = 0.5 * r * sin(thetastart) * cos(phi); 
  starty = r * sin (thetastart) * sin(phi);
  move to Orig+(starty,actualz) ; 
  move to Here - (0.707 * startx, 0.707*startx) ; 
  for theta = thetastart to thetaend by onedegree do {
    actualz = r * cos(theta);
    actualx = 0.5 * r * sin(theta) * cos(phi);
    actualy = r * sin(theta) * sin (phi);
    line to Orig+(actualy,actualz) - (0.707 * actualx, 0.707 * actualx); 
  }
})

# Note that orthogmove requires Orig to be defined AND IT DOES NOT RESTORE
# THE POSITION!!!!
                                             `orthogmove(r, theta, phi)'
define(`orthogmove', move to Orig; r=$1; theta=$2; phi=$3;
  actualz = r * cos (theta); 
  actualx = 0.5 * r * sin(theta) * cos(phi); 
  actualy = r * sin(theta) * sin(phi);
  move to Orig+(actualy,actualz) - (0.707 * actualx, 0.707*actualx);
)

divert(0)dnl
psset_(arrowsize=1.2pt 4`,'arrowlength=1.64`,'arrowinset=0)dnl





