POV-Ray : Newsgroups : povray.general : recursively defined objects and memory : Re: recursively defined objects and memory Server Time
29 Jul 2024 10:25:39 EDT (-0400)
  Re: recursively defined objects and memory  
From: Anthony D  Baye
Date: 19 Aug 2013 14:55:01
Message: <web.521269c9e896405b328783aa0@news.povray.org>
Ger <ger### [at] NoSpamthankyou> wrote:
> On 08/19/2013 10:51 AM, Warp wrote:
> > Ger <ger### [at] nospamthankyou> wrote:
> >>>>     #declare PlaneAngleX = rand(RandAngle) * 360;
> >>>>     #declare PlaneAngleY = rand(RandAngle) * 360;
> >>>>     #declare PlaneAngleZ = rand(RandAngle) * 360;
> >>>
> >>> On a separate note, are you sure that method of choosing the plane
> >>> orientation gives a uniform random distribution...?
> >
> >> No, it does not, but doing it this way gives a better result than using
> >> a single rand() for the plane orientation.
> >
> > Better in what way?
> >
> More uniform, but in all honesty, that was not the first thing I was
> paying attention to. I'll run a single vs triple rand() test case later.
>
> --
> Cheers
> Ger

My method was to choose random Phi and Theta for spherical coordinates:

#for(I, 0, 30, 1)
#local Phi = Rand_Gauss(0.0, 0.33, RdmA)*180;
#local Theta = Rand_Gauss(0.0, 0.33, RdmB)*180;
intersection {
    sphere { 0.0, 3.0 }
    plane { <sin(Phi)*cos(Theta), sin(Phi)*sin(Theta), cos(Phi)>, 0 }
        pigment { White }
        translate <-15*6 + I*6, 0, 0>
    }
#end

if you want to avoid the flaw with hemispherical slices, then you also need a
random offset:

#for(I, 0, 30, 1)
#local Phi = Rand_Gauss(0.0, 0.33, RdmA)*180;
#local Theta = Rand_Gauss(0.0, 0.33, RdmB)*180;
#local Offset = Rand_Gauss(0.0, 0.33, RdmC)*3.0;
intersection {
    sphere { 0.0, 3.0 }
    plane { <sin(Phi)*cos(Theta), sin(Phi)*sin(Theta), cos(Phi)>, Offset }
        pigment { White }
        translate <-15*6 + I*6, 0, 0>
    }
#end

and in a test scene:

#include "kolors.inc"
#include "rand.inc"

light_source {
    0*x
    color rgb 1
    translate <15, 30, -60>
}
camera {
    perspective
    location <3, 5, -60>
    up y
    right x*(image_width/image_height)
    look_at 0
}


#for(I, 0, 30, 1)
#local Phi = Rand_Gauss(0.0, 0.33, RdmA)*180;
#local Theta = Rand_Gauss(0.0, 0.33, RdmB)*180;
#local Offset = Rand_Gauss(0.0, 0.33, RdmC)*3.0;
intersection {
    sphere { 0.0, 3.0 }
    plane { <sin(Phi)*cos(Theta), sin(Phi)*sin(Theta), cos(Phi)>, Offset }
        pigment { White }
        translate <-15*6 + I*6, 0, 0>
    }
#end

Now, obviously, the CSG method isn't going to work because of memory
constraints. but you can easily use this method to generate your plane, and then
take the dot-product like so:

#declare Normal = <sin(Phi)*cos(Theta), sin(Phi)*sin(Theta), cos(Phi)>
#declare Mag = Rand_Gauss(0.0, 0.33, RdmC)*BaseRad;

vdot(Mag*Normal, CurrVertex - Mag*Normal)

At least, I think that should work...

Then scale the vertex coordinates based on whether the dot product is positive
or negative.

Regards,
A.D.B.


Post a reply to this message

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