POV-Ray : Newsgroups : povray.binaries.images : Isosurface doodle : Re: Isosurface doodle Server Time
7 Nov 2024 07:30:55 EST (-0500)
  Re: Isosurface doodle  
From: Bald Eagle
Date: 17 Jul 2016 22:35:01
Message: <web.578c3fffca82f27f5e7df57c0@news.povray.org>
Tried a second method based on 4D vectors converted to 3D coordinates.

I get output that superficially appears to be valid, but I have problems when
adding bonds to "the 4 nearest neighbors" - it just seems like it comes out
wrong.

I added some checks to filter out invalid endpoint coordinates, but that didn't
seem to fix things.

Change space and iterations to increase or decrease the number of spheres.

--------------------------------------------------------------------------

#declare ShowCylinders = false;
#declare Space = 10;
#declare Iterations = 10;

#for (d, -Iterations, Iterations)
 #for (a, -Space, Space)
  #for (b, -Space, Space)
   #for (c, -Space, Space)
    #if ( (a+b+c)=0 | (a+b+c)=1)
     #declare X = (a + b - c - d);
     #declare Y = (a - b + c - d);
     #declare Z = (-a + b + c - d);
     //#debug concat( " X = ", str(X, 3, 1),  " Y = ", str(Y, 3, 1), " Z = ",
str(Z, 3, 1), "\n")
     sphere {<X, Y, Z> 0.125 texture {pigment {Blue*0.4} finish {specular 0.6}}
}



//############################################################################################################
     #if (ShowCylinders)
     //  The four nearest neighbors of each point may be obtained, in this
coordinate system,
     //  by adding one to each of the four coordinates, or by subtracting one
from each of the four coordinates,
     //  accordingly as the coordinate sum is zero or one.
     #declare FourD = array[4] {a, b, c, d}
     #declare NewPoint = array[4] {0, 0, 0, 0}
     #for (Adjustment, 0, 3)
      #for (Power, 1, 2)
       #declare Factor = pow (-1, Adjustment);
       #for (Coordinate, 0, 3)
        #if (Coordinate = Adjustment)
         #declare NewPoint[Coordinate] = FourD[Coordinate]+Factor;
        #else
         #declare NewPoint[Coordinate] = FourD[Coordinate];
        #end // end if
       #end // for Coordinate
       #declare a2 = NewPoint[0];
       #declare b2 = NewPoint[1];
       #declare c2 = NewPoint[2];
       #declare d2 = NewPoint[3];
       #if ( (a2+b2+c2)=0  | (a2+b2+c2)=1)
        #declare X2 = ( a2 + b2 - c2 - d2);
        #declare Y2 = ( a2 - b2 + c2 - d2);
        #declare Z2 = (-a2 + b2 + c2 - d2);
        #if (X=X2 | Y=Y2 | Z=Z2)
        #else
         cylinder {<X, Y, Z>, <X2, Y2, Z2>, 0.0725 pigment {Red}}
        #end // end degenerate cylinder check
       #end // end a2+b2+c2 check
      #end // end for Power
     #end // end for Adjustment
     #end // end if ShowCylinders

//############################################################################################################


    #end // end if
   #end // end for c
  #end // end for b
 #end // end for a
#end // end for d


Post a reply to this message


Attachments:
Download 'diamondstructure.png' (390 KB)

Preview of image 'diamondstructure.png'
diamondstructure.png


 

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