POV-Ray : Newsgroups : povray.text.scene-files : Mobius macro Server Time
1 Nov 2024 05:21:34 EDT (-0400)
  Mobius macro (Message 1 to 1 of 1)  
From: Trevor Quayle
Subject: Mobius macro
Date: 25 Sep 2001 14:39:29
Message: <3bb0cf61$1@news.povray.org>
As promised in p.b.i, here is my mobius macro v1.0:
-tgq


//
// Mobius for POVRay 3.5 Mesh2 Object v1.0
// Trevor G Quayle, Sept 25, 2001
//
// This is a mobius strip made from mesh2. The strip twists
// around a neutral-axis defined by a closed ellipse on the
// x-z plane.
//
// syntax: Mobius(Ax,Az,W,m,n,nR,SA)
// Ax = half-length of x-axis
// Az = half-length of z-axis (Az=Ax for circular)
// W  = Width of strip (centred on N.A.)
// m  = # segments in width (integer > 0)
// n  = # segments in circumference (integer > 3)
// nR = # half-twists of the strip (0=no twist, 1=180deg, etc.)
//     (decimals may be used, but will not close properly)
//     (negative #s wil reverse the direction of the twist)
// SA = start angle of twisting (0=flat, 90=vertical, etc.)
//
// Note: At present the strip has no thickness and is not
// smoothed. The smoothness of the strip can be increased by
// increasing the #segments used (m & n). Strip Widths greater
// than the minimum axis may produce odd results. The strip
// starts in the +x direction and procedes in a CCW direction
// around the Y-axis.
//

#macro Mobius(Ax,Az,W,m,n,nR,SA)
  #if (Ax<=0)
    #warning concat("X-axis must be  > 0, assigning 2*W"
    #local Ax=2*W;
  #end
  #if (Az<=0)
    #warning concat("Z-axis must be  > 0, assigning 2*W"
    #local Az=2*W;
  #end
  #if (m<1)
    #warning "m must be an integer > 0, assigning 1\n"
    #local m=1;
  #end
  #if (n<4)
    #warning "n must be an integer > 3, assigning 4\n"
    #local n=4;
  #end
  #local m=int(m);
  #local n=int(n);
  #if (min(Ax,Az)<W)
    #warning "A minimum axis smaller than the width may produce
unpredictable results!\n"
  #end

  #macro Ep(A,Ax,Az) <Ax*cos(radians(A)),0,Az*sin(radians(A))> #end
  mesh2{
    vertex_vectors{
      (m+1)*(n+1)
      #local i=0;
      #while (i<=n)
        #local A1=i*360/n;
        #local V1=Ep(A1+360/n,Ax,Az)-Ep(A1-360/n,Ax,Az);
        #local A2=atan2(V1.x,-V1.z);
        #local A3=radians(i*nR*180/n+SA);
        #local j=-m/2;
        #while (j<=m/2)
          ,Ep(A1,Ax,Az)+W/m*j*<cos(A2)*cos(A3),sin(A3),sin(A2)*cos(A3)>
          #local j=j+1;
        #end
        #local i=i+1;
      #end
    }
    face_indices{n*m*2
      #local i=0;
      #while (i<n)
        #local j=0;
        #while (j<m)
          ,<i*(m+1)+j,(i+1)*(m+1)+(j+1),i*(m+1)+(j+1)>
          ,<i*(m+1)+j,(i+1)*(m+1)+(j+1),(i+1)*(m+1)+j>
          #local j=j+1;
        #end
        #local i=i+1;
      #end
    }
  }
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.