QB64 Phoenix Edition
QBJS Rotating 4D cube - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: QBJS, BAM, and Other BASICs (https://qb64phoenix.com/forum/forumdisplay.php?fid=50)
+--- Thread: QBJS Rotating 4D cube (/showthread.php?tid=1075)

Pages: 1 2


RE: QBJS Rotating 4D cube - vince - 11-10-2022

A couple of mods:

the clifford torus (with assymetry for effect)
Code: (Select All)
dim shared pi, p, q, d, z0, t, f, sw, sh

sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)

screen _newimage(sw, sh, 32)

sv = 2*pi/30
su = 2*pi/10

'do
for t = 0 to 2*pi step 0.01
    cls
    u = 0
    for v=0 to 2*pi+sv step sv
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
       
        proj x, y, z, w
        pset (p, q)
       
        for u=0 to 2*pi+su step su
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
       
            proj x, y, z, w
            line -(p, q)
        next
    next
   
    for u=0 to 2*pi+su step su
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
       
        proj x, y, z, w
        pset (p, q), _rgb(255,0,0)
       
        for v=0 to 2*pi+sv step sv
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
       
            proj x, y, z, w
            line -(p, q), _rgb(255,0,0)
        next
    next
   

    _limit 50
next
'loop

sub proj(x, y, z, w)
    xx = x
    yy = y*cos(t) - w*sin(t)
    zz = z
    ww = y*sin(t) + w*cos(t)

    d2 = 3
    w0 = 3
    xx = xx*d2/(w0 + ww)
    yy = yy*d2/(w0 + ww)
    zz = zz*d2/(w0 + ww)
   
    xxx = xx*cos(t) - zz*sin(t)
    zzz = xx*sin(t) + zz*cos(t)
    xx = xxx
    zz = zzz
   
    a = pi/12
    b = pi/3
    xxx = xx*cos(a) - yy*sin(a)
    yyy = xx*sin(a) + yy*cos(a)
    xx = xxx
    yy = yyy

    yyy = yy*cos(b) - zz*sin(b)
    zzz = yy*sin(b) + zz*cos(b)
    yy = yyy
    zz = zzz
   
    xx = 200*xx
    yy = 200*yy
    zz = 200*zz

    p = sw/2 + 2*xx*d/(yy + z0)
    q = sh/2 - 2*zz*d/(yy + z0)
end sub

the 5-cell (this one is confusing but looks correct to me, idk)
Code: (Select All)
dim shared pi, p, q, d, z0, t, f, sw, sh

sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)


dim x(16), y(16), z(16), w(16)
x(0)=0-1: y(0) =0-1: z(0) =0-1: w(0) = 0-1
x(1)=  1: y(1) =0-1: z(1) =0-1: w(1) = 0-1
x(2)=  1: y(2) =  1: z(2) =0-1: w(2) = 0-1
x(3)=0-1: y(3) =  1: z(3) =0-1: w(3) = 0-1

x(4)=0-1: y(4) =0-1: z(4) =1: w(4) = 0-1
x(5)=  1: y(5) =0-1: z(5) =1: w(5) = 0-1
x(6)=  1: y(6) =  1: z(6) =1: w(6) = 0-1
x(7)=0-1: y(7) =  1: z(7) =1: w(7) = 0-1

x( 8)=0-1: y( 8) =0-1: z( 8) =0-1: w( 8) = 1
x( 9)=  1: y( 9) =0-1: z( 9) =0-1: w( 9) = 1
x(10)=  1: y(10) =  1: z(10) =0-1: w(10) = 1
x(11)=0-1: y(11) =  1: z(11) =0-1: w(11) = 1

x(12)=0-1: y(12) =0-1: z(12) =1: w(12) = 1
x(13)=  1: y(13) =0-1: z(13) =1: w(13) = 1
x(14)=  1: y(14) =  1: z(14) =1: w(14) = 1
x(15)=0-1: y(15) =  1: z(15) =1: w(15) = 1


screen _newimage(sw, sh, 32)

'do
for t = 0 to 2*pi step 0.01
    cls

    f=0
    i = 0
    proj x(i), y(i), z(i), w(i)
    pset (p, q)
    for i=1 to 2
        proj x(i), y(i), z(i), w(i)
        line -(p, q)
    next
    i = 0
    proj x(i), y(i), z(i), w(i)
    line -(p, q)
   
    k = 4
    for i=0 to 2
        proj x(i), y(i), z(i), w(i)
        pset (p, q)
   
        proj x(k), y(k), z(k), w(k)
        line -(p, q)
    next
   
    for i=0 to 2
        proj x(i), y(i), z(i), w(i)
        pset (p, q), _rgb(255,0,0)
  
        k = 9
   
        proj x(k), y(k), z(k), w(k)
        line -(p, q), _rgb(255,0,0)
    next
   
    k = 4
    proj x(k), y(k), z(k), w(k)
    line -(p, q), _rgb(255,0,0)
   
    _limit 50
next
'loop

sub proj(x, y, z, w)
    xx = x
    yy = y*cos(t) - w*sin(t)
    zz = z
    ww = y*sin(t) + w*cos(t)

    d2 = 3
    w0 = 3
    xx = xx*d2/(w0 + ww)
    yy = yy*d2/(w0 + ww)
    zz = zz*d2/(w0 + ww)

    xxx = xx*cos(0) - zz*sin(0)
    zzz = xx*sin(0) + zz*cos(0)
    xx = xxx
    zz = zzz

    a = pi/3
    b = pi/8
    xxx = xx*cos(a) - yy*sin(a)
    yyy = xx*sin(a) + yy*cos(a)
    xx = xxx
    yy = yyy

    yyy = yy*cos(b) - zz*sin(b)
    zzz = yy*sin(b) + zz*cos(b)
    yy = yyy
    zz = zzz

    xx = 100*xx
    yy = 100*yy
    zz = 100*zz

    p = sw/2 + 2*xx*d/(yy + z0)
    q = sh/2 - 2*zz*d/(yy + z0)
end sub