1 *
2 * \$Id\$
3 *
4 * \$Log\$
5 * Revision 1.1.1.1  1995/10/24 10:21:35  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 29/03/94  15.41.23  by  S.Giani
11 *-- Author :
12       SUBROUTINE GVROT(DCOSIN,PART)
13 C.
14 C.    ******************************************************************
15 C.    *                                                                *
16 C.    *  Rotates vector from one reference system into another         *
17 C.    *  defined by the direction cosines contained in the vector      *
18 C.    *  DCOSIN. The input vector PART is overwritten.                 *
19 C.    *                                                                *
20 C.    *    ==>Called by :                                              *
21 C.    *       Author    F.Carminati **********                         *
22 C.    *                                                                *
23 C.    *                                                                *
24 C.    ******************************************************************
25 C.
26       DIMENSION PART(*),DCOSIN(*)
27 #if !defined(CERNLIB_SINGLE)
28       DOUBLE PRECISION DUX,DUY,DUZ,SINTH2,ONE,COSTH,SINTH,COSPH,SINPH
29       DOUBLE PRECISION DNORM
30 #endif
31       LOGICAL ROTATE
32       PARAMETER (ONE=1)
33 C.
34 C.    ------------------------------------------------------------------
35 C.
36       DUX      = DCOSIN(1)
37       DUY      = DCOSIN(2)
38       DUZ      = DCOSIN(3)
39       ROTATE   = .TRUE.
40       IF(ABS(DUZ).GE.0.85) THEN
41          SINTH2=DUX**2+DUY**2
42          IF(SINTH2.GT.0.) THEN
43             COSTH  = SIGN(ONE,DUZ)*SQRT(ONE-SINTH2)
44             SINTH  = SQRT(SINTH2)
45             COSPH  = DUX/SINTH
46             SINPH  = DUY/SINTH
47          ELSEIF(DUZ.GT.0.)THEN
48             ROTATE = .FALSE.
49          ELSE
50             COSTH = -1.
51             SINTH =  0.
52             COSPH =  1.
53             SINPH =  0.
54          ENDIF
55       ELSE
56          COSTH  = DUZ
57          SINTH  = SQRT((ONE+DUZ)*(ONE-DUZ))
58          DNORM  = ONE/SQRT(DUX**2+DUY**2)
59          COSPH  = DUX*DNORM
60          SINPH  = DUY*DNORM
61       ENDIF
62 *
63       IF(ROTATE) THEN
64          P1=PART(1)
65          P2=PART(2)
66          P3=PART(3)
67          PART(1)= P1*COSTH*COSPH - P2*SINPH + P3*SINTH*COSPH
68          PART(2)= P1*COSTH*SINPH + P2*COSPH + P3*SINTH*SINPH
69          PART(3)=-P1*SINTH                  + P3*COSTH
70       ENDIF
71 C
72       END