C Count cubes in cubic lattice cut by sphere around origin C A cube with an inscribed sphere is divided into n*n*n C smaller cubes. The program counts how many of the small C cubes are cut or touched at their vertices. C Cubes only touched by the cutting sphere, but all points C either inside or outside the sphere are counted only half, C because they occur in inside/outside pairs. C Author: Hugo Pfoertner http://www.pfoertner.org/ C 16.07.2003 C IMPLICIT INTEGER (A-Z) PARAMETER (M=100) DO 100 R = 2,M RR = R * R C L counts cubes fully cut L = 0 C N counts cubes touched at one of its vertices N = 0 C Loops over lattice points DO 110 I = -R, R-2, 2 II = I*I IPP = (I+2)*(I+2) DO 120 J = -R, R-2, 2 JJ = J*J JPP = (J+2)*(J+2) DO 130 K = -R, R-2, 2 KK = K*K KPP = (K+2)*(K+2) C Differences of squared radii of 8 vertices from cutting sphere D1 = II + JJ + KK - RR D2 = II + JPP + KK - RR D3 = IPP + JJ + KK - RR D4 = IPP + JPP + KK - RR D5 = II + JJ + KPP - RR D6 = II + JPP + KPP - RR D7 = IPP + JJ + KPP - RR D8 = IPP + JPP + KPP - RR C WRITE(*,*)R,I,J,D1,D2,D3,D4 MI = MIN (D1,D2,D3,D4,D5,D6,D7,D8) MA = MAX (D1,D2,D3,D4,D5,D6,D7,D8) C Check if sign change of squared differences occurs IF ( MI * MA .LE. 0 ) THEN IF ( MI * MA .EQ. 0 ) THEN C Vertex hit N = N + 1 ELSE C Cube cut L = L + 1 ENDIF C ELSE ENDIF 130 CONTINUE 120 CONTINUE 110 CONTINUE C Only half of the vertex hits are counted WRITE (*,*) R, L + N/2 100 CONTINUE END C Results: N N_cut 2 8 3 26 4 56 5 98 6 152 7 194 8 272 9 362 10 440 11 530 12 656 13 746 14 872 15 1034 16 1160 17 1298 18 1496 19 1658 20 1856 21 1994 22 2240 23 2450 24 2624 25 2906 26 3128 27 3362 28 3656 29 3890 30 4208 31 4442 32 4760 33 5090 34 5360 35 5714 36 6032 37 6362 38 6752 39 7106 40 7496 41 7826 42 8216 43 8618 44 9080 45 9458 46 9896 47 10298 48 10736 49 11258 50 11696 51 12194 52 12680 53 13130 54 13712 55 14090 56 14696 57 15218 58 15728 59 16346 60 16880 61 17474 62 17984 63 18578 64 19232 65 19802 66 20432 67 21074 68 21704 69 22322 70 23072 71 23642 72 24296 73 24962 74 25712 75 26426 76 27056 77 27866 78 28616 79 29234 80 30104 81 30842 82 31520 83 32330 84 33128 85 33986 86 34712 87 35546 88 36440 89 37082 90 38120 91 38930 92 39728 93 40634 94 41504 95 42482 96 43256 97 44210 98 45128 99 46010 100 47000