|
|
Hi all -
Not quite sure when I graduate from the "new user group", so here goes:
I am trying to model a moving asteroid belt (for those keeping score, its a
different project then my OTHER question about asteroids - that was for a
still ;-)
In order to do this, i have set up arrays to contain the terms used to
calculate an orbit, and then while loops with random number streams to fill
the arrays. These arrays are then used to calculate the orbit and the orbit
determines the placement of the sphere "asteroid".
Long explanations to get to the problem ... sorry
the problem is that the first time i call an argument from an array, i get
an "uninitialized array element" error. I've included the code and error
below, thanks in advance for taking the time.
-OpalPlanet
#include "colors.inc"
#include "stones.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "textures.inc"
#include "rand.inc"
camera { location <00,00,-20> look_at 0 }
light_source { <5, 5, -10> White }
//the asteroid field, a torus between 2.2 and 4 AU
//#declare Field =
torus{
3.1, .09
rotate -90*x
pigment {Green}
hollow
}//end torus
///////////////////////////////////////////
//declare and initialize the arrays to hold the orbital elements and physcal
parameters of the asteroids
//////////////////////////////////////////
#declare n_asteroids = 10;
// Input parameters
#declare axis = array[n_asteroids] // semi-major axis, in AU
#declare axis[0] = 0.0 ;
#declare ecc = array[n_asteroids] // orbital eccentricity
#declare ecc[0] = 0.0 ;
#declare inc = array[n_asteroids] // orbital inclination
#declare inc[0] = radians(0.0) ;
#declare wbar = array[n_asteroids] // longitude of pericenter (not
argument!)
#declare wbar[0] = radians(0.0) ;
#declare Omega = array[n_asteroids] // longitude of ascending node
#declare Omega[0] = radians(0.0) ;
#declare mean_long = array[n_asteroids] // mean longitude at initial time
#declare mean_long[0] = radians(0.0) ;
#declare rad = array[n_asteroids] // radius, in Earth diameters
#declare rad[0] = 0.0 ;
// Calculated variables
#declare n = array[n_asteroids] // mean motion (calculated)
#declare n[0] = 0.0 ;
#declare tau = array[n_asteroids] // time past pericenter (years,
calculated)
#declare tau[0] = 0.0 ;
#declare w = array[n_asteroids] // argument of pericenter
#declare w[0] = radians(0.0) ;
////////////fill the arrays using random number streams and loops
//axis array
#declare i = 0; //counter
#declare I = seed(1);
#while (i<n_asteroids - 1)
#declare axis[i] = 3.1 + rand(I);
#declare i = i+1;
#end// while
//ecc array
#declare j = 0; //counter
#declare J = seed(3);
#while (j<n_asteroids - 1)
#declare ecc[j] = (1.7 + rand(J))/10;
#declare j = j+1;
#end// while
//inc array
#declare k = 0; //counter
#declare K = seed(5);
#while (k<n_asteroids - 1)
#declare inc[k] = radians(5+10*rand(K));
#declare k = k+1;
#end// while
//wbar array
#declare l = 0; //counter
#declare L = seed(7);
#while (l<n_asteroids - 1)
#declare wbar[l] = radians(16.871 + 320 * rand(L));
#declare l = l+1;
#end// while
//Omega array
#declare m = 0; //counter
#declare M = seed(9);
#while (m<n_asteroids - 1)
#declare Omega[m] = radians(50+50*rand(M));
#declare m = m+1;
#end// while
//mean_long array
#declare o = 0; //counter
#declare O = seed(12);
#while (o<n_asteroids - 1)
#declare mean_long[o] = radians(102+80*rand(O));
#declare o = o+1;
#end// while
//n array
#declare q = 0; //counter
#declare Q = seed(56);
#while (q<n_asteroids - 1)
#declare n[q] = radians(360)/(sqrt(axis[q]*axis[q]*axis[q]));
#declare q = q+1;
#end// while
//tau array
#declare r = 0; //counter
#declare R = seed(46);
#while (r<n_asteroids - 1)
#declare tau[r] = (wbar[r] - mean_long[r])/n[r];
#declare r = r+1;
#end// while
//w array
#declare s = 0; //counter
#declare S = seed(85);
#while (s<n_asteroids - 1)
#declare w[s] = Omega[s] - wbar[s];
#declare s = s+1;
#end// while
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Now put the asteroids in, based on the simulation time //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#declare total_time = 10.0; // Total simulation time (years)
#declare my_time = clock*total_time;
#declare p=0;
#while(p <= n_asteroids-1)
////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate position of asteroid //
////////////////////////////////////////////////////////////////////////////////////////////////////
#declare M = (n[p]*(my_time - tau[p])); //this is where i get the error
// M = mean anomoly
#declare term1 = ((2.0*ecc[p] -
((1.0/4.0)*ecc[p]*ecc[p]*ecc[p]))*sin(M));
#declare term2 = ((5.0/4.0)*(ecc[p]*ecc[p])*sin(2.0*M));
#declare term3 = ((13.0/12.0)*(ecc[p]*ecc[p]*ecc[p])*sin(3.0*M));
#declare f = (M + term1 + term2 + term3); // f = true anomoly
#declare rp = axis[p]*(1.0 - ecc[p]*ecc[p])/(1.0 + ecc[p]*cos(f));
// r = heliocentric distance
#declare xp = rp * ( cos(f + w[p]) * cos(Omega[p]) - sin(f + w[p]) *
cos(inc[p]) * sin(Omega[p]) );
#declare yp = rp * ( cos(f + w[p]) * sin(Omega[p]) + sin(f + w[p]) *
cos(inc[p]) * cos(Omega[p]) );
#declare zp = rp * sin(f + w[p]) * sin(inc[p]);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Place the asteroid in the scene //
////////////////////////////////////////////////////////////////////////////////////////////////////
sphere { <0,0,0> 1
texture {
pigment{ Yellow}
finish {Dull ambient 0.25 diffuse 0.5} }
rotate <-90,0,0>
translate <xp,yp,-zp> // NOTE: positive z coordinate because we've
set up a right handed coordiante system in the camera
no_shadow }
////////////////////////////////////////////////////////////////////////////////////////////////////
// Move on to the next asteroid //
////////////////////////////////////////////////////////////////////////////////////////////////////
#declare p = p+1;
#end // This ends the 'while' loop
//end program
and this is the error
#declare M = n[p]
Parse Error: Attempt to access uninitialized array element.
Post a reply to this message
|
|
|
|
"OpalPlanet" <ecs### [at] msncom> wrote:
> #declare M = (n[p]*(my_time - tau[p])); //this is where i get the error
> Parse Error: Attempt to access uninitialized array element.
It's a good old off-by-one error due to the single character: "=" :-)
#while(p <= n_asteroids-1)
You could delete the = here, but it looks like what you'd really want to do
is add it to your other loops. I normally leave the "=" and "-1" off, and
just use "<" like #while (whatever < n_asteroids)
Charles
Post a reply to this message
|
|