POV-Ray : Newsgroups : povray.general : Math problem : Re: Math problem Server Time
12 Aug 2024 13:24:07 EDT (-0400)
  Re: Math problem  
From: Andrew Cocker
Date: 16 Mar 1999 19:20:26
Message: <36eef54a.0@news.povray.org>
Thankyou all.

--
Andy


Josh English wrote in message <36E### [at] spiritonecom>...
>Okay, barring any stupid coding problems, here we go with an example. It will only to
two
>dimentions right now and it not even complete there, but it provides a starting
point:
>
>#declare Max_X = 10; // number of spheres along X Axis
>#declare Max_Z = 10; // number of spheres along Y Axis
>#declare Base_Radius = 1; // radius of a sphere that is not under the influence
>#declare Max_Radius = 2; // radius of the sphere that is under the influence
>#declare Steps = 5; // the fifth sphere from the center of the effect will be at Base
Radius
>
>#declare Each_Step = (Max_Radius - Base_Radius)/Steps; // Quick formula to determine
>
>// how different adjacent spheres will be
>#declare separation = 4; // the distance between sphere centers
>
>
>#declare MyGrid = array[Max_X][Max_Z]
>
>// initalize the array, giving everything a value of Base Radius
>#macro InitGrid ()
>  #declare i = 0;
>  #while ( i < Max_X )
>    #declare j = 0;
>    #while ( j < Max_Z )
>      #declare MyGrid[i][j] = Base_Radius;
>      #declare j = j + 1;
>    #end
>    #declare i = i + 1;
>  #end
>#end
>
>
>#macro DrawGrid ()
>  #declare i = 0;
>  #while (i < Max_X )
>  #declare j = 0;
>    #while ( j < Max_Z )
>      sphere { <i*separation,2,j*separation> MyGrid[i][j] // Y value is merely
temporary
>               pigment { red 1 }
>               finish { phong 1 } }
>      #declare j = j + 1;
>    #end
>    #declare i = i + 1;
>  #end
>#end
>
>#macro CheckCord(a,b) // we will use this one extensively
>  ( (a < Max_X) & (a >= 0) & (b < Max_Z ) & ( b >= 0 ) )
>#end
>
>#macro AlterGrid (m,n) // this macro changes the spheres in the gird
>  #declare MyGrid[m][n] = Max_Radius;
>  #declare cvar = 1;
>  #while (cvar < Steps )
>
>    #declare Temp_Radius =  Max_Radius- (cvar * Each_Step );
>
>    #if (CheckCord(m + cvar, n) ) // spheres in the +X direction
>      #declare MyGrid[m+cvar][n] = Temp_Radius;
>    #end
>
>    #if (CheckCord(m-cvar, n) ) // spheres in the -X direction
>      #declare MyGrid[m-cvar][n] = Temp_Radius;
>    #end
>
>    #if (CheckCord(m, n+cvar) ) // spheres in the +Z direction
>      #declare MyGrid[m][n+cvar] = Temp_Radius;
>    #end
>
>    #if (CheckCord(m, n-cvar) ) // spheres in the -Z direction
>      #declare MyGrid[m][n-cvar] = Temp_Radius;
>    #end
>
>    #if ( CheckCord (m+cvar,n+cvar) ) // spheres in +X,+Z diagonal
>      #declare MyGrid[m+cvar][n+cvar] = Temp_Radius;
>    #end
>
>    #if ( CheckCord (m+cvar,n-cvar) ) // spheres in the +X,-Z direction
>      #declare MyGrid[m+cvar][n-cvar] = Temp_Radius;
>    #end
>
>    #if ( CheckCord (m-cvar,n+cvar) ) // spheres in -X,+Z direction
>      #declare MyGrid[m-cvar][n+cvar] = Temp_Radius;
>    #end
>
>    #if ( CheckCord (m-cvar,n-cvar) ) // spheres in the -X,-Z direction.
>      #declare MyGrid[m-cvar][n-cvar] = Temp_Radius;
>    #end
>
>    #declare cvar = cvar + 1;
>  #end
>
>#end // AlterGrid
>
>
>InitGrid()
>
>AlterGrid (4,5)
>
>DrawGrid()
>
>Sadly, this still misses 24 cubes in the grid. I'm sure there's an easier way to do
it,
and
>this is mostly brute force, but it works.
>
>
>Andrew Cocker wrote:
>
>> I hope someone can help get me started with my latest experiment.
>>
>> I want to try out arrays. My plan is to create a cube made up of, say, 20x20x20
tiny
>> spheres. If I pick one of these spheres and designate it to be the centre of the
effect
>> I'm trying to create, and scale it by a factor of 2, how do I make the surrounding
spheres
>> get gradually smaller until 5 spheres away they are back to scale 1? I plan to
animate
the
>> effect so that the centre of the effect moves around inside the array of spheres.
>>
>> I have heard the term 'fields' used. Is this the method I should use, and if so,
could
>> anyone suggest either how it is done, or else point me in the direction of where I
can
>> find more out about it.
>>
>> I am not a mathematician or a programmer, but I hand-code only so I should be able
to
make
>> use of any suggestions, as long as you assume large levels of ignorance on my part.
>>
>> Many thanks in anticipation.
>>
>> -----------
>> Andy
>


Post a reply to this message

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