POV-Ray : Newsgroups : povray.advanced-users : Stochastics expertise needed Server Time
17 May 2024 00:20:50 EDT (-0400)
  Stochastics expertise needed (Message 7 to 16 of 26)  
<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 14:05:01
Message: <web.57c083f28629941bb488d9aa0@news.povray.org>
I see the "probability" aspect of this now...
no time to code it at the moment.

define a spline with a probability function
sparse near 0, denser near 1, maybe exponentially peaking at 1

choose rand between 0 and 1
pluck out y value from spline

then it's just a sphere in that y gradient


Post a reply to this message

From: LanuHum
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 16:20:00
Message: <web.57c0a3b08629941b7a3e03fe0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

Let me simulate it in Blender. I use a system of particles and particle_map.
We have invented a bicycle.
Blender - your problem?


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 16:40:00
Message: <web.57c0a88b8629941bb488d9aa0@news.povray.org>
"LanuHum" <Lan### [at] yandexru> wrote:
> We have invented a bicycle.

likely.  ;)

// Log spherical pattern
// Bald Eagle 2016
#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "textures.inc"
#include "rand.inc"


#declare R = 5;


camera {
 location <0, R, -15>
 look_at  <0, R, 0>
}


light_source {<20, 50, -100> White shadowless}



#declare Tiny = 0.000001;
#declare Stream = seed (123);
#declare Stream2 = seed (456);
#declare Stream3 = seed (789);

#declare Sphere_Spline =
  spline {
    linear_spline
   -0.25, <-0.25, 0.0, 0>,
    0.00, <0.00000000000000000001, 0.0, 0>,

    1.00, <1, 0, 0>
    1.1 , <1.1, 0, 0>
  } //-------------------




#declare Sphere1 =
union {
    #for (Point, 1, 1000)
        #declare Phi =  RRand(0, 2*pi, Stream);

        #declare Variable2 = RRand(1.00000001, 10, Stream2);

        #declare Theta = -pi*Sphere_Spline(1-log(Variable2))+(pi/2);

    #declare X = R * cos (Theta.x) * sin (Phi);
    #declare Z = R * cos (Theta.x) * cos (Phi);
    #declare Y = R * sin (Theta.x) + R;

    sphere {<X, Y, Z>, 0.01 pigment {Red} }
    #end
}



object {Sphere1}


Post a reply to this message

From: LanuHum
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 17:45:00
Message: <web.57c0b8258629941b7a3e03fe0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "LanuHum" <Lan### [at] yandexru> wrote:
> > We have invented a bicycle.
>
> likely.  ;)
>
Tomorrow you will be asked to another location formula. The day after tomorrow
another. In each case the formula. Tired, you want to relax.
I have shown in the screenshots universal way: image_map.
Draw Mandelbrot grayscale on any object - no problem. :)))))


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 18:40:01
Message: <web.57c0c5018629941b5e7df57c0@news.povray.org>
"LanuHum" <Lan### [at] yandexru> wrote:

> Tomorrow you will be asked to another location formula. The day after tomorrow
> another. In each case the formula. Tired, you want to relax.
> I have shown in the screenshots universal way: image_map.
> Draw Mandelbrot grayscale on any object - no problem. :)))))

Yes, my Russian friend, but we ask many things of our good friend Christoph, and
he works hard for us to deliver the goods.
I'm always glad to help a friend, and I always look forward to seeing your
interpretations and experiments, translating between Blender and POV-Ray.

I think that he wants a function, an algorithm, that can be called in the source
code of POV-Ray, in order to perform a certain task.
It needs to be a method whereby any given point can be selected at random, and
the function will evaluate a probability density on the sphere.
It seems a lot to me like a highlight model.

I had many things to do today, and did the best I could on short notice, just to
illustrate the basic idea.  With some refinements, perhaps this evolve into
what's needed.

I am not sure I understand the banding on your image map method.

I think clipka needs something that is a very dense cluster at y=1 and hardly
anything at all near y=0.  I'm not sure my model is accurate, but it was a quick
brainstorming exercise.


Post a reply to this message

