POV-Ray : Newsgroups : povray.general : Problems performing trace() on object Server Time
15 Nov 2024 03:23:41 EST (-0500)
  Problems performing trace() on object (Message 1 to 5 of 5)  
From: Mike Thorn
Subject: Problems performing trace() on object
Date: 11 Dec 2004 20:07:39
Message: <41bb99db@news.povray.org>
I know lots of you have used trace() quite recently, so I hope you'll be 
able to help me out here. :)

I have a heightfield. A big one. As in, 600x500. I want to place battle 
droids (similar to the one I posted in p.b.i earlier this week) on it. 
It would be nice to spread them out over about half of it in on the 
z-axis, if that's even possible, (but I thought I heard somewhere that 
it's not) but most importantly I just want them spread over the width of 
the entire field.

So I'm using trace() to position them randomly at the proper height. 
That works. Very well, in fact. However, they only get spread over about 
an eighth of the image - halfway across and about a quarter way down.

Here's the slightly modified code I copied from Gilles' xfrog tree 
conversion page ("battlefield" is the heightfield and "droid+gun.pov" is 
the file which contains the droid object definition. "Inter+y*19" is 
necessary to raise the droid to the proper height above the field):

   #include "droid+gun.pov"
   #declare i=1;
   #declare rd=seed(2);
   #while (i < 25) // loop 49 droids
     #declare Norm=<0,0,0>;
     #declare Start = x*(-300*rand(rd)) + z*(250*rand(rd));
     #declare Inter= trace ( battlefield, Start, y, Norm );
     #if (vlength(Norm)>0) // If Norm = <0,0,0> no intersection is found
       object{droid rotate y*1*rand(rd) translate Inter+y*19}
     #end
     #declare i=i+1;
   #end

Is there a reason obvious to anyone why it's doing this? I can provide 
the render if necessary.

Thanks,

~Mike


Post a reply to this message

From: Tim Nikias
Subject: Re: Problems performing trace() on object
Date: 11 Dec 2004 20:32:21
Message: <41bb9fa5$1@news.povray.org>
First: Where's your heightfield placed? Centered on the origin? Because,
without scalement or translation, it ranges from <0,0,0> to <1,1,1>.
Second: The script only covers the area from <-300,250,0> to <0,0,0>, not
more. If you want it to spread from <-300,250,0> to <300,0,0>, you should
modify this line:
#declare Start = x*(-300*rand(rd)) + z*(250*rand(rd));
to this:
#declare Start = x*(-300*(rand(rd)*2-1)) + z*(250*rand(rd));

That aside, random placement of course has some issues. Even distribution
with a little random noise might work better. But that's just my 2 cents.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: stm31415
Subject: Re: Problems performing trace() on object
Date: 11 Dec 2004 20:35:00
Message: <web.41bb9fe127cc0c29acced0c50@news.povray.org>
>      #declare Start = x*(-300*rand(rd)) + z*(250*rand(rd));


Have you tried increasing the y? If you happen to be starting on the wrong
side, you'd never see the droid.

-S
5TF!


Post a reply to this message

From: Mike Thorn
Subject: Re: Problems performing trace() on object
Date: 11 Dec 2004 20:40:27
Message: <41bba18b$1@news.povray.org>
Tim Nikias wrote:
> First: Where's your heightfield placed? Centered on the origin? Because,
> without scalement or translation, it ranges from <0,0,0> to <1,1,1>.

Translated <.-5,.009, -.5> and then scaled <600, 75, 500>.

> Second: The script only covers the area from <-300,250,0> to <0,0,0>, not
> more. If you want it to spread from <-300,250,0> to <300,0,0>, you should
> modify this line:
> #declare Start = x*(-300*rand(rd)) + z*(250*rand(rd));
> to this:
> #declare Start = x*(-300*(rand(rd)*2-1)) + z*(250*rand(rd));
> 
> That aside, random placement of course has some issues. Even distribution
> with a little random noise might work better. But that's just my 2 cents.

I didn't think of trying even distro. That'll be version 2. :)

Your line above works great, with the small exception that they seem to 
be more bunched up on the left side than the right. Which is okay, I 
think, but just for curiosity's sake, is there a reason for that?

Thanks a bunch, Tim!!

~Mike


Post a reply to this message

From: Tim Nikias
Subject: Re: Problems performing trace() on object
Date: 11 Dec 2004 20:53:35
Message: <41bba49f@news.povray.org>
> I didn't think of trying even distro. That'll be version 2. :)

Well, there are even distro which work quite well. E.g. the following:

#declare MaxRad = 1;
#local Counter=0;
#while (Counter<=TotalAmount)

#declare Pos=vrotate(<MaxRad ,0,0>,y*(360/.618*Counter)) *
sqrt(Counter/TotalAmount);
sphere{Pos,.05 pigment{rgb x}}

#declare Counter=Counter+1;
#end

produces a nice, even distribution, without looking like a grid.

(Here's a link for further insight into the code above:
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#seeds).

> Your line above works great, with the small exception that they seem to
> be more bunched up on the left side than the right. Which is okay, I
> think, but just for curiosity's sake, is there a reason for that?

I'm not sure, but it may depend on how many times you call the rd-random
stream. AFAIK, the stream jumps back and forth between positions more to 0
and more to 1, but over hundreds of iterations, this evens out. Just try a
different seed, or, if my theory would be correct, just add a rand(rd)
before entering the #if (vlength())-case.

Another thing I've noticed: vlength() will always return positive numbers or
0, so instead of
#if (vlength(Norm)>0)
you could just as easily write
#if (vlength(Norm)
because POV-Ray interprets 0 as false, but !=0 as true.

> Thanks a bunch, Tim!!

No problem, that was an easy one. :-)

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

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