POV-Ray : Newsgroups : povray.newusers : Spheres in a sphere : Re: Spheres in a sphere Server Time
9 Jun 2024 03:03:38 EDT (-0400)
  Re: Spheres in a sphere  
From: nonostar
Date: 24 Mar 2014 11:45:00
Message: <web.533052679f83cd68419a77410@news.povray.org>
"nonostar" <nomail@nomail> wrote:
> "nonostar" <nomail@nomail> wrote:
> > Alain <kua### [at] videotronca> wrote:

> > > > Hello,
> > > >
> > > > i want to make spheres in a sphere. I know there is a function for that :
> > > > VRand_In_Obj.
> > > >
> > > > But i want to prevent the intersection of spheres between them.
> > > >
> > > > How can i do proceed to do that ?
> > > >
> > > > Thanks for your help
> > > >
> > > >
> > >
> > > A common and simple solution for equaly sized spheres:
> > > Create an array large enough to contain the locations of all your spheres.
> > > Randomly place about 10 to 100 spheres. Make sure that the new spheres
> > > are located at twice the individual radius. Each acceptable location is
> > > placed in the array.
> > > Make an union of test spheres, each having twice the radius of your
> > > intended spheres.
> > > Now, for the next spheres, start with an insideness test against that
> > > union. There is an is_inside function that return 0 if outside an object
> > > and 1 if inside.
> > > Continue for another batch of spheres that will also be used to create
> > > another union.
> > > Repeat untill you have all yours spheres, or you need to many tries to
> > > find a suitable location.
> > >
> > > Finaly, using the locations from your array, place the actual spheres.
> > >
> > > Using a bunch of unions of double sized spheres is much faster than
> > > testing for every previous spheres.
> > >
> > > This don't ensure the most optimum packing, but ensure that all spheres
> > > are non-intersecting.
> > >
> > > If you search in povray.binaries.scene-files, you can find some working
> > > code made exactly for that purpose.
> > >
> > >
> > > Alain
> >
> > Thanks for these answers.
> > I will try to do it step by step with time because i am a new user on this
> > software.
> > i inform you.
>
> Hello
>
> This is that i did. But some sphere are again to gether.
> Where is the problem?
> I use the function : inside.
>
> #include "rand.inc"
> #declare Random_1 = seed (12433);
> #declare Tableau=array[3000]
> #declare Tableau2=array[3000]
> #declare Variable=0;
> #while (Variable<3000)
> #declare Tableau[Variable]= VRand_In_Sphere(Random_1);
> #declare Variable=Variable+1;
> #end
>
> #declare VariableX=0;
> #declare Variable=1;
> #declare S1=Tableau[0];
> #declare B1=sphere{S1 0.05 pigment {rgb <1,1,0>}}
> #declare Point=Tableau[1]  ;
> #while (Variable<3000)
>     #while (VariableX<=Variable)
>         #if (inside(B1,  Point))
>         #declare Tableau2[Variable]=0 ;
>         #declare VariableX=VariableX+1;
>         #declare S1=Tableau[VariableX];
>         #else
>         #declare Tableau2[Variable]=0.05;
>         #end
>     #declare VariableX=VariableX+1;
>     #end
>     #declare Variable=Variable+1;
>
> #end
> //---------------------------------------------------------
>
> #declare Variable=1;
> #declare Variable2=1;
> #while (Variable<3000)
> #declare S2=Tableau[Variable];
> #declare S3=Tableau2[Variable];
> sphere{S2 S3 pigment{rgb<1,1,0>}}
> #declare Variable=Variable+1;
> #declare Variable2=Variable2+1;
> #end
>
>
> Can you help me?
>
> Thanks

I improve my code but spheres stay together.
This is the new code :
#include "rand.inc"
#declare Random_1 = seed (12433);
#declare ArrayPosition=array[3000]
#declare ArrayRayon=array[3000]
#declare Variable=0;

#while (Variable<3000)
        #declare ArrayPosition[Variable]=VRand_In_Sphere(Random_1);
        #declare ArrayRayon[Variable]=0.05;
        #declare Variable=Variable+1;
#end

#declare Variable1=0;
#declare Variable2=1;

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

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

#end

#declare Variable=0;
#while (Variable<2999)
sphere{ArrayPosition[Variable] ArrayRayon[Variable] pigment {rgb
<0.85,0.85,0.85>}}
#declare Variable=Variable+1;
#end


Any suggestions about my error ?

Thanks


Post a reply to this message

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