"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/manual/C03-geom" (28 Jan 2000, 20539 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2                                   Chapter 3
    3 
    4                            GEOMETRY and TRIGONOMETRY
    5 
    6                                    Summary
    7 
    8 
    9              The geometry functions provide basic support for spatial
   10              analysis in multiple dimensions. They are designed to be
   11              effective in 3D graphics applications. The following
   12              geometrical computations are covered:
   13 
   14                           o Vector Operations
   15                           o Rotations
   16                           o Plane Trigonometry
   17                           o Spherical Trigonometry
   18                           o Hyperbolic Trigonometry
   19 
   20 -----------------------------------------------------------------------------
   21 
   22  Note on Contents
   23 
   24      The geometry and trigonometry functions in the library simplify many
   25  elementary geometric computations.
   26 
   27  o  Vector Operations:
   28 
   29     crossp  ------- compute the cross-product of two 3-vectors.
   30     dotp  --------- compute the inner (dot) product of two vectors.
   31     metpr  -------- compute an inner product based on a metric matrix.
   32     scalv  -------- multiply a vector by a scalar.
   33     trvec  -------- translate a vector.
   34     leng  --------- compute the length of a vector or difference vector.
   35 
   36      Vector operations cover cross and scalar products as well as scaling
   37  and translation operations. The dimensionality of the vector is restricted
   38  only for the 3-dimensional cross-product.
   39 
   40  o  Rotations:
   41 
   42     euler  -------- rotate a set of 3-vectors using a rotation
   43                     specified by its Euler angles.
   44     rotax  -------- rotate a 3-vector about a specified axis.
   45 
   46       The function performing rotations about an axis has a mode in which
   47  rotations through a fixed angular increment can be repeated efficiently.
   48  This is useful in many 3D graphics applications.
   49 
   50  o  Trigonometry:
   51 
   52      The trigonometry functions generate solutions for the unknown elements
   53  of triangles and compute triangle areas. Functions are provided for
   54  triangles in spaces with constant curvature zero (Euclidean), positive
   55  (Spherical), and negative (Hyperbolic).
   56 
   57     Plane Trigonometry
   58 
   59     trgsas  ------- solve a plane triangle given sas.
   60     trgasa  ------- solve a plane triangle given asa.
   61     trgsss  ------- solve a plane triangle given all sides (sss).
   62     trgssa  ------- solve for all feasible solutions given ssa.
   63     trgarea  ------ find the area of a plane triangle given its sides.
   64 
   65     Spherical Trigonometry
   66 
   67     strgsas  ------ solve a spherical triangle given sas.
   68     strgasa  ------ solve a spherical triangle given asa.
   69     strgsss  ------ solve a spherical triangle given all sides (sss).
   70     strgaaa  ------ solve a spherical triangle given all angles (aaa).
   71     strgarea  ----- find the area of a spherical triangle given its
   72                     angles.
   73 
   74     Hyperbolic Trigonometry
   75 
   76     htgsas  ------- solve a hyperbolic triangle given sas.
   77     htgasa  ------- solve a hyperbolic triangle given asa.
   78     htgsss  ------- solve a hyperbolic triangle given all sides (sss).
   79     htgaaa  ------- solve a hyperbolic triangle given all angles (aaa).
   80     htgarea  ------ find the area of a hyperbolic triangle given its
   81                     angles.
   82 
   83 -------------------------------------------------------------------------------
   84 
   85  General Technical Comments:
   86 
   87      Rotations
   88 
   89      Rotations may be parameterized either by a set of Euler angles or by the
   90  axis and angle of rotation. The convention that positive rotations are right
   91  handed (anticlockwise) is consistently adopted. In addition, the y-axis is
   92  used as the rotation axis corresponding to the second Euler angle. These
   93  conventions are widely adopted, but by no means universal. Thus, the user is
   94  advised to identify the conventions employed, when an algorithm specified in
   95  terms of rotations is used.
   96 
   97      Trigonometry
   98 
   99      Plane and spherical trigonometry have many well known applications,
  100  including application to navigation problems. Spherical trigonometry can
  101  also be applied to the composition of rotations in an intuitive geometric
  102  fashion. Hyperbolic trigonometry is less common, but it has very
  103  important applications in relativistic kinematics. The geometry of
  104  velocities in special relativity is a three dimensional Lobachevsky space
  105  of constant negative curvature. Thus, hyperbolic trigonometry is a natural
  106  tool to use in analyzing transformations between inertial frames.
  107 
  108 -------------------------------------------------------------------------------
  109                           FUNCTION SYNOPSES
  110 -------------------------------------------------------------------------------
  111 
  112  Vector Operations:
  113 -------------------------------------------------------------------------------
  114 
  115 crossp
  116 
  117      Compute the cross product of two 3-vectors, h = u x v.
  118 
  119      void crossp(double *h,double *u,double *v)
  120        h = pointer to array of output 3-vector
  121        u = pointer to array of left factor 3-vector
  122        v = pointer to array of left factor 3-vector
  123            (the arrays have dimension 3 and components
  124             are stored in [x,y,z] right handed order)
  125 
  126      ------------------------------------------------------------------
  127 
  128 dotp
  129 
  130      Compute the dot product of two real vectors s = u~*v.
  131 
  132      double dotp(double *,double *v,int n)
  133        u = pointer to array of vector u
  134        v = pointer to array of vector v
  135        n = dimension (dim(u)=dim(v)=n)
  136       return value: s = u~*v.
  137 
  138      -------------------------------------------------------
  139 
  140 metpr
  141 
  142      Compute the "metric" product s = u~*A*v of vectors u and v.
  143 
  144      double metpr(double *u,double *a,double *v,int n)
  145        u = pointer to array of input vector u.
  146        v = pointer to array of input vector v.
  147        a = pointer to array of metric matrix A
  148        n = dimension of vectors (dim(u)=dim(v)=n, dim(a)=n*n)
  149       return value: s = u~*A*v.
  150 
  151      ------------------------------------------------------------
  152 
  153 scalv
  154 
  155      Multiply all components of a vector v by a scalar s, v -> s*v.
  156 
  157      void scalv(double *v,double s,int n)
  158         v = pointer to first component of vector (scaled in place,
  159              with v' = s* v )
  160         s = isotropic scale factor
  161         n = dimension of vector
  162 
  163      -----------------------------------------------------------------
  164 
  165 trvec
  166 
  167      Compute a translated vector c = a + b.
  168 
  169      void trvec(double *c,double *a,double *b,int n)
  170         c = pointer to first component of output vector
  171         a = pointer to first component of vector-a
  172         b = pointer to first component of vector-b
  173         n = dimension of vectors
  174 
  175      -----------------------------------------------------------
  176 
  177 leng
  178 
  179      Compute the length of a difference vector.
  180 
  181      #include <math.h>
  182      double leng(double *a,double *b,int n)
  183         a = pointer to first component of vector-a
  184         b = pointer to first component of vector-b
  185             ( b=NULL -> vector-b has all components equal to zero )
  186         n = dimension of vectors
  187      return value: d = length of difference vector |a - b|
  188 
  189 -------------------------------------------------------------------------------
  190 
  191  Rotations:
  192 -------------------------------------------------------------------------------
  193 
  194 euler
  195 
  196      Rotate a set of vectors, using a rotation specified by Euler angles.
  197 
  198      void euler(double *pv,int m,double a,double b,double c)
  199         pv = pointer to array containing a sequence of vector components
  200              ( [x,y,z] order for each vector )
  201         m = number of vectors in array pv (dimension=3*m)
  202         a,b,c = Euler angles of rotation R(a,b,c) about axes
  203                 z,y, and z. ( All angles in radians, with
  204                 positive angles -> anticlockwise rotations. )
  205 
  206      -----------------------------------------------------------------
  207 
  208 rotax
  209 
  210      Rotate a vector, using a rotation specified by axis and angle.
  211 
  212      void rotax(double *v,double az,double pa,double ang,int k)
  213         v = pointer to array containing vector ( components in
  214              [x,y,z] order, rotated in place )
  215         az = azimuthal angle of rotation axis
  216         pa = polar angle of rotation axis
  217         ang = angle of rotation
  218               ( All angles in radians, with positive angles
  219                  -> anticlockwise rotations. )
  220         k = control flag, with:
  221              k=0 -> compute rotation matrix from input angles
  222              k>0 -> use rotation matrix computed at last k=0 call
  223 
  224      The k>0 mode is useful in creating a set of vectors to specify an
  225      arc in three-dimensions.
  226 
  227 -------------------------------------------------------------------------------
  228  Trigonometry:
  229 -------------------------------------------------------------------------------
  230 
  231  Euclidean Plane Trigonometry:
  232 -------------------------------------------------------------------------------
  233 
  234      Note: The angle inputs and outputs are assumed to be interior
  235            angles of the triangles. The angular unit for input and
  236            output is the radian. Ranges for sides and angles are:
  237 
  238            side > 0 ; and  0 < angle < pi .
  239 
  240            The solution of triangles with two sides and an angle
  241            opposite to one of those sides given is potentially
  242            ambiguous. Depending on the inputs, there may be two,
  243            one, or no valid solutions. The function 'trgssa'
  244            returns all valid solutions.
  245 
  246      -----------------------------------------------------------------
  247 
  248 trgsas
  249 
  250      Find the remaining elements of a plane triangle given two sides
  251      and the included angle.
  252 
  253      void trgsas(double a,double g,double b,double *ans)
  254        a = side of triangle
  255        g = angle of triangle between sides a and b (radians)
  256        b = side of triangle
  257        ans = pointer to three dimensional array to be loaded with
  258              ans[0] = angle opposite side a (radians)
  259              ans[1] = side opposite angle g
  260              ans[2] = angle opposite side b (radians)
  261 
  262      --------------------------------------------------------------
  263 
  264 trgasa
  265 
  266      Find the remaining elements of a plane triangle given two angles
  267      and the included side.
  268 
  269      int trgasa(double a,double ss,double b,double *asn)
  270        a = angle of triangle (radians)
  271        ss = side of triangle between angles a and b
  272        b = angle of triangle (radians)
  273        asn = pointer to three dimensional array to be loaded with
  274              asn[0] = side opposite angle a
  275              asn[1] = angle opposite side ss (radians)
  276              asn[2] = side opposite angle b
  277       return value: input status flag with
  278                      0 -> success
  279                     -1 -> inputs rejected (a or b < 0)
  280 
  281      --------------------------------------------------------------------
  282 
  283 trgsss
  284 
  285      Find the angles of a plane triangle given its three sides.
  286 
  287      int trgsss(double a,double b,double c,double *ang)
  288      double a,b,c,*ang;
  289        a = side of triangle
  290        b = side of triangle
  291        c = side of triangle
  292        ang = pointer to three dimensional array to be loaded with
  293              ang[0] = angle opposite side a (radians)
  294              ang[1] = angle opposite side b (radians)
  295              ang[2] = angle opposite side c (radians)
  296       return value: input status flag with
  297                      0 -> success
  298                     -1 -> inputs rejected (sides violate
  299                           triangle inequality)
  300 
  301      ------------------------------------------------------------------
  302 
  303 trgssa
  304 
  305      Find possible solutions for the remaining elements of a plane
  306      triangle given two sides and an angle adjacent to only one side.
  307 
  308      int trgssa(double a,double b,double ba,double *an)
  309        a = side of triangle
  310        b = side of triangle
  311        ba = angle of triangle opposite side b
  312        an = pointer to six dimensional array to be loaded with
  313             possible solutions
  314             an[0] = third side of triangle (solution #1)
  315             an[1] = angle of triangle opposite third side (radians)
  316             an[2] = angle of triangle opposite side a (radians)
  317              (solution #2)
  318             an[3] = third side of triangle (solution #2) or 0
  319             an[4] = angle of triangle opposite third side (radians)
  320             an[5] = angle of triangle opposite side a (radians)
  321       return value: solution status flag with
  322                      0 -> at least one solution
  323                     -1 -> no valid solutions
  324 
  325      Note: If only one valid solution exists, an[3]=an[4]=an[5]=0
  326            is return as the second solution.
  327 
  328      ---------------------------------------------------------------
  329 
  330 trgarea
  331 
  332      Find the area of a plane triangle given its three sides.
  333 
  334      double trgarea(double a,double b,double c)
  335        a = side of triangle
  336        b = side of triangle
  337        c = side of triangle
  338       return value: A = area of the plane triangle
  339 
  340 -------------------------------------------------------------------------------
  341 
  342  Spherical Trigonometry:
  343 -------------------------------------------------------------------------------
  344 
  345      Note: The angle inputs and outputs are assumed to be interior
  346            angles of the triangles. The angular unit for input and
  347            output is the radian. Ranges for sides and angles are:
  348 
  349            0 < side < pi  ; and  0 < angle < pi or 0 > angle > -pi.
  350 
  351            Normally the angle inputs are assumed to be positive.
  352            However, to permit use in applications where the
  353            orientation of the triangle is significant, the
  354            functions 'stgsas' and 'stgasa' can accept negative
  355            angles as inputs provided that both angle inputs to
  356            'stgasa' have the same sign. This ensures that all
  357            interior angles of the triangle will have identical
  358            sign. Angle inputs to 'stgaaa' and 'stgarea' must be
  359            positive.
  360 
  361      ---------------------------------------------------------------------
  362 
  363 stgsas
  364 
  365      Find the remaining elements of a spherical triangle given two sides
  366      and the included angle.
  367 
  368      void stgsas(double a,double g,double b,double *ang)
  369        a = side of the triangle (radians)
  370        g = angle between sides a and b (radians)
  371        b = side of triangle (radians)
  372        ang = pointer to three dimensional array to be loaded with
  373              ang[0] -> angle opposite side a (radians)
  374              ang[1] -> side opposite angle g (radians)
  375              ang[2] -> angle opposite side b (radians)
  376 
  377      ----------------------------------------------------------------
  378 
  379 stgasa
  380 
  381      Find the remaining elements of a spherical triangle given two
  382      angles and the included side.
  383 
  384      int stgasa(double a,double c,double b,double *ang)
  385        a = angle of the triangle (radians)
  386        c = side between angles a and b (radians)
  387        b = angle of triangle (radians)
  388        ang = pointer to three dimensional array to be loaded with
  389              ang[0] -> side opposite angle a (radians)
  390              ang[1] -> angle opposite side c (radians)
  391              ang[2] -> side opposite angle b (radians)
  392      return value: input status flag with
  393                     0 -> success
  394                    -1 -> inputs rejected (angles have
  395                          opposite sign)
  396 
  397      -----------------------------------------------------------------
  398 
  399 stgsss
  400 
  401      Find the angles of a spherical triangle given its three sides.
  402 
  403      int stgsss(double a,double b,double c,double *ang)
  404        a = side of triangle (radians)
  405        c = side of triangle (radians)
  406        b = side of triangle (radians)
  407        ang = pointer to three dimensional array to be loaded with
  408              an[0] -> angle opposite side a (radians)
  409              an[1] -> angle opposite side c (radians)
  410              an[2] -> angle opposite side b (radians)
  411       return value: input status flag with
  412                      0 -> success
  413                     -1 -> inputs rejected (sides violate
  414                           triangle inequality)
  415 
  416      -------------------------------------------------------------
  417 
  418 stgaaa
  419 
  420      Find the sides of a spherical triangle given its three angles.
  421 
  422      int stgaaa(double a,double b,double c,double *ang)
  423        a = angle of triangle (radians > 0)
  424        c = angle of triangle (radians > 0)
  425        b = angle of triangle (radians > 0)
  426        ang = pointer to three dimensional array to be loaded with
  427              ang[0] -> side opposite angle a (radians)
  428              ang[1] -> side opposite angle c (radians)
  429              ang[2] -> side opposite angle b (radians)
  430       return value: input status flag with
  431                      0 -> success
  432                     -1 -> inputs rejected (angle sum <= pi)
  433 
  434      ----------------------------------------------------------------
  435 
  436 stgarea
  437 
  438      Find the area of a spherical triangle given its three angles.
  439 
  440      double stgarea(double a,double b,double c)
  441        a = angle of triangle (radians > 0)
  442        b = angle of triangle (radians > 0)
  443        c = angle of triangle (radians > 0)
  444       return value: A = area of spherical triangle
  445 
  446      Note: Each spherical triangle has a dual triangle with sides
  447            s and angles A related by
  448 
  449            s' = pi - A  for sides and  A' = pi - s  for angles.
  450 
  451 -------------------------------------------------------------------------------
  452 
  453  Hyperbolic Trigonometry:
  454 -------------------------------------------------------------------------------
  455 
  456      Note: The angle inputs and outputs are assumed to be interior
  457            angles of the triangles. The angular unit for input and
  458            output is the radian. Ranges for sides and angles are:
  459 
  460            side > 0 ; and  0 < angle < pi .
  461 
  462      -------------------------------------------------------------------
  463 
  464 htgsas
  465 
  466      Solve for the remaining elements of a hyperbolic triangle given
  467      two sides and the included angle.
  468 
  469      void htgsas(double a,double g,double b,double *an)
  470        a = side of the triangle
  471        g = angle between sides a and b (radians)
  472        b = side of triangle
  473        an = pointer to three dimensional array to be loaded with
  474             an[0] -> angle opposite side a (radians)
  475             an[1] -> side opposite angle g
  476             an[2] -> angle opposite side b (radians)
  477 
  478      --------------------------------------------------------------
  479 
  480 htgasa
  481 
  482      Solve for the remaining elements of a hyperbolic triangle given
  483      two angles and the included side.
  484 
  485      int htgasa(double a,double cc,double b,double *ans)
  486        a = angle of triangle (radians)
  487        cc = side of triangle adjacent to angles a and b
  488        b = angle of triangle (radians)
  489        ans = pointer to three dimensional array to be loaded with
  490              ans[0] -> side opposite angle a
  491              ans[1] -> angle opposite side cc
  492              ans[2] -> side opposite angle b
  493      return value: input status flag with
  494                      0 -> success
  495                     -1 -> input rejected (angle <0)
  496 
  497      ----------------------------------------------------------------
  498 
  499 htgsss
  500 
  501      Solve for the angles of a hyperbolic triangle given its three angles.
  502 
  503      int htgsss(double a,double b,double c,double *ang)
  504        a = side of triangle
  505        b = side of triangle
  506        c = side of triangle
  507        ang = pointer to three dimensional array to be loaded with
  508              ang[0] -> angle opposite side a
  509              ang[1] -> angle opposite side b
  510              ang[2] -> angle opposite side c
  511       return value: input status flag with
  512                      0 -> success
  513                     -1 -> inputs rejected (sides violate
  514                           triangle inequality)
  515 
  516      -------------------------------------------------------------
  517 
  518 htgaaa
  519 
  520      Solve for the sides of a hyperbolic triangle given three angles.
  521 
  522      int htgaaa(double a,double b,double c,double *as)
  523        a = angle of triangle (radians)
  524        b = angle of triangle (radians)
  525        c = angle of triangle (radians)
  526        as = pointer to three dimensional array to be loaded with
  527             as[0] -> side opposite angle a
  528             as[1] -> side opposite angle b
  529             as[2] -> side opposite angle c
  530       return value: input status flag with
  531                      0 -> success
  532                     -1 -> inputs rejected (angle sum >= pi)
  533 
  534      -----------------------------------------------------------------
  535 
  536 htgarea
  537 
  538      Find the area of a hyperbolic triangle given three angles.
  539 
  540      double htgarea(double a,double b,double c)
  541        a = angle of triangle (radians)
  542        b = angle of triangle (radians)
  543        c = angle of triangle (radians)
  544       return value u = area of hyperbolic triangle