
18.5. SUBROUTINES FOR MODELING GEOMETRY 331
csphere.f
Geometry routine for a sphere, centered at the origin.
C23456789|123456789|123456789|123456789|123456789|123456789|123456789|12
subroutine csphere(R,x0,y0,z0,u,v,w,s,inside,hit)
implicit none
C Calculates the distance to a sphere centered at (0,0,0)
logical
* inside ! Input: inside = .true. => particle thinks it is inside
* , ! Input: inside = .false. => particle thinks it is outside
* hit ! Output: hit = .true. => particle would hit the surface
! Output: hit = .false. => particle would miss the surface
real
* R, ! Input: Radius of the cylinder
* x0, ! Input: x-coordinate of the particle
* y0, ! Input: y-coordinate of the particle
* z0, ! Input: z-coordinate of the particle
* u , ! Input: x-axis direction cosine of the particle
* v , ! Input: y-axis direction cosine of the particle
* w , ! Input: w-axis direction cosine of the particle
* s ! Output: Distance to the surface (if hit)
real
* A, ! Internal: Quadratic coefficient A
* B, ! Internal: Quadratic coefficient B
* C ! Internal: Quadratic coefficient C
A = 1e0 ! i.e. u**2 + v**2 + w**2 = 1
B = u*x0 + v*y0 + w*z0
C = x0**2 + y0**2 + z0**2 - R**2
call quadric(A,B,C,s,inside,hit) ! Get the generic quadric solution
return
end