POV-Ray : Newsgroups : povray.binaries.scene-files : Array problem Server Time
1 Sep 2024 18:18:37 EDT (-0400)
  Array problem (Message 1 to 2 of 2)  
From: Yadgar
Subject: Array problem
Date: 12 Aug 2004 16:46:55
Message: <411bd73f@news.povray.org>
High!

I'm trying to set up an array for the position vectors of seven planets, 
  but whenever I start the script, I get the error message


File: E:\Povscn\system.pov  Line: 20
#while (a<7)

   PlanetPoss[a] <----ERROR

Parse Error: Expected 'object or directive', float function 'float 
identifier' found instead

Here is the code:

#declare Planets=array[3][7]
{
   { 3750000, 19400000, 40100000, 104720000, 201000000, 338000000, 
949000000 }
   { 1289, 2560, 12784, 63879, 34974, 51075, 10451 }
   { 12, 90, 104, 56, 32, 253, 4 }
}

#declare PlanetPoss=array[7] { 0, 0, 0, 0, 0, 0, 0 }
#declare a=0;
#while (a<7)
   PlanetPoss[a]=StarPos+Planets[0][a]*<sin(Planets[2][a]*(pi/180)), 0, 
cos(Planets[2][a]*(pi/180))>
   #declare a=a+1;
#end

(astronomers: please forgive me that I, for the time being, assumed 
circular orbits!)

See you in Khyberspace!

Yadgar


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array problem
Date: 12 Aug 2004 23:07:34
Message: <411c3076$1@news.povray.org>
Yadgar wrote:
> High!

Hi

> I'm trying to set up an array for the position vectors of seven planets, 
>  but whenever I start the script, I get the error message
> 
> 
> File: E:\Povscn\system.pov  Line: 20
> #while (a<7)
> 
>   PlanetPoss[a] <----ERROR
> 
> Parse Error: Expected 'object or directive', float function 'float 
> identifier' found instead
> 
> Here is the code:
> 
> #declare Planets=array[3][7]
> {
>   { 3750000, 19400000, 40100000, 104720000, 201000000, 338000000, 
> 949000000 }
>   { 1289, 2560, 12784, 63879, 34974, 51075, 10451 }
>   { 12, 90, 104, 56, 32, 253, 4 }
> }
> 
> #declare PlanetPoss=array[7] { 0, 0, 0, 0, 0, 0, 0 }
> #declare a=0;
> #while (a<7)
>   PlanetPoss[a]=StarPos+Planets[0][a]*<sin(Planets[2][a]*(pi/180)), 0, 
> cos(Planets[2][a]*(pi/180))>
>   #declare a=a+1;
> #end
...

Yadgar, you get that error message because that line is
missing a #declare statement.


Here are some further comments:

- The line also lacks a semicolon at the end.
- You have forgotten to initialize the StarPos variable.
- You cannot assign a vector to elements in an array that
   already contains float values.
- You should avoid making variable names that consists of
   lowercase letters only.
- POV-Ray has a radians() function that converts from
   degrees to radians.
- Your vector expression with cos() and sin() functions
   can be replaced with a vrotate() statement.

Some code that works:


#declare Planets =
   array[3][7] {
     { 3.75e6, 1.94e7, 4.01e7, 1.0472e8, 2.01e8, 3.38e8, 9.49e8 }
     { 1289, 2560, 12784, 63879, 34974, 51075, 10451 }
     { 12, 90, 104, 56, 32, 253, 4 }
   }

#declare StarPos = <0, 0, 0>;

#declare PlanetPos = array[7]

#declare A = 0;
#while (A < 7)
   #declare PlanetPos[A] =
     StarPos + Planets[0][A]*vrotate(z, Planets[2][A]*y);
   #declare A = A + 1;
#end // while


-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

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