This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / GEANT321 / gdraw / gdcut.F
1 *
2 * $Id$
3 *
4 * $Log$
5 * Revision 1.1.1.1  1995/10/24 10:20:22  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 29/03/94  15.41.26  by  S.Giani
11 *-- Author :
12       SUBROUTINE GDCUT
13 C.
14 C.    ******************************************************************
15 C.    *                                                                *
16 C.    *       Draw the 4 lines obtained by the intersection            *
17 C.    *       of the cut plane (at point DCUT along axis ICUT) and     *
18 C.    *       the NSURF surfaces stored in vector SURF.                *
19 C.    *       DCUT, ICUT, NSURF, SURF are in common block GCDRAW.      *
20 C.    *                                                                *
21 C.    *    ==>Called by : GDRWSC, GDSSUR                               *
22 C.    *       Author : P.Zanarini   *********                          *
23 C.    *                                                                *
24 C.    ******************************************************************
25 C.
26 #include "geant321/gcbank.inc"
27 #include "geant321/gcdraw.inc"
28       DIMENSION SURF(2)
29       EQUIVALENCE (WS(1),SURF(1))
30       DIMENSION P(3,2),U(2),V(2),XI(2),YI(2),ZI(2),PL(3),PR(3)
31       EQUIVALENCE (PL(1),XL),(PL(2),YL),(PL(3),ZL)
32       EQUIVALENCE (PR(1),XR),(PR(2),YR),(PR(3),ZR)
33 C
34       SAVE EPS,ICUT3
35       DATA EPS/0.00001/
36 C.
37 C.    ------------------------------------------------------------------
38 C.
39 C     Let be L(XL,YL,ZL) and R(XR,YR,ZR) the extreme points of a line,
40 C     I(XI,YI,ZI) the intersection point between the line and
41 C     the cut-plane (for example Z=C, i.e. the plane normal to Z axis).
42 C     Then we have:
43 C
44 C
45 C                       (XR-XL)               (XR-XL)
46 C     XI = XL + (ZI-ZL) ------- = XL + (C-ZL) -------
47 C                       (ZR-ZL)               (ZR-ZL)
48 C
49 C
50 C                       (YR-YL)               (YR-YL)
51 C     YI = YL + (XI-XL) ------- = YL + (C-XL) -------
52 C                       (XR-XL)               (XR-XL)
53 C
54 C
55 C     ZI = C
56 C
57 C
58 C     Then we have two cases:
59 C
60 C     1.   ZL <= ZI <= ZR
61 C          i.e. the cut-plane intersects the line at I(XI,YI,ZI) :
62 C          a line is drawn between that point and next one
63 C
64 C     2.   ZL = ZR
65 C          i.e. the line is parallel to (or into) the cut-plane :
66 C          any line is drawn
67 C
68 C
69       IF (NSURF.EQ.0) GO TO 80
70 C
71       IF (ICUT.EQ.0) THEN
72          ICUT3=3
73          ICUT=3
74       ELSE
75          ICUT3=0
76       ENDIF
77 C
78       IF (ICUT.LT.1.OR.ICUT.GT.3) GO TO 80
79 C
80       DO 70  I=1,NSURF
81 C
82          ISTART=12*(I-1)+1
83          J=0
84 C
85          DO 40 L=1,4
86 C
87             IL=ISTART+(L-1)*3
88             IR=IL+3
89             IF (L.EQ.4) IR=ISTART
90             XL=SURF(IL)
91             YL=SURF(IL+1)
92             ZL=SURF(IL+2)
93             XR=SURF(IR)
94             YR=SURF(IR+1)
95             ZR=SURF(IR+2)
96 C
97             IF (ICUT3.GT.0) THEN
98 C
99 C             Transform PL and PR to have Z-axis = line of sight CTHETA,
100 C
101                SAVTHE=GTHETA
102                SAVPHI=GPHI
103                GTHETA=CTHETA
104                GPHI=CPHI
105                NGVIEW=0
106                CALL GD3D3D(PL,-1,PL,0)
107                CALL GD3D3D(PR,-1,PR,0)
108                GTHETA=SAVTHE
109                GPHI=SAVPHI
110                NGVIEW=0
111 C
112             ENDIF
113 C
114 C             Is the line parallel to the cut-plane ?
115 C
116             IF ((PL(ICUT).GE.PR(ICUT)-EPS).AND.(PL(ICUT).LE.PR(ICUT)+
117      +      EPS)) GO TO 40
118 C
119 C             No, it isn't
120 C
121             AMX=MAX(PL(ICUT),PR(ICUT))
122             AMN=MIN(PL(ICUT),PR(ICUT))
123             IF ((DCUT.LT.AMN).OR.(DCUT.GT.AMX)) GO TO 40
124 C
125             J=J+1
126 C
127             IF (ICUT.NE.3) GO TO 10
128             XI(J)=XL+(DCUT-ZL)*(XR-XL)/(ZR-ZL)
129             YI(J)=YL+(DCUT-ZL)*(YR-YL)/(ZR-ZL)
130             ZI(J)=DCUT
131             GO TO 30
132 C
133    10       IF (ICUT.NE.1) GO TO 20
134             XI(J)=DCUT
135             YI(J)=YL+(DCUT-XL)*(YR-YL)/(XR-XL)
136             ZI(J)=ZL+(DCUT-XL)*(ZR-ZL)/(XR-XL)
137             GO TO 30
138 C
139    20       CONTINUE
140             XI(J)=XL+(DCUT-YL)*(XR-XL)/(YR-YL)
141             YI(J)=DCUT
142             ZI(J)=ZL+(DCUT-YL)*(ZR-ZL)/(YR-YL)
143 C
144    30       IF (J.EQ.2) GO TO 50
145 C
146    40    CONTINUE
147 C
148          IF (J.LT.2) GO TO 70
149 C
150    50    CONTINUE
151          DO 60 IND=1,2
152             P(1,IND)=XI(IND)
153             P(2,IND)=YI(IND)
154             P(3,IND)=ZI(IND)
155    60    CONTINUE
156 C
157          IF (ICUT3.GT.0) THEN
158 C
159 C             Transform back P
160 C
161             SAVTHE=GTHETA
162             SAVPHI=GPHI
163             GTHETA=CTHETA
164             GPHI=CPHI
165             NGVIEW=0
166             CALL GD3D3D(P(1,1),-2,P(1,1),1)
167             GTHETA=SAVTHE
168             GPHI=SAVPHI
169             NGVIEW=0
170 C
171          ENDIF
172 C
173 C             Points are now in general reference system
174 C
175          CALL GDFR3D(P,-2,U,V)
176 C
177 CM             Short circuit in case of GMR
178 C
179          IF ( IGMR .EQ. 0 ) CALL GDRAWV(U,V,2)
180 CM
181    70 CONTINUE
182 C
183    80 CONTINUE
184 C
185       IF (ICUT3.GT.0) THEN
186          ICUT3=0
187          ICUT=0
188       ENDIF
189 C
190       NSURF=0
191       ISURF=1
192 C
193       END