Created
June 4, 2011 03:08
-
-
Save madebyjeffrey/1007521 to your computer and use it in GitHub Desktop.
Pie Slices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE FUNCTION atan2! (y AS DOUBLE, x AS DOUBLE) | |
DECLARE SUB PieSlice2 (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, ro AS SINGLE, ri AS SINGLE) | |
DECLARE SUB PieSlice (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, orad AS SINGLE, irad AS SINGLE) | |
' for PieSlice2 | |
CONST sep = 10 | |
DEF fnphi (x!, ri!) = ATN(x! / (2 * ri)) | |
DEF fnAx (theta!, ri!) = ri! * COS(theta! + fnphi(sep, ri!)) | |
DEF fnAy (theta!, ri!) = ri! * SIN(theta! + fnphi(sep, ri!)) | |
DEF fnBx (theta!, ri!) = ri! * COS(theta! - fnphi(sep, ri!)) | |
DEF fnBy (theta!, ri!) = ri! * SIN(theta! - fnphi(sep, ri!)) | |
DEF fnZx (theta!, ro!) = ro! * COS(theta!) | |
DEF fnZy (theta!, ro!) = ro! * SIN(theta!) | |
DEF fnCx (theta!, ro!) = -SIN(theta!) * sep / 2 + ro! * COS(theta!) | |
DEF fnCy (theta!, ro!) = COS(theta) * sep / 2 + ro! * SIN(theta!) | |
DEF fnDx (theta!, ro!) = SIN(theta) * sep / 2 + ro! * COS(theta!) | |
DEF fnDy (theta!, ro!) = -COS(theta) * sep / 2 + ro! * SIN(theta!) | |
SCREEN 12 | |
'LINE (0, 0)-(639, 479) | |
CONST PI = 3.141593 | |
FOR i = 0 TO 5 | |
PieSlice2 i * PI / 3, i * PI / 3 + PI / 3, 320, 240, 200, 50 | |
NEXT i | |
FUNCTION atan2 (y AS DOUBLE, x AS DOUBLE) | |
DIM result AS DOUBLE | |
IF (x > 0) THEN | |
result = ATN(y / x) | |
ELSEIF (x < 0 AND y >= 0) THEN | |
result = PI + ATN(y / x) | |
ELSEIF (y < 0 AND x < 0) THEN | |
result = -PI + ATN(y / x) | |
ELSEIF (y > 0 AND x = 0) THEN | |
result = PI / 2 | |
ELSEIF (y < 0 AND x = 0) THEN | |
result = -PI / 2 | |
ELSE | |
result = 0 | |
END IF | |
IF (result < 0) THEN | |
result = result + 2 * PI | |
END IF | |
atan2 = result | |
END FUNCTION | |
SUB PieSlice (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, orad AS SINGLE, irad AS SINGLE) | |
DIM Ax AS SINGLE, Ay AS SINGLE | |
DIM Bx AS SINGLE, By AS SINGLE | |
DIM Cx AS SINGLE, Cy AS SINGLE | |
DIM Dx AS SINGLE, Dy AS SINGLE | |
theta1 = theta1 + PI / 32 | |
theta2 = theta2 - PI / 32 | |
Ax = irad * COS(theta1) + x | |
Ay = irad * SIN(theta1) + y | |
Bx = orad * COS(theta1) + x | |
By = orad * SIN(theta1) + y | |
Cx = orad * COS(theta2) + x | |
Cy = orad * SIN(theta2) + y | |
Dx = irad * COS(theta2) + x | |
Dy = irad * SIN(theta2) + y | |
DIM ct1 AS SINGLE, ct2 AS SINGLE | |
ct1 = 2 * PI - theta1 | |
ct2 = 2 * PI - theta2 | |
IF ct1 = 2 * PI THEN ct1 = 0 | |
IF ct2 = 2 * PI THEN ct2 = 0 | |
LINE (Ax, Ay)-(Bx, By), 15 | |
CIRCLE (x, y), orad, 15, ct2, ct1 | |
LINE (Cx, Cy)-(Dx, Dy), 15 | |
CIRCLE (x, y), irad, 15, ct2, ct1 | |
END SUB | |
SUB PieSlice2 (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, ro AS SINGLE, ri AS SINGLE) | |
' LINE (fnAx(theta1, ri) + x, fnAy(theta1, ri) + y)-(fnBx(theta2, ri) + x, fnBy(theta2, ri) + y) | |
' LINE (fnCx(theta1, ro) + x, fnCy(theta1, ro) + y)-(fnDx(theta2, ro) + x, fnDy(theta2, ro) + y) | |
LINE (fnAx(theta1, ri) + x, fnAy(theta1, ri) + y)-(fnCx(theta1, ro) + x, fnCy(theta1, ro) + y) | |
LINE (fnBx(theta2, ri) + x, fnBy(theta2, ri) + y)-(fnDx(theta2, ro) + x, fnDy(theta2, ro) + y) | |
DIM ct1 AS SINGLE, ct2 AS SINGLE | |
ct1 = 2 * PI - theta1 | |
ct2 = 2 * PI - theta2 | |
IF ct1 = 2 * PI THEN ct1 = 0 | |
IF ct2 = 2 * PI THEN ct2 = 0 | |
DIM A!, B!, C!, D! | |
A! = atan2(fnAy(theta1, ri), fnAx(theta1, ri)) | |
B! = atan2(fnBy(theta2, ri), fnBx(theta2, ri)) | |
'IF fnAx(theta1, ri) < 0 THEN A! = A! + 3.14159 | |
'IF fnAy(theta1, ri) < 0 THEN A! = A! + 3.14159 | |
'IF fnBx(theta2, ri) < 0 THEN B! = B! + 3.14159 | |
'IF fnBx(theta2, ri) < 0 THEN B! = B! + 3.14159 | |
' | |
C! = atan2(fnCy(theta1, ro), fnCx(theta1, ro)) | |
D! = atan2(fnDy(theta2, ro), fnDx(theta2, ro)) | |
' PRINT C! * (180 / 3.14159), D! * (180 / 3.14159) | |
CIRCLE (x, y), ri, 15, A!, B! | |
CIRCLE (x, y), ro, 15, C!, D! | |
END SUB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment