DECLARE SUB DisplayReducedSqrt (num&) DECLARE FUNCTION acos (x!) DEFLNG A-Z 'VECTOR CALCULATOR ii 'BY TOSHIHIRO HORIE 'CREATED 5/18/1996 DIM SHARED primes(46): 'up to 199 CONST pi = 3.1415926535# MAIN: SCREEN 0: CLS : COLOR 15, 3 PRINT " VECTOR CALCULATOR by Toshihiro Horie 1996" + SPACE$(35) PRINT : COLOR 0, 7 LOCATE 25, 1: PRINT " RESTRICTION: Integer Vectors only" + SPACE$(26); PRINT DATE$ + SPACE$(2) + LEFT$(TIME$, 5) + SPACE$(2); GOSUB SIEVE: COLOR 15, 0: LOCATE 3, 1 INPUT "ENTER VECTOR A (X1,Y1,Z1) ", X1, Y1, Z1 AL2 = (X1 * X1 + Y1 * Y1 + Z1 * Z1) COLOR 15, 1: PRINT "Magnitude ³A³=AùA:"; : COLOR 15, 0 DisplayReducedSqrt AL2 COLOR 15, 1: PRINT "Direction vector :"; : COLOR 15, 0 IF AL2 = 0 THEN PRINT "0i+0j+0k" ELSE PRINT USING "###.####i,"; X1 / SQR(AL2); PRINT USING "###.####j,"; Y1 / SQR(AL2); PRINT USING "###.####k"; Z1 / SQR(AL2) END IF PRINT INPUT "ENTER VECTOR B (X2,Y2,Z2) ", X2, Y2, Z2 BL2 = (X2 * X2 + Y2 * Y2 + Z2 * Z2) COLOR 15, 1: PRINT "Magnitude ³B³=BùB:"; : COLOR 15, 0 DisplayReducedSqrt BL2 COLOR 15, 1: PRINT "Direction vector :"; : COLOR 15, 0 IF BL2 = 0 THEN PRINT "0i+0j+0k" ELSE PRINT USING "###.####i,"; X2 / SQR(BL2); PRINT USING "###.####j,"; Y2 / SQR(BL2); PRINT USING "###.####k"; Z2 / SQR(BL2) END IF PRINT : COLOR 15, 1 PRINT "Vector B-A "; : COLOR 15, 0 XD = X2 - X1: YD = Y2 - Y1: ZD = Z2 - Z1 PRINT USING "###.####i,"; XD; PRINT USING "###.####j,"; YD; PRINT USING "###.####k"; ZD; PRINT SPC(6); COLOR 15, 1: PRINT "Distance A->B"; : COLOR 15, 0 DL2 = (XD * XD + YD * YD + ZD * ZD) DisplayReducedSqrt DL2 PRINT : COLOR 15, 1 PRINT "Vector A+B "; : COLOR 15, 0 XB = X2 + X1: YB = Y2 + Y1: ZB = Z2 + Z1 PRINT USING "###.####i,"; XB; PRINT USING "###.####j,"; YB; PRINT USING "###.####k"; ZB PRINT : COLOR 15, 1 PRINT "AùB (Scalar product)"; : COLOR 15, 0 'AùB=³A³³B³cos é VS = X1 * X2 + Y1 * Y2 + Z1 * Z2 PRINT USING "###.####"; VS; XM! = (X1 + X2) / 2: YM! = (Y1 + Y2) / 2: ZM! = (Z1 + Z2) / 2 PRINT SPC(10); : COLOR 15, 1 PRINT "Midpoint A,B"; : COLOR 15, 0 PRINT USING "###.####,"; XM!; PRINT USING "###.####,"; YM!; PRINT USING "###.####"; ZM! PRINT : COLOR 15, 1 PRINT "Angle between A and B": COLOR 15, 0 IF BL2 = 0 OR AL2 = 0 THEN PRINT "Angle is undefined (Zero Vector)" ELSE cosangle! = VS / SQR(AL2) / SQR(BL2) 'PRINT "Arccos "; cosangle! angle! = acos(cosangle!) PRINT USING "Angle ####.#### degrees"; angle! * 180 / pi END IF 'to do angles between planes, plug in the coefficients of the equation 'for the plane except the constant, because this gives you the normal 'line to each plane. The angle between planes = angle between normals. PRINT : COLOR 15, 1 PRINT "Vector AxB (Vector Product) "; 'AxB = ³A³³B³sin é '³AxB³=Area of parallelogram, ³rxF³=magnitude of torque 'AxB gives a vector perpendicular (normal) to both A and B, 'a point and this normal vector determine a plane. 'the direction corresponds to the thumb in the right-hand rule (physics) Xc = Y1 * Z2 - Z1 * Y2 Yc = -(X1 * Z2 - X2 * Z1) Zc = X1 * Y2 - X2 * Y1 IF Xc = 0 AND Yc = 0 AND Zc = 0 THEN COLOR 14, 1: PRINT "- Vectors are parallel.": COLOR 15, 0 ELSE PRINT END IF COLOR 15, 0 PRINT USING "###.####i,"; Xc; PRINT USING "###.####j,"; Yc; PRINT USING "###.####k"; Zc c2 = (Xc * Xc + Yc * Yc + Zc * Zc) PRINT "Area/Torque ³AxB³="; DisplayReducedSqrt c2 'other ideas: 'unit normal vector, volume of parallelpiped 'scalar, vector projections, plane eq, dist. END 'Sieve (c) 1994 Electronics Now 'prime number finder SIEVE: SIZE = 100 primes(0) = 2 COUNT = 1 DIM FLAGS(101) FOR I = 0 TO SIZE FLAGS(I) = 1 NEXT I FOR I = 0 TO SIZE IF FLAGS(I) = 0 THEN GOTO SKIP PRIME = I + I + 3 primes(COUNT) = PRIME K = I + PRIME CHECK: IF K > SIZE THEN GOTO INC FLAGS(K) = 0 K = K + PRIME GOTO CHECK INC: COUNT = COUNT + 1 SKIP: NEXT I 'PRINT COUNT; "primes found" ERASE FLAGS RETURN DEFSNG A-Z FUNCTION acos (x!) '0<=y<=pi IF x < 0 THEN acos = ATN(SQR(1 - x * x) / x) + pi ELSEIF x = 0 THEN acos = pi / 2 ELSE acos = ATN(SQR(1 - x * x) / x) '(normal) END IF END FUNCTION DEFLNG A-Z SUB DisplayReducedSqrt (num) outside = 1 inside = num repeatit: FOR x = 0 TO UBOUND(primes) - 1 divisor = primes(x) * primes(x) IF divisor > num THEN EXIT FOR IF (inside MOD divisor) = 0 THEN 'PRINT divisor, inside, outside IF inside = 1 THEN EXIT FOR outside = outside * primes(x) inside = inside / divisor GOTO repeatit END IF NEXT x COLOR 15, 0: PRINT " "; : 'add a leading space IF outside = 1 THEN IF inside = 1 THEN PRINT "1" ELSE PRINT "û" + LTRIM$(STR$(inside)) END IF ELSEIF inside = 1 THEN PRINT LTRIM$(STR$(outside)) ELSE PRINT LTRIM$(STR$(outside)) + "û" + LTRIM$(STR$(inside)) END IF COLOR 15, 0 END SUB