From: lelama
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 19:20:00
Message: <web.57c0ce5f8629941b7a63dc9f0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Folks, I could need a bit of help with a maths problem.
>
> I need an algorithm to generate random points on the surface of a
> sphere, conforming to the following criteria:
>
> - The distribution must be radially symmetric around the Y axis.
> - The sample density should be roughly uniform, except for a pronounced
> peak centered at +Y (but not -Y!)
> - For each random point generated, the algorithm also needs to compute
> the theoretical sample density at that location.
> - The algorithm must be reasonably fast.
>
> Ideally, the algorithm should also have the following properties:
>
> - The density should fall off smoothly from the peak.
> - The algorithm should have a parameter to govern the "tightness" of the
> peak.
> - The sample density away from the peak should approach (but not reach!)
> zero.

You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
with  y in [-1,1] and r=sqrt(1-y^2).

Then you choose t uniformly, and for y, you choose your distribution as you want
(this is you free parameter). Then the density around a point x,y,z depends only
on y.

If you want an explicit density with associated random points on the sphere in
povray, you may choose a density d(y) pieciwise affine : constant equal to c1>0
on an interval [-1,p] and growing from c1 to c2 when y is  in [p,1].  Then you
choose randomly and uniformly  (y,v) in [-1,1]x[0,c2]. If v>d(y), throw your
point away. If v<=d(y), choose t randomly and put the point P(t,y) on the
sphere.

This shoud satisfy all your needs if I'm not wrong.


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 22:21:19
Message: <57c0f91f$1@news.povray.org>
Am 27.08.2016 um 00:38 schrieb Bald Eagle:

> I think that he wants a function, an algorithm, that can be called in the source
> code of POV-Ray, in order to perform a certain task.
> It needs to be a method whereby any given point can be selected at random, and
> the function will evaluate a probability density on the sphere.
> It seems a lot to me like a highlight model.

You've hit the nail right on the head :)

This is intended to become part of a stochastic sampling mechanism,
intended to compute both diffuse interreflections (as currently computed
by radiosity) /and/ blurred reflections (as currently computed by a
dedicated algorithm in UberPOV) in one go.

A simple procedure to achieve that would be as follows:


(1) Pick a random direction, using a uniform distribution.

(2) Trace a ray in that direction to compute how much light comes from
other objects in that driection.

(3) Pretending that we have a light source in that direction, use the
established algorithms for diffuse, specular and phong to compute the
effective brightness the surface would exhibit if it was illuminated
only from this direction.

(4) Repeat, summing up the effective brightness for illumination from a
handful of directions.

(5) Divide the computed sum by the number of rays shot.


However, while this approach is ok for materials where the diffuse
contribution dominates, it's far from ideal when highlights are the
dominant component, since in that case we waste a lot of energy on
directions that contribute virtually nothing.

What we need to do is change the probability distribution of the random
directions. Ideally, the distribution should match the combined BRDF of
the diffuse, specular and phong components, but that might be difficult
to achieve, and besides all we need is a somewhat /similar/
distribution. So that's what I'm searching for.

Obviously however, if we just plug in a different random distribution
into the above mechanism, the regions with high distribution will tend
to be overrepresented in the the result; the solution to that is to
weigh the individual directions' contributions by the inverse of the
probability for picking that particular direction. But that's where I
start to struggle.


To keep things simple, I've decided /not/ to aim for a distribution that
matches a certain combined BRDF, but rather use two different
distributions: One custom-tailored for highlights, and one
custom-tailored for diffuse (cos-weighted should be ideal there). I
would then choose between the two distributions alternatingly or at random.


Post a reply to this message

From: Bald Eagle
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 22:40:00
Message: <web.57c0fd6f8629941b5e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> You've hit the nail right on the head :)

Here's my crappy code, but best looking distribution for the day (based on my
abyssmal histograph).

I think it's a matter of defining the function / spline / clustering of the
random vector - everything else looks fairly straightforward.

I especially wanted to avoid the wasteful hit-or-miss style algorithm - so I
made sure every random number returns a "valid" result.

I'd say this looks like a statistics specialty, or given the spherical-based
distribution - a quantum mechanics-type function.

I hope this acts as a first pointer in the right direction.
{I started to struggle right at Theta and Phi.   ;)  :D   }

##############################################################

// spline / sqrt spherical pattern
// Bald Eagle 2016
#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "textures.inc"
#include "rand.inc"


#declare R = 5;


camera {
 location <0, R, -20>
 look_at  <0, R, 0>
 right     x*image_width/image_height
 up y
}


light_source {<20, 50, -100> White shadowless}



#declare Tiny = 0.000001;
#declare Stream = seed (123);
#declare Stream2 = seed (456789);
#declare Stream3 = seed (789);

#declare Sphere_Spline =
  spline {
    linear_spline
   //-0.25, <-0.25, 0.0, 0>,
    0.00, <0.00000000000000000001, 0.0, 0>,
 0.1 <0.9, 0, 0>,
    1.00, <1, 0, 0>
   // 1.1 , <1.1, 0, 0>
  } //-------------------


#declare Samples = 10000;
#declare Histograph = array [60]
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0};

#declare Sphere1 =
union {
    #for (Point, 1, Samples)
        #declare Phi =  RRand(0, 2*pi, Stream);

        #declare Variable2 = RRand(0, 1, Stream2);
        //#declare Variable2 = RRand(1.00000001, 10, Stream2);

  //#declare Theta = (pi*Sphere_Spline(Variable2).x)-(pi/2);
  #declare Theta = (pi*sqrt(Sphere_Spline(Variable2).x))-(pi/2);
        //#declare Theta = (-pi*(1-Sphere_Spline(log(Variable2)).x))+(pi/2);
        //#declare Theta = (-pi*abs(Sphere_Spline(pow(1-log(Variable2),
3)).x))+(pi/2);

    #declare X = R * cos (Theta.x) * sin (Phi);
    #declare Z = R * cos (Theta.x) * cos (Phi);
    #declare Y = R * sin (Theta.x) + R;

 #declare Histograph [int((Y/(2*R))*59)] = Histograph [int((Y/(2*R))*59)]+1;

    sphere {<X, Y, Z>, 0.01 pigment {Red} }
    #end
}



object {Sphere1}

cylinder {<0, 0, 0>, <6, 0, 0>, 0.05 pigment {Blue} }
cylinder {<0, 0, 0>, <0, R, 0>, 0.05 pigment {Blue} }
#for (GraphX, 0, 60-1)
 sphere {<GraphX/10, Histograph[GraphX]/10, 0>, 0.1 pigment {Green}}// translate
-y*R}
#end


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 26 Aug 2016 23:49:51
Message: <57c10ddf$1@news.povray.org>
Am 27.08.2016 um 01:18 schrieb lelama:

> You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
> with  y in [-1,1] and r=sqrt(1-y^2).
> 
> Then you choose t uniformly, and for y, you choose your distribution as you want
> (this is you free parameter). Then the density around a point x,y,z depends only
> on y.
...
> This shoud satisfy all your needs if I'm not wrong.

Gee, I you have indeed nailed it!


Post a reply to this message

From: clipka
Subject: Re: Stochastics expertise needed
Date: 27 Aug 2016 02:24:09
Message: <57c13209$1@news.povray.org>
Am 27.08.2016 um 05:49 schrieb clipka:
> Am 27.08.2016 um 01:18 schrieb lelama:
> 
>> You parametrize your sphere by t,y using the formula  x= r cos t, y,z= r sin t
>> with  y in [-1,1] and r=sqrt(1-y^2).
>>
>> Then you choose t uniformly, and for y, you choose your distribution as you want
>> (this is you free parameter). Then the density around a point x,y,z depends only
>> on y.
> ....
>> This shoud satisfy all your needs if I'm not wrong.
> 
> Gee, I you have indeed nailed it!

Hm... this still leaves me with a quest for an easy-to-generate random
distribution in the range [0..1) with a nicely configurable peak at 0,
and an easy-to-compute probability density function.

I guess I want the derivative of the probability density function to be
zero at the peak, and ideally also at 1.


Post a reply to this message

<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>

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