POV-Ray : Newsgroups : povray.newusers : Spheres in a sphere : Re: Spheres in a sphere Server Time
1 Jun 2024 13:35:05 EDT (-0400)
  Re: Spheres in a sphere  
From: Alain
Date: 24 Mar 2014 13:36:47
Message: <53306d2f$1@news.povray.org>

> I tried to improve this.
>
> But i get a problem.
> When i ran i had this message : "Attempt to access unitialized array elemement"
> for this line :
>
>   #declare Point=ArrayPosition[Variable2];

This mean that you try to access an element of ArrayPosition that have 
never been set to any value.

>
>
> i give you my code.
>
> #include "rand.inc"
> #declare Random_1 = seed (12433);
> #declare ArrayPosition=array[3000]
> #declare ArrayRayon=array[3000]
> #declare Variable=0;
>
Add:
#declare Rayon = 0.05;

> #while (Variable<30)
>          #declare ArrayPosition[Variable]=VRand_In_Sphere(Random_1);
>          #declare ArrayRayon[Variable]=0.05;
Comment out the line above.

>          #declare Variable=Variable+1;
> #end
>
> #declare Variable1=0;
> #declare Variable2=1;
>
> #declare Object=sphere{ArrayPosition[Variable1] ArrayRayon[Variable1] pigment
> {rgb <1,1,0>}};

As you have constant radius, it would be beter to use a simple variable 
here. This become this:

#declare Object=sphere{ArrayPosition[Variable1] Rayon pigment{rgb <1,1,0>}}

Note: In this case, the ";" is not needed. It's mandatory when declaring 
a simple numerical variable or a vector. It's never needed when 
declaring an object.

> #declare Point=ArrayPosition[Variable2];
>
> #while (Variable2<3000)
>          #while (Variable1<Variable2)
>                  #if(inside(Object,Point))

Try replacing this by:
#if(inside(Object, ArrayPosition[Variable2] ))

>                  #declare ArrayRayon[Variable2]=0;
>                  #declare Variable1=Variable2;
>                  #else
>                  #declare Variable1=Variable1+1;
>                  #declare Object=sphere{ArrayPosition[Variable1]
> ArrayRayon[Variable1] pigment {rgb <1,1,0>}};
>                  #end
>          #end
>          #declare Variable2=(Variable2+1);
>          #declare Variable1=0;
>          #declare Object=sphere{ArrayPosition[Variable1] ArrayRayon[Variable1]
> pigment {rgb <1,1,0>}};
>          #declare Point=ArrayPosition[Variable2];
>
> #end
>

It's here that you create the spheres to be visible. The previous ones 
are only used for the placement.

> #declare Variable=0;
> #while (Variable<3000)
Change this:
> sphere{ArrayPosition[Variable] ArrayRayon[Variable] pigment {rgb <1,1,0>}}

To this:
sphere{ArrayPosition[Variable] Rayon/2 pigment {rgb <1,1,0>}}

> #declare Variable=Variable+1;
> #end
>
>
> where is the mistake ?
>
> I don't understand.
>
> Thanks for your help
>
>

The spheres that you use to test the placement MUST be twice as large as 
the ones you intend to be visible.



Alain


Post a reply to this message

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