540_degree_twisted_Moebious_Strip.BAS

Home   »   540_degree_twisted_Moebious_Strip.BAS

!540 degree twisted Moebious Strip becomes shape with D_3 symmetry
!2021-05-29 @aoki_taichi
!https://twitter.com/aoki_taichi/status/1397704576048844802
!https://twitter.com/aoki_taichi/status/1398413436795514884?s=20
!http://hp.vector.co.jp/authors/VA008683/
!http://www.darwin3d.com/gamedev/articles/col0599.pdf
!todo: Verlet Integlationとやらを使った方が安定する?

OPTION ARITHMETIC NATIVE

LET dt=0.04! time step
LET m=10*3*2 ! x
LET n=5    ! y
LET nn=n*m ! number of particles
LET k=2*1.0e2 !spring constant
LET drag=0.2
DIM x(1 TO nn),y(1 TO nn),z(1 TO nn)
DIM vx(1 TO nn),vy(1 TO nn),vz(1 TO nn)
DEF id(xx,yy)=(xx-1)*n + (yy-1) +1
SET WINDOW -1/3*m +m/6,2/3*m -m/6,-m/2 +m/6,m/2 -m/6
SET POINT STYLE 2

DIM ex(1 TO 3),ey(1 TO 3),ez(1 TO 3)!orthogonal vector
DATA 1,0,0
DATA 0,1,0
DATA 0,0,1
MAT READ ex
MAT READ ey
MAT READ ez

!initialize the particle positions
FOR xx=1 TO m
   FOR yy=1 TO n
      LET i=id(xx,yy)
      LET x(i)=xx
      LET y(i)=yy-CEIL(n/2)
      LET z(i)=0
   NEXT YY
NEXT XX

!link the particles
LET nnn= (n-1)*m + n*(m-1) + (n-1)*(m-1)*2 + (n-2)*m + n*(m-2) ! number of links
DIM link(1 TO nnn,0 TO 1)
LET ii=0
FOR xx=1 TO m-1
   FOR yy=1 TO n
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy)
      LET link(ii,1)=id(xx+1,yy)
   NEXT  YY
NEXT XX
FOR xx=1 TO m
   FOR yy=1 TO n-1
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy)
      LET link(ii,1)=id(xx,yy+1)
   NEXT  YY
NEXT XX

FOR xx=1 TO m-1
   FOR yy=1 TO n-1
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy)
      LET link(ii,1)=id(xx+1,yy+1)
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy+1)
      LET link(ii,1)=id(xx+1,yy)
   NEXT  YY
NEXT XX

FOR xx=1 TO m-2
   FOR yy=1 TO n
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy)
      LET link(ii,1)=id(xx+2,yy)
   NEXT  YY
NEXT XX
FOR xx=1 TO m
   FOR yy=1 TO n-2
      LET ii=ii+1
      LET link(ii,0)=id(xx,yy)
      LET link(ii,1)=id(xx,yy+2)
   NEXT  YY
NEXT XX

IF ii-nnn <> 0 THEN STOP
DIM d0(1 TO nnn) ! rest length for each link
FOR ii=1 TO nnn
   LET i=link(ii,0)
   LET j=link(ii,1)
   LET d0(ii)=SQR((x(i)-x(j))^2+(y(i)-y(j))^2+(z(i)-z(j))^2)
NEXT ii

DO
   LET mx_was=mx
   LET my_was=my
   mouse poll mx,my,ml,mr
   LET t=t+dt
    
   FOR ii= 1 TO nnn
      LET i=link(ii,0)
      LET j=link(ii,1)
      LET d=SQR((x(i)-x(j))^2+(y(i)-y(j))^2+(z(i)-z(j))^2) 
      LET f=k*(d - d0(ii))!Hooke's law
      LET vx(i)=vx(i)-f*(x(i)-x(j))/d*dt
      LET vy(i)=vy(i)-f*(y(i)-y(j))/d*dt
      LET vz(i)=vz(i)-f*(z(i)-z(j))/d*dt
       
      LET vx(j)=vx(j)+f*(x(i)-x(j))/d*dt
      LET vy(j)=vy(j)+f*(y(i)-y(j))/d*dt
      LET vz(j)=vz(j)+f*(z(i)-z(j))/d*dt
   NEXT  II
    
   FOR i= 1 TO nn
      IF t

Leave a Reply

Your email address will not be published. Required fields are marked *