1 *
2 * \$Id\$
3 *
4 * \$Log\$
5 * Revision 1.1.1.1  1995/10/24 10:19:41  cernlib
6 * Geant
7 *
8 *
9 #include "geant321/pilot.h"
10 *CMZ :  3.21/02 29/03/94  15.41.31  by  S.Giani
11 *-- Author :
12       SUBROUTINE CGBFIT(FACE,ABCD,NT)
13 ************************************************************************
14 *                                                                      *
15 *     Name: CGBFIT                                                     *
16 *     Author: E. Chernyaev                       Date:    15.03.89     *
17 *                                                Revised: S.Giani 1992 *
18 *                                                                      *
19 *     Function: Find all intersection points of face with plane        *
20 *                                                                      *
21 *     References: none                                                 *
22 *                                                                      *
23 *     Input: FACE(*) - face                                            *
24 *            ABCD(4) - plane                                           *
25 *                                                                      *
26 *     Output: NT - number of intersections                             *
27 *                                                                      *
28 *                                                                      *
29 ************************************************************************
30 #include "geant321/cggpar.inc"
31 #include "geant321/cgcedg.inc"
32 #include "geant321/cgdelt.inc"
33       REAL      FACE(*),ABCD(4)
34 #if !defined(CERNLIB_SINGLE)
35       DOUBLE PRECISION  A,B,C,D
36 #endif
37       INTEGER   KCG(6)
38       DATA      KCG/KCGX1,KCGY1,KCGZ1,KCGX2,KCGY2,KCGZ2/
39 *-
40       ERROR  = EEWOR
41       A      = ABCD(1)
42       B      = ABCD(2)
43       C      = ABCD(3)
44       D      = ABCD(4)
45 *      D1=0
46 *      D2=0
47       XDELT  = FACE(KCGBB)*C - B*FACE(KCGCC)
48       YDELT  = FACE(KCGCC)*A - C*FACE(KCGAA)
49       ZDELT  = FACE(KCGAA)*B - A*FACE(KCGBB)
50       K      = 1
51       IF (ABS(YDELT) .GT. ABS(XDELT))           K = 2
52       IF (ABS(ZDELT) .GT. ABS(DELTA(K)))        K = 3
53       IF(ABS(DELTA(K)).LT.ERROR)RETURN
54       DD     = 1./ABS(DELTA(K))
55       DELTA(1)  = DELTA(1) * DD
56       DELTA(2)  = DELTA(2) * DD
57       DELTA(3)  = DELTA(3) * DD
58       KCG1   = KCG(K)
59       KCG2   = KCG(K+3)
60 *        F I N D   I N T E R S E C T I O N S   P O I N T S
61       J      = LCGFAC - LCGEDG
62       NT     = 0
63       NEDGE  = FACE(KCGNE)
64       DO 600 NE=1,NEDGE
65         J      = J + LCGEDG
66         D1     = A*FACE(J+KCGX1) + B*FACE(J+KCGY1) + C*FACE(J+KCGZ1) + D
67         D2     = A*FACE(J+KCGX2) + B*FACE(J+KCGY2) + C*FACE(J+KCGZ2) + D
68         IF (ABS(D1) .LE. ERROR)         D1 = 0.
69         IF (ABS(D2) .LE. ERROR)         D2 = 0.
70         IF (D1*D2 .GT. 0.)              GOTO 600
71         NT     = NT + 1
72         IF (D1.EQ.0. .AND. D2.EQ.0.)    GOTO 500
73         IF (D1.LT.0. .OR.  D2.GT.0.)    TTT(2,NT) =-1.
74         IF (D1.GT.0. .OR.  D2.LT.0.)    TTT(2,NT) =+1.
75 *           D 1   O R   D 2   I S   N O T   Z E R O
76         IF (NT .NE. 1)                  GOTO 400
77         XA     = (D2*FACE(J+KCGX1)-D1*FACE(J+KCGX2)) / (D2 - D1)
78         YA     = (D2*FACE(J+KCGY1)-D1*FACE(J+KCGY2)) / (D2 - D1)
79         ZA     = (D2*FACE(J+KCGZ1)-D1*FACE(J+KCGZ2)) / (D2 - D1)
80         TTT(1,1)   = 0.
81         GOTO 600
82   400   X      = (D2*FACE(J+KCG1)-D1*FACE(J+KCG2)) / (D2 - D1)
83         TTT(1,NT)  = (X - AA(K)) / DELTA(K)
84         GOTO 600
85 *           D 1   A N D   D 2   B O T H   A R E   Z E R O
86   500   IF (NT .NE. 1)                  GOTO 510
87         XA     = FACE(J+KCGX1)
88         YA     = FACE(J+KCGY1)
89         ZA     = FACE(J+KCGZ1)
90         TTT(1,1)   = 0.
91         TTT(2,1)   = 0.
92         GOTO 520
93   510   X        = FACE(J+KCG1)
94         TTT(1,NT)  = (X - AA(K)) / DELTA(K)
95         TTT(2,NT)  = 0.
96   520   NT       = NT + 1
97         X        = FACE(J+KCG2)
98         TTT(1,NT)  = (X - AA(K)) / DELTA(K)
99         TTT(2,NT)  = 2.
100         IF (TTT(1,NT) .GT. TTT(1,NT-1)) GOTO 600
101         TTT(2,NT-1)= 2.
102         TTT(2,NT)  = 0.
103   600   CONTINUE
104       RETURN
105       END