_TITLE "Knot Function of Angle" ' B+ 2019-07-18 ' another attempt to get intersect points by computer rather than eyeball
CONST xmax
= 740, ymax
= 740, pi
= 3.14159265 DIM x0
, y0
, r0
, rThick
, rFill
'for knot r is for equation, r1 is for thickness of rings, r2 is fill thicknes
x0 = xmax / 2: y0 = ymax / 2: r0 = 120: rThick = 4: rFill = 2
x0 = xmax / 2: y0 = ymax / 2: r0 = 100: rThick = 8: rFill = 4
knot xmax / 4, ymax / 4, 60, 15, 8, &HFF009900, &HFF0000FF, 1
knot 3 * xmax / 4, ymax / 4 + 35, 100, 8, 4, &HFFFFFF00, &HFFFF0000, 2
knot xmax / 4, ymax * 3 / 4, 98, 4, 1, &HFFFFFFFF, &HFF009900, 3
knot xmax * 3 / 4, ymax * 3 / 4, 90, 4, 2, &HFF0000FF, &HFF00BBBB, 4
stepper = 1 / (2 * pi * r) 'how close to step 'orig 2*pi
'first pass draw in outline
FOR a
= 0 TO 2 * pi
- 2 * stepper
STEP stepper
'collect data CASE 1: FofA xc
, yc
, r
, a
, x
, y
CASE 2: FofA2 xc
, yc
, r
, a
, x
, y
CASE 3: FofA3 xc
, yc
, r
, a
, x
, y
CASE 4: FofA4 xc
, yc
, r
, a
, x
, y
IF ABS(ang
(x
, y
) - a
) > pi
/ 12 THEN 'not too close pi/12 orig counts(x, y) = counts(x, y) + 1 'hopefully
ang(x, y) = a 'update xy position with latest angle
counts(x, y) = 1: ang(x, y) = a
fcirc x, y, r1, border
'next pass draw in fill
IF counts
(x
, y
) THEN fcirc x
, y
, r2
, fill
flag = 0
IF ((intersects
(i
, 0) - x
) ^ 2 + (intersects
(i
, 1) - y
) ^ 2) ^ .5 < 2 THEN flag
= 1:
EXIT FOR intersects(ii, 0) = x
intersects(ii, 1) = y
ii = ii + 1
intersects(ii, 0) = x
intersects(ii, 1) = y
ii = ii + 1
'For each intersect there is am angle it goes over and an angle it goes under
' looking at figure from angle = 0, it alternates over, under, over, under....;
' its the over angles that need the bridges. How to find the over angles?
FOR a
= 0 TO 2 * pi
- 2 * stepper
STEP stepper
'collect data CASE 1: FofA xc
, yc
, r
, a
, x
, y
CASE 2: FofA2 xc
, yc
, r
, a
, x
, y
CASE 3: FofA3 xc
, yc
, r
, a
, x
, y
CASE 4: FofA4 xc
, yc
, r
, a
, x
, y
IF x
= intersects
(i
, 0) AND y
= intersects
(i
, 1) AND ABS(a
- lasta
) > pi
/ 24 THEN toggle
= (toggle
+ 1) MOD 2 IF toggle
THEN 'save every other angle as positive for the overpasses 'build a bridge
FOR b
= a
- 3 * pi
/ 96 TO a
+ 3 * pi
/ 96 STEP stepper
CASE 1: FofA xc
, yc
, r
, b
, xx
, yy
CASE 2: FofA2 xc
, yc
, r
, b
, xx
, yy
CASE 3: FofA3 xc
, yc
, r
, b
, xx
, yy
CASE 4: FofA4 xc
, yc
, r
, b
, xx
, yy
fcirc xx, yy, r1, border
FOR b
= a
- 4 * pi
/ 96 TO a
+ 4 * pi
/ 96 STEP stepper
CASE 1: FofA xc
, yc
, r
, b
, xx
, yy
CASE 2: FofA2 xc
, yc
, r
, b
, xx
, yy
CASE 3: FofA3 xc
, yc
, r
, b
, xx
, yy
CASE 4: FofA4 xc
, yc
, r
, b
, xx
, yy
fcirc xx, yy, r2, fill
lasta = a
xReturn
= INT(xc
+ r
* (COS(a
) + COS(4 * a
) / .7 + SIN(2 * a
) / 12)) yReturn
= INT(yc
+ r
* (SIN(a
) + SIN(4 * a
) / .7 + COS(2 * a
) / 12))
xReturn
= xc
+ r
* (COS(a
) + COS(5 * a
) / 1.6 + SIN(2 * a
) / 3) yReturn
= yc
+ r
* (SIN(a
) + SIN(5 * a
) / 1.6 + COS(2 * a
) / 3)
xReturn
= xc
+ r
* (COS(a
) + COS(7 * a
) / 2 + SIN(2 * a
) / 3) yReturn
= yc
+ r
* (SIN(a
) + SIN(7 * a
) / 2 + COS(2 * a
) / 3)
'for function number 4, the following works best
xReturn
= xc
+ r
* (COS(a
) + COS(4 * a
) / 2.9 + SIN(6 * a
) / 2.1) '2.6 2.1 works yReturn
= yc
+ r
* (SIN(a
) + SIN(4 * a
) / 2.9 + COS(6 * a
) / 2.1) ' 2.7 2.2 better? 2.8 2.3 OK too 2.9 2.1 is it
'''''' ================= failed: bridges too close or passes do not alternate , too many loops?
''''' Toggle commented function blocks to see some fancy loops tried
'SUB FofA4 (xc, yc, r, a AS SINGLE, xReturn AS INTEGER, yReturn AS INTEGER)
' xReturn = xc + r * (COS(a) + COS(9 * a) / 2.5 + SIN(3 * a) / 2.6)
' yReturn = yc + r * (SIN(a) + SIN(9 * a) / 2.5 + COS(3 * a) / 2.6)
'END SUB
'SUB FofA4 (xc, yc, r, a AS SINGLE, xReturn AS INTEGER, yReturn AS INTEGER)
' xReturn = xc + r * (COS(a) + COS(3 * a) / 2 + SIN(11 * a) / 2.7)
' yReturn = yc + r * (SIN(a) + SIN(3 * a) / 2 + COS(11 * a) / 2.7)
'END SUB
'SUB FofA4 (xc, yc, r, a AS SINGLE, xReturn AS INTEGER, yReturn AS INTEGER)
' xReturn = xc + r * (COS(a) + COS(9 * a) / 2 + SIN(5 * a) / 2.5)
' yReturn = yc + r * (SIN(a) + SIN(9 * a) / 2 + COS(5 * a) / 2.5)
'END SUB
'SUB FofA4 (xc, yc, r, a AS SINGLE, xReturn AS INTEGER, yReturn AS INTEGER)
' xReturn = xc + r * (COS(a) + COS(5 * a) / 2.7 + SIN(6 * a) / 2)
' yReturn = yc + r * (SIN(a) + SIN(5 * a) / 2.7 + COS(6 * a) / 2)
'END SUB
Radius
= ABS(R
): RadiusError
= -Radius: X
= Radius: Y
= 0 LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), C
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), C
, BF