Jump to content

Recommended Posts

hi

I am thinking about some stuff for Houdini

can someone better equiped than me point me where to read more

about randomness and explain a little about noise and random functions we use inside houdini

I am just wondering how to get the biggest ammount of changes and as less as possible repetition

I hope this sounds reasonable :wacko:

thanks

z

Share this post


Link to post
Share on other sites
explain a little about noise and random functions we use inside houdini

Hey Zoki,

Think of random (e.g: the rand() function in hscript, or nrandom() in VEX) as a specific kind of noise: the kind that can generate all possible outcomes with equal probability on each sampling -- it doesn't matter if the samples are "close together", or "far appart" (in whatever context that makes sense), or related in some other way that you consider meaningful: that will have no influence on the outcome. If we were talking about the audible/visible spectrum , then this would be "white noise": all frequencies with an equal chance of being present at any given position/time. If we were talking about a grey scale image, then the value of each pixel would be allowed to become any one of the values in the range black->white with equal probability -- and even if you zoomed into it forever, you'd still see the same behaviour.

The sample position for these functions is called the "seed", and if the seeds of two calls are different (even by "a little bit") then the results could be wildly different form each other. (however, for practical reasons, if the seeds are identical, then so will the result -- VEX's nrandom() being an exception to this rule).

The noise() functions, on the other hand, have a sense of "scale" to them, because unlike random(), they have a "frequency" (an therefore a scale, and dimensionality). Suddenly, the terms "close together" and "far appart" have meaning, because there is a frequencey to relate them to (or measure against). This type of randomness is designed in such a way that samples that are close together (relative to the frequency) will have similar values, whereas samples that are far appart won't, necessarily (i.e: the farther appart they are, the less the probability that they will have the same value, and viseversa). The hscript noise functions (noise(), snoise(), etc) and their VEX equivalents all share this characteristic. Their frequency is generally fixed at 1, and so you control how "smooth" or "noisy" your results are by how close together or far appart you take your samples, respectively. Given this, then, you can think of random() as noise() with an infinite frequency.

Hope that makes some sense.

Share this post


Link to post
Share on other sites

Zoki,

this might be interesting for you:

<http://www.renderman.org/RMR/Books/arman/shaders/noises.h>

<http://www.random.org/>

On a cocktail party I met once a physicist who explained me the nature of random number algorithms:

It somehow got something to do with the fractions of very big and very small numbers.

He wrote a simple algorithm on a coaster but I lost it.

(Boring dinner party were you get algorithms by scientist instead of phone numbers of beautiful girls ...)

<http://www.fenews.com/fen24/levy.html>

Georg

Share this post


Link to post
Share on other sites

thanks georg

I like your work on the website

very interesting

z

Share this post


Link to post
Share on other sites
Think of random (e.g: the rand() function in hscript, or nrandom() in VEX) as a specific kind of noise: the kind that can generate all possible outcomes

I don't think that is entirely accurate. I've stumbled on something interesting with the random function. using add sop to a copy sop I make about 6000 points @ 0,0,0 (I win! :] ) , then lay down a pont sop and in the TX TY TZ fit(rand($PT+x*y),0,1,-1,1) where x and y are arbitrary numbers. It makes a cube. I would expect this to be more of a sphere. I am thinking this is happening because the rand function tends more twords .5, and rarely reaches 0 or 1. If it was indeed "equal probability" this would make a sphere, but the fact that with enough points the function makes a perfect cube I have to say this is peculiar indeed.

Does Houdini have an equivalent to the sphrand function in Maya?

ok, I see the error of my ways. To get a sphereical radom, it needs to be distance based not postition based.. My bad...

Thanks,

3db

Edited by 3dbeing

Share this post


Link to post
Share on other sites
I don't think that is entirely accurate. I've stumbled on something interesting with the random function. using add sop to a copy sop I make about 6000 points @ 0,0,0 (I win! :] ) , then lay down a pont sop and in the TX TY TZ fit(rand($PT+x*y),0,1,-1,1) where x and y are arbitrary numbers. It makes a cube. I would expect this to be more of a sphere. I am thinking this is happening because the rand function tends more twords .5, and rarely reaches 0 or 1. If it was indeed "equal probability" this would make a sphere, but the fact that with enough points the function makes a perfect cube I have to say this is peculiar indeed.

