5 * Revision 1.1.1.1 1995/10/24 10:20:57 cernlib
9 #include "geant321/pilot.h"
10 *CMZ : 3.21/02 29/03/94 15.41.31 by S.Giani
13 FUNCTION GVSAFE (XYZ, C1, C, NC)
14 ************************************************************************
16 * GVSAFE Calculates the distance from a point YB 870511 *
17 * to a surface, and the gradient in this point. *
18 * This is an approximation of the distance, which is smaller *
19 * than the real distance. *
21 * Input : XYZ point coordinates *
22 * C1 constant coefficient from the surface *
23 * C(1) number of non constant coefficients from *
25 * C(2),C(3),... non constant coefficients from the surface *
26 * NC total number of coefficients from the surface *
28 * Extra OUTPUT: COMMON/SLATE/ISLATE(2) ISLATE(2)=ISIGN (from GVSIGN) *
29 * SLATE(10) - value of S(X) *
30 * SLATE(11:13) - gradient *
31 * SLATE(14) - normalisation factor for distance *
32 * SLATE(15) - normalisation factor for gradient *
34 ************************************************************************
35 COMMON /SLATE/ SLATE (40)
37 EQUIVALENCE (SLATE,ISLATE)
38 EQUIVALENCE (JDUMM,SLATE(2))
41 *-----------------------------------------------------------------------
44 IF (NC.NE.2) GO TO 200
46 * case with simplified surface X=C0, Y=C0, Z=C0, X*2+Y*2=C0
47 * (happens only when initialisation is done)
54 SLATE(10) = C1 + XYZ(IAX)
58 RXY2 = XYZ(1)**2 + XYZ(2)**2
60 SLATE(10) = (RXY2 - C1**2)
65 CC = SLATE(10)/SLATE(14)
67 IF (SLATE(10)) 101,102,103
75 * case with surfaces with 4, 7 or 10 coefficients (normal case)
77 200 JDUMM = GVSIGN (XYZ, C1, C, NC)
83 IF (NC .EQ. 4) GO TO 999
87 CCC AA = C(5)**2+C(6)**2+C(7)**2CCC AA = C(5)**2+C(6)**2+C(7)**2
88 CCC ++ 0.5*(C(8)**2+C(9)**2+C(10)**2)
92 CALL GVGRAD (XYZ, C, NC, SLATE(11))
93 TT2 = SLATE(11)**2 + SLATE(12)**2 + SLATE(13)**2
94 SLATE(14) = (TT2+4.*AA*ABS(CC))
95 IF (SLATE(14)-TT2.LE.0.1*TT2) THEN
96 SLATE(15) = SQRT(SLATE(14))
100 SLATE(14) = 0.5*(SLATE(15) + SQRT(SLATE(14)))
102 IF (ABS(SLATE(14)).LE.0.) SLATE(14) = 1.E-10