Author Topic: Square to Circle  (Read 74 times)

Square to Circle
« on: June 19, 2018, 08:04:18 PM »
Maybe someone can make heads or tails out of this and maybe use it in a an example.

I am trying but all I get is illegal function call errors.

http://squircular.blogspot.com/2015/09/fg-squircle-mapping.html

https://stackoverflow.com/questions/13211595/how-can-i-convert-coordinates-on-a-circle-to-coordinates-on-a-square
« Last Edit: June 19, 2018, 08:28:40 PM by Code Hunter »

Offline bplus

  • B = B + geberation
Re: Square to Circle
« Reply #1 on: June 19, 2018, 08:25:42 PM »
Ha! Looking into that this afternoon!

Here is my cosine grid:
Code: [Select]
_TITLE "Sphere sim by bplus started 2018-06-19"
'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
CONST xmax = 800
CONST ymax = 600
DIM SHARED pi
pi = _PI


SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 360, 60

'divide a quarter circle into 9 equal angles (pi/2) / 9
'create a grid with the cos of these angles
DIM cxy(9)
i = 0
FOR a = 0 TO pi / 2 STEP (pi / 2) / 9
    cxy(i) = COS(a)
    i = i + 1
NEXT
' need a radius say 300 half the height of screen
r = 300
cy = ymax / 2
cx = xmax / 2
FOR i = 0 TO 9
    ln cx - r * cxy(i), 0, cx - r * cxy(i), ymax
    ln cx + r * cxy(i), 0, cx + r * cxy(i), ymax
    ln 0, cy - r * cxy(i), xmax, cy - r * cxy(i)
    ln 0, cy + r * cxy(i), xmax, cy + r * cxy(i)
    CIRCLE (cx, cy), r * cxy(i)
NEXT

SUB ln (x1, y1, x2, y2)
    LINE (x1, y1)-(x2, y2)
END SUB



Looking to map rectangle into the circle.
« Last Edit: June 19, 2018, 08:28:49 PM by bplus »
B = B + ...

Re: Square to Circle
« Reply #2 on: June 19, 2018, 08:30:42 PM »
Syntax error inside the final loop.

Code: [Select]
    ln cx - r * cxy(i), 0, cx - r * cxy(i), ymax
    ln cx + r * cxy(i), 0, cx + r * cxy(i), ymax
    ln 0, cy - r * cxy(i), xmax, cy - r * cxy(i)
    ln 0, cy + r * cxy(i), xmax, cy + r * cxy(i)

Offline bplus

  • B = B + geberation
Re: Square to Circle
« Reply #3 on: June 19, 2018, 08:31:13 PM »
Fixed forgot ln sub
B = B + ...