![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
soemthing curious happened as i tried out vlength.
my aim was to put random spheres on the floor and the code itself has to
avoid intersections.
whenever i test about vlength i always get intersections between spheres.
my formular
#if ( (vlength(Mylist[Temp]-Random_Place)) > (2*Radi) )
takes no effect, whatever i put in for Radi from 0 till 0.5.
if i proof differences of Radi above 0.5 i get an error message that my
array is uninitialized.
maybe anyone can say what went wrong with the code.
attached is the scene which is everytime the same.
//----------------------------------------------code starts
#local Count = 50;
#local Counter = 0;
#local ix = seed(15);
#local ze = seed(5);
#local Mylist = array[Count]
#local Mylist[0]= <3*rand(ix),0,3*rand(ze)>;
#local Radi = 0.1; //takes no effect from 0 till 0.5 and above
#local NoGood = 1;
#while (Counter < Count)
//assume, sphere makes intersection
//if vlength > 2*Radi then draw sphere
#local NoGood = 1;
#while (NoGood)
#local Random_Place = <3*rand(ix),0,3*rand(ze)>;
#local Temp = 0;
#while (Temp <= Counter)
#if ( (vlength(Mylist[Temp]-Random_Place)) > (2*Radi) )
#local NoGood = 0;
#local Temp = Count+1;
#end
#local Temp = Temp + 1;
#end //while(Temp..
#end //while(NoGood)
#local Mylist[Counter] = Random_Place;
sphere {
<0,0,0>,1
scale <0.1,0.1,0.1>
pigment{color Green}
translate y*0.1
translate Mylist[Counter]
}
#local Counter = Counter + 1;
#end //while
//----------------------------------------------code ends
Post a reply to this message
Attachments:
Download 'vlength.jpg' (15 KB)
Preview of image 'vlength.jpg'
![vlength.jpg](/povray.binaries.images/attachment/%3C3c36ff40%40news.povray.org%3E/vlength.jpg?ttop=443840&toff=9900&preview=1)
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
marabou wrote:
> soemthing curious happened as i tried out vlength.
> my aim was to put random spheres on the floor and the code itself has to
> avoid intersections.
> whenever i test about vlength i always get intersections between spheres.
> my formular
> #if ( (vlength(Mylist[Temp]-Random_Place)) > (2*Radi) )
I think the problem in your code is that if even at one point the vlength >
2*Radi (and the propability is quite high for that) then it doesn't matter
if at some other point the vlength < 2*Radi.
I'd correct the code for you but my brain isn't functioning properly atm :)
-Jide
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Wasn't it marabou who wrote:
>
>soemthing curious happened as i tried out vlength.
>my aim was to put random spheres on the floor and the code itself has to
>avoid intersections.
>whenever i test about vlength i always get intersections between spheres.
>my formular
>#if ( (vlength(Mylist[Temp]-Random_Place)) > (2*Radi) )
>takes no effect, whatever i put in for Radi from 0 till 0.5.
>if i proof differences of Radi above 0.5 i get an error message that my
>array is uninitialized.
>maybe anyone can say what went wrong with the code.
>attached is the scene which is everytime the same.
Your code looks for a random location for which there is at least one
ball that is at least (2*Radi) away. It only needs to find one such ball
to decide that the new location is OK, therefore it considers just about
everywhere to be OK.
What you ought to be looking for is a location for which *all* the balls
are at least (2*Radi) away. Like:-
#local Good = 0;
#while (Good = 0)
#local Random_Place = <3*rand(ix),0,3*rand(ze)>;
#local Temp = 0;
#local Good = 1;
#while (Temp < Counter)
#if ( (vlength(Mylist[Temp]-Random_Place)) < (2*Radi) )
#local Good = 0;
#end
#local Temp = Temp + 1;
#end //while(Temp..
#end //while(Good=0)
You now have to keep Radi below about 0.17 or there won't be anywhere
left to place the 50th ball, and the code will loop forever.
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Jide wrote:
> I'd correct the code for you but my brain isn't functioning properly atm
:)
>
> -Jide
Ok ok. Couldn't resist. Hope outlook won't screw up the wrapping.
Oh and btw. If at some point it parses WAY too long then lower
NumBalls or increase the possible area of Random_Place (ie.
<5*rand(Seed),0,5*rand(Seed)>.
//----------------------------------------------code starts
#local NumBalls = 100;
#local Counter = 1;
#local Seed = seed(4);
#local Mylist = array[NumBalls]
#local Mylist[0]= <3*rand(Seed),0,3*rand(Seed)>;
#local Radi = 0.1; //takes no effect from 0 till 0.5 and above
#while (Counter < NumBalls)
#local Good = 1; //Assume there is no intersection
#local Random_Place = <3*rand(Seed),0,3*rand(Seed)>;
#local Temp = 0;
#while (Temp < Counter)
#if ( (vlength(Mylist[Temp]-Random_Place)) < (2*Radi) )
#local Good = 0;
//But if even 1 intersection is found then reject the random point
#end
#local Temp=Temp+1;
#end //while (Temp <= Counter)
#if(Good)
#local Mylist[Counter] = Random_Place;
sphere {
<0,0,0>,Radi
pigment{color Green}
translate y*Radi
translate Mylist[Counter]
}
#local Counter=Counter+1;
#end //if (Good)
#end //while
//----------------------------------------------code ends
-Jide
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Mike Williams wrote:
> Your code looks for a random location for which there is at least one
> ball that is at least (2*Radi) away. It only needs to find one such ball
> to decide that the new location is OK, therefore it considers just about
> everywhere to be OK.
I knew I shouldn't have waited with the code.
Well atleast I explained this (well sort of anyway) before you. And the
small brain tease was good for me :)
-Jide
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
okay, you inverted my look of this. with your code you get an endless loop.
i do not know, but it has to do with the line
#while (Temp < Counter)
Mike Williams wrote:
>
> #local Good = 0;
> #while (Good = 0)
> #local Random_Place = <3*rand(ix),0,3*rand(ze)>;
> #local Temp = 0;
> #local Good = 1;
> #while (Temp < Counter)
> #if ( (vlength(Mylist[Temp]-Random_Place)) < (2*Radi) )
> #local Good = 0;
> #end
> #local Temp = Temp + 1;
> #end //while(Temp..
> #end //while(Good=0)
>
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
your code works really fine! seems as i code too complicated...
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Now the question is: What happens, if there isn't any position left,
for any sphere to be placed ?
Probably you'll need "emergency-exit", so I use to add a counter, how
often I try to position a sphere ...
--
"Somehow what you suggest is like suggesting to add drills \ jan### [at] lzer net
to cars so you can drill for oil when you run out of fuel. \
Sure you could do it, but it might not be the most practical > Jan
solution." [Thorsten Froehlich in p.u.p] / Walzer
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |