POV-Ray : Newsgroups : povray.newusers : Spheres in a sphere Server Time
14 May 2024 13:31:46 EDT (-0400)
  Spheres in a sphere (Message 11 to 17 of 17)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: nonostar
Subject: Re: Spheres in a sphere
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

From: Alain
Subject: Re: Spheres in a sphere
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

From: Alain
Subject: Re: Spheres in a sphere
Date: 24 Mar 2014 13:51:26
Message: <5330709e@news.povray.org>


>
> 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]

ALL your spheres have the exact same radius. This mean that the above 
array is superfluous. Replace it with a simple scalar variable.

#declare Rayon = 0.05;

> #declare Variable=0;
>
> #while (Variable<3000)
>          #declare ArrayPosition[Variable]=VRand_In_Sphere(Random_1);

Remove the following line.
>          #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>}}

Use your simple Rayon variable MULTIPLIED by 2!
Also, as this object will NEVER show, it don't need to have any pigment, 
giving you this:
#declare Object=sphere{ArrayPosition[Variable1] Rayon*2}

Doubling "Rayon" ensure that the points you find are far enough from the 
others to prevent any spheres from overlapping.

Make the same change in the loop below:

> #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]
> Rayon*2 }
>                  #end
>          #end
>          #declare Variable2=(Variable2+1);
>          #declare Variable1=0;
>          #declare Object=sphere{ArrayPosition[Variable1] Rayon*2}
>
>          #declare Point=ArrayPosition[Variable2];
>
> #end
>

The following spheres are those that ARE visible and need the pigment.

> #declare Variable=0;
> #while (Variable<2999)
> sphere{ArrayPosition[Variable] Rayon pigment {rgb
> <0.85,0.85,0.85>}}
> #declare Variable=Variable+1;
> #end
>
>
> Any suggestions about my error ?
>
> Thanks
>
>

PS.: If you have trouble in english, send me your e-mail address. French 
is my native language, and your naming suggest that it's the same for you.



Alain


Post a reply to this message

From: nonostar
Subject: Re: Spheres in a sphere
Date: 24 Mar 2014 14:40:00
Message: <web.53307b699f83cd6812fd452f0@news.povray.org>
In fact i found my error. The radius of my object has to have a radius*2. But
now  i have wholes in my sphere. How can i improve it ?

Thanks


Post a reply to this message

From: nonostar
Subject: Re: Spheres in a sphere
Date: 24 Mar 2014 15:30:01
Message: <web.533087339f83cd6812fd452f0@news.povray.org>
"nonostar" <nomail@nomail> wrote:
> In fact i found my error. The radius of my object has to have a radius*2. But
> now  i have wholes in my sphere. How can i improve it ?
>
> Thanks


I didn't see your message. I am sorry about this. Indeed i speak french. How can
i send you a private message ? I didn't found the option in this forum.

Thanks again


Post a reply to this message

From: Stephen
Subject: Re: Spheres in a sphere
Date: 24 Mar 2014 16:54:10
Message: <53309b72@news.povray.org>
On 24/03/2014 7:27 PM, nonostar wrote:
> I didn't see your message. I am sorry about this. Indeed i speak french. How can
> i send you a private message ? I didn't found the option in this forum.


There are no PM's on this forum. It is old fashioned, it is a news group.
There is an international forum, where non-English threads are.

-- 
Regards
     Stephen

I solemnly promise to kick the next angle, I see.


Post a reply to this message

From: Stephen
Subject: Re: Spheres in a sphere
Date: 24 Mar 2014 16:56:04
Message: <53309be4@news.povray.org>
On 24/03/2014 8:54 PM, Stephen wrote:
> There is an international forum, where non-English threads are.

Sorry, I forgot the link. :-(

http://news.povray.org/povray.international/


-- 
Regards
     Stephen

I solemnly promise to kick the next angle, I see.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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