#include "colors.inc" camera { location <10,10,-120> look_at <0,0,0> } background { color <0.25,0.35,0.80> } light_source { <-10000, 60030, -28000> color White } // // Parameter Section // // You must use "merge" in the object declaration or you'll get weird results. #declare theObject = merge { cylinder{ <0,15,0>, <0,-15,0>, 7 } sphere { <0,0,0> 10 } texture { pigment { White } } }; #declare DistanceFromZero = 100;// must be further from <0,0,0> than any point on the object, suggest : furthest point * 2 #declare Iterations = 100; // accuracy, min 5, if you ShowTraceStart or ShowTraceEnd or ShowTraceLine a high value here might blow the memory #declare ShowTraceStart = 0; // 0 = no, 1 = yes , shows a sphere at the start of the trace line #declare ShowObject = 0; // 0 = no, 1 = yes , shows the CSG object being converted #declare ShowTraceEnd = 1; // 0 = no, 1 = yes , shows a sphere where the trace hits the CSG object #declare ShowTraceLine = 0; // 0 = no, 1 = yes , shows a cylinder representing the traced ray // // End Of Parameter Section // #declare rotateAmount = 360/Iterations; #fopen MyFile "Result.pov" write // write out the iterationCount #write (MyFile,"#include \"colors.inc\" ") #write (MyFile,"camera { location <10,10,-120> look_at <0,0,0> } ") #write (MyFile,"background { color <0.25,0.35,0.80> } ") #write (MyFile,"light_source { <-10000, 60030, -28000> color White } ") #write (MyFile," mesh { ") // create the arrays #declare row1 = array[Iterations]; #declare row2 = array[Iterations]; // initialise the arrays #declare loop = 0; #while(loop < Iterations) #declare row1[loop] = <0,0,0>; #declare row2[loop] = <0,0,0>; #declare loop = loop + 1; #end // iterate a count of hoops #declare Hoops = Iterations; // Hoops = x rotation #while(Hoops > 0) // iterate round a hoop #declare HoopPos = 360; // HoopPos = y rotation #declare aCount=0; // used to keep track of position in array #while(HoopPos > 0) //Declare the start Point #declare TraceStartPoint = <0,0,DistanceFromZero * -1>; //rotate the trace start start point #declare TraceStartPoint = vrotate(TraceStartPoint,); #if(ShowTraceStart=1) sphere { TraceStartPoint,.5 texture { pigment { Red } } } #end #declare TraceEnd = trace(theObject,<0,0,0>,TraceStartPoint); #if(ShowTraceLine=1) cylinder{TraceStartPoint,TraceEnd,0.1 texture { pigment { Blue } } } #end #if(Hoops=Iterations) #declare row1[aCount] = TraceEnd; #else #declare row2[aCount] = TraceEnd; #end #declare aCount = aCount + 1; //#write(MyFile,TraceEnd) #if(ShowTraceEnd=1) sphere { TraceEnd,.5 texture { pigment { Green } } } #end #declare HoopPos = HoopPos - rotateAmount; #end // if we are in the second or later hoop, write out the triangles #if(Hoops!=Iterations) #declare loop = 0; #while(loop < Iterations) // tie the begining of the array to the start #if(loop = 0) // part of a square #write(MyFile,"triangle {") #write(MyFile,row1[0]) #write(MyFile,row1[Iterations-1]) #write(MyFile,row2[0]) #write(MyFile,"}") //second part of the square #write(MyFile,"triangle {") #write(MyFile,row1[Iterations-1]) #write(MyFile,row2[Iterations-1]) #write(MyFile,row2[0]) #write(MyFile,"}") #end // standard square linking current lop to next points round loop // part of a square #if(loop < Iterations-2) #write(MyFile,"triangle {") #write(MyFile,row1[loop]) #write(MyFile,row1[loop+1]) #write(MyFile,row2[loop]) #write(MyFile,"}") //second part of the square #write(MyFile,"triangle {") #write(MyFile,row1[loop+1]) #write(MyFile,row2[loop+1]) #write(MyFile,row2[loop]) #write(MyFile,"}") #end #declare loop = loop + 1; #end // now move the second to up to be the first row #declare loop = 0; #while(loop < Iterations) #declare row1[loop] = row2[loop]; #declare loop = loop + 1; #end #end #declare Hoops = Hoops - 1; #end // write out the end of the mesh #write (MyFile, " texture { pigment { agate color_map {[0 White][.5 Red][1 Green]} } scale 5} ") #write (MyFile," } ") #fclose MyFile #if(ShowObject=1) object { theObject } #end