Does Houdini have an equivalent to the sphrand function in Maya?

ok, I see the error of my ways. To get a sphereical radom, it needs to be distance based not postition based.. My bad...

Thanks,

3db

What you're probably looking for is gaussian random number...

Share this post


Link to post
Share on other sites
ok, I see the error of my ways. To get a sphereical radom, it needs to be distance based not postition based.. My bad...

Yup, randomly scaling an orthogonal set of axes (Cartesian/Euclidean space) will give you an orthogonal distribution -- i.e: a cube in 3D. Spheres are a different beast (spherical geometry is non-Euclidean: no parallel lines, etc).

You suggest using distance instead of position (which I take to mean using Spherical instead of Cartesian coordinates), but if you do this, and do it in such a way that the angular distribution is uniform, you'll still get a disproportionately large number of points near the center -- IOW, not a uniform distribution with respect to volume.

The "classical" way to distribute volume-uniform points inside a sphere is to generate the "cube distribution" as you did, and then discard all the points that are outside the inscribed sphere (the idea being that if your cube distribution is already uniform w.r.t volume, then so will any slice of it). But it also means that, in the case of the inscribed sphere, about half the point-generation effort is wasted.

I haven't searched to see if there is an algorithm that uses spherical coordinates to distribute volume-uniform points in a sphere/ellipsoid (I'd be surprised if there wasn't one somewhere). I'd imagine you'd have to start by looking at the rate of change of the volume with respect to a change in distance/radius (dV/dR)...

Let me know if you come across a "native" spherical distribution algorithm somewhere -- I'm interested! :)

Cheers.

Share this post


Link to post
Share on other sites
You suggest using distance instead of position (which I take to mean using Spherical instead of Cartesian coordinates

Actually I was thinking along the lines of creating a random normalized vector per point then moving the point along that vector a random distance between min radius to max radius, should give me even enough distribution. I havn't had a chance to get back to that yet, Ill let you know if it works...

-3db

Share this post


Link to post
Share on other sites
Actually I was thinking along the lines of creating a random normalized vector per point then moving the point along that vector a random distance between min radius to max radius, should give me even enough distribution. I havn't had a chance to get back to that yet, Ill let you know if it works...

A unit-length direction times a distance *is* a spherical coordinate. I was talking about that too (they are the same thing -- one uses vectors, the other uses angles).

As to whether you'll get a volume-uniform distribution using that method... I was just thinking out loud without testing it, so I could definitely be waaaaay off about it all.

Please let us know how it turns out. Thanks!

Share this post


Link to post
Share on other sites

Ok, so I went to wikipedia, which I should have done first as I was ignorant to the spherical coordinate system. So in response to your previous question.... yes I am going to use spherical coordinates.

$TX+normalize(vector3(fit01(rand($PT+2),-1,1),fit01(rand($PT+$NPT),-1,1),fit01(rand($PT+$NPT*2),-1,1)))[0]*fit01(rand($PT*10),.1,2)

likewize for TY and TZ, And it works quite nicely.

-3db

Share this post


Link to post
Share on other sites

What about random points on a sphere with random radii?

fn calcSpherePoint = (
 r=random spongeLike_radius_min spongeLike_radius_max
 tetha=(random 0 180)
 phi=(random 0 360)
 x=r*(sin tetha)*(cos phi)
 y=r*(sin tetha)*(sin phi)	
 z=r*cos tetha
 return ([x, y, z]
)

This chooses a random radius between min and max - that way you can make hollow spheres.

Then the function calculates a random point on the surface of this sphere.

Don't know if that satisfies statistical needs, but it looks like a sphere filled with random points.

I currently try to make a vex vop that does the same, but something goes wrong:

[edit: I didn't seed theta, phi and r ... <_< ]

flower.jpg

With this method one can fill cylinders, cones and torii, too. Well, torii I didn't implement, yet.

Georg

Edited by rdg

Share this post


Link to post
Share on other sites
likewize for TY and TZ, And it works quite nicely.

Excellent!

Ultimately, the definition of "uniform" is completely determined by the context it's being used in, so if the distribution you're getting fits your requirements, there's no need to look any further. But you got me curious, so I went and did some testing.

Here are the results I got, which I'm posting simply because I think they're interesting purely from an academic point of view, nothing more:

All tests use half-a-million points distributed inside the volume of a unit sphere. The camera is orthographic, and the extents of the frame are the extents of the sphere -- IOW, the points are meant to reach all the way to the edge of frame.

Method 1: "Cartesian"

Construct a direction vector by assigning a random [-1,1] number to each component separately, normalizing, and then scaling by a random [0,1] radius. This is the method you're using right now.

post-148-1175068704_thumb.jpg

You can clearly see that there are more points toward the center than toward the limit surface (the points are supposed to reach to the edges of frame). There is also some heavy axis-aligned clumping going on. This has to do with that business of assigning values to each component separately.

Method 2: "Uniform Solid Angle"

Construct two random angles: theta [0,PI], and phi [0,2*PI], and warp them in such a way that their distribution is uniform with respect to solid angle (or surface area in the case of the unit sphere). These two angles, together with a random radius [0,1] create a spherical coordinate which we then convert to a standard (cartesian) vector.

post-148-1175068718_thumb.jpg

Again, there is clumping toward the center, but now we've lost the axis-aligned clumping because we're building from angles instead of vector components. The overall result feels a little more uniform because the angular spread is covered more uniformly.

Method 3: "Uniform Volume"

So I thought a little bit about the relationship of the volume to the radius and as a quick first stab, came up with this:

The change in volume is only dependent on the radius r. Specifically, the volume increases at the rate of 4 PI r^2. I ended up with PDF=4 r^3, CDF=r^3, and InvCDF=zeta^(1/3). That is: instead of just assigning a random number to the radius directly, you instead assign it pow(rand(),1/3). I didn't spend a lot of time on this so I might have screwed up along the way, but, in combination with method 2 above, it does seem to improve the situation somewhat (at least visually):

post-148-1175089408_thumb.jpg

Anyhoo... at least this gives you three methods to choose from.

Here's the hip file with the three tests:

sdist2.hip

P.S: That looks cool Georg!

EDIT: *CORRECTION*: That should have been CDF=r^3 and InvCDF=zeta^(1/3). I've updated the text, hip, and last image to reflect this. ... oops <_<

Share this post


Link to post
Share on other sites

I did also some research but ended up with a more "kitchen academic" result.

I also watched the clumping on the axis - something that didn't bother me till now.

I followed your note to generate a cubic distribution and discarded all point that are not inside the sphere. This makes it hard to get a predefined number of point inside the volume.

I don't have fancy stuff like your rvSpherical-thingy so my vop sops are a little bit confusing :D

To be honest my sops are hardly more than nonperformant fakes of the groupSOP with bounding objects <_<. they generate a "crop" group to be deleted.

If you don't delete the crop group the min-parameter of radius/width/height/ ... can be used to bias the clumping zones.

Anyway this some interesting soup to explain some very molecular coherences in 3d space and the manilpulation of points.

crops.jpg

top left: hollow cube filled with random points

top right hollow cylinder (tube) filled with random points

bottom left: sphere with clumping

bottom right: cube filled with random points boolean sphere

Georg

sponge_03.hipnc

Edited by rdg

Share this post


Link to post
Share on other sites

Wow thanks for the hip Mario, but heyyyyyy... That's a unique VOP, at least it's not in my list, but I checked and there is a help file?!? :blink:

Am I missing something?

Still thanks for the explination, U ROCK! yes in this case I must have explicit control over the total number of points. Im using these points as look-ats for normal vectors on other points. And as NPT->infinity, I will need as even of distribution as possible.

but can you enlighten me on what this means

PDF=4 r^3, CDF=r^3, and InvCDF=zeta^(1/3)

I assume the first one does not refer to Adobe, and what is cdf and inverse cdf?

Thanks Again!

-3db

Edited by 3dbeing

Share this post


Link to post
Share on other sites

I lifted an expression from one of these lists a lot time ago which can be useful -so i'll just share it back:

# random gaussian distribution

float 
gaussrand( idum )
{
		idum = idum * -1;
		v1 = 2.0 * rand(idum) - 1.0;
		idum = idum + .01;
		v2 = 2.0 * rand(idum) - 1.0;
		idum = idum + .01;
		rsq = v1 * v1 + v2 * v2;
		while (rsq &gt;= 1.0 || rsq == 0.0) {
				v1 = 2.0 * rand(idum) - 1.0;
				idum = idum + .01;
				v2 = 2.0 * rand(idum) - 1.0;
				idum = idum + .01;
				rsq = v1 * v1 + v2 * v2;
		}
		fac = sqrt(-2.0 * log(rsq) / rsq);
		return v2 * fac;
}

Share this post


Link to post
Share on other sites
Wow thanks for the hip Mario, but heyyyyyy... That's a unique VOP, at least it's not in my list, but I checked and there is a help file?!? :blink:

Am I missing something?

Sorry. Forgot to mention it. Yes, that's a custom VOP (one of a few that I posted here a while back and are still available in the codex as "AXYZ Vex Bundle"), but the algorithm is very straight forward -- actually, Georg already posted it earlier in this thread. As a vex function, you could write it like this:

// Random Variate: Spherical
//----------------------------------------------------------
// Inputs:
// u0 and u1 =&gt; two random numbers in [0,1]
// r		 =&gt; radius
// Output:
// A position on the surface of the sphere centered at 
// {0,0,0) with radius 'r'
//----------------------------------------------------------
vector rvSpherical(float u0,u1,r) {
   float phi   = u0*M_PI;
   float theta = u1*M_PI*2;

   // Unit sphere with Z-orientation
   float sph = sin(phi);
   return r * set(sph*cos(theta),sph*sin(theta),cos(phi));
}

The rest of that VOP is just window dressing... pretty much. The core of it is that mapping.

but can you enlighten me on what this means

PDF=4 r^3, CDF=r^3, and InvCDF=zeta^(1/3)

I assume the first one does not refer to Adobe, and what is cdf and inverse cdf?

Those weird statistical acronyms are:

PDF = "Probability Density Function"

In this case it says that the bigger the volume, the higher the probability that there will be a point inside it. It is proportional to how volume increases w.r.t radius.

CDF = "Cumulative Distribution Function"

This is basically the integral of the PDF. It's interpreted as the probability that a random variable will take on a value less than or equal to x.

InvCDF (or "Quantile") = "Inverse Cumulative Distribution Function"

The inverse of the CDF. This is what you use to modify the output of a uniform random number generator like rand(), for example, so that it has the distribution of the PDF (instead of its natural uniform distribution).

I lifted an expression from one of these lists a lot time ago which can be useful -so i'll just share it back:

Thanks Jason.

Yes, I noticed that TheUsualAlex pointed this out too... but... uhmmmm...

OK. What am I missing here, guys?

How exactly do you see the normal distribution being used in all this?

Sorry. My brain is a little slow today and I'm just not seeing it... throw me a bone over here. :)

Cheers!

Share this post


Link to post
Share on other sites
Yes, I noticed that TheUsualAlex pointed this out too... but... uhmmmm...

OK. What am I missing here, guys?

How exactly do you see the normal distribution being used in all this?

In 2D, a gaussian distribution is kinda circular? <shrugs>

MathWorld says that an easy way to randomly pick a uniform point distribution on the surface of a hypersphere is to choose the coordinates according to a gaussian (as opposed to uniform) variate and then normalize.

http://mathworld.wolfram.com/HyperspherePointPicking.html

Share this post


Link to post
Share on other sites

Thanks Ed.

Yeah, those methods are interesting, but they all deal with distributing points on the *surface* of a sphere, not its volume. The Marsaglia one uses rejection to distribute over a 2D disk and then remaps to the sphere (I suppose the gaussian helps reduce the number of rejections, because it is, as you say, circular in 2D), and the hypersphere one is what I've been calling the "cartesian" method, except in higher dimensions (with r fixed at 1 so it's only on the surface).

I still don't see the normal distribution's connection to filling the sphere's volume...

TheUsualAlex?, Jason? ... I'm in need of enlightment.

...you got me racking my brain with these cryptic references to the mysterious use of a gaussian to fill the volume :D

Share this post


Link to post
Share on other sites

I read that page differently. I think the second paragaph refers to a completely separate method? The first method on that page talks about rejection, but note that it says that it's not generalizable to higher dimensions. The second method, which does generalize, doesn't use rejection.

Yes, neither of these methods choose points on the volume but it sounds like your method also depends on choosing a uniform distribution of points on the sphere? So if rvSpherical() was replaced with Muller 1959, then we have a way of doing it with using the gaussian distribution? (inefficiently :) ).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×