Archived

This topic is now archived and is closed to further replies.

Random Vectors In a nonuniform bounding box

This topic is 5842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Well I''m making a particle engine and I have it all down on paper and yesterday I went ahead and started coding and of course I ran in to a problem that I had not thought of while designing the system. In anycase I need a way to make random vectors that stay inside a bounding box that doesn''t necessarily have the same sized sides on each side. Like a a pyrimid with the top cut off. Does any know??

Share on other sites
One way to do it would be to generate normals to the faces of the bounding box, and using those, make sure the point is behind all of the faces.

--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share on other sites
hmmm...come up with a rectangular bounding box that actually contains this irregular frustum shape. Generate a point within this bounding box (three rand() calls). and then see if it is inside the frustum shape. (by testing the point against frustum planes, as the previous poster said). That should be faster than choosing any point and testing it against frustum.

Share on other sites
I found some source on the net but the author describes it in VERY mathmatical notation. Can some one explain in English what this code does

  Point3 Pick(Point3 v0, Point3 v1, Point3 v2, Point3 v3) {double s = drand();double t = drand();double u = drand();if(s+t>1.0) { // cut''n fold the cube into a prisms = 1.0 - s;t = 1.0 - t;}if(t+u>1.0) { // cut''n fold the prism into a tetrahedrondouble tmp = u;u = 1.0 - s - t;t = 1.0 - tmp;} else if(s+t+u>1.0) {double tmp = u;u = s + t + u - 1.0;s = 1 - t - tmp;}a=1-s-t-u; // a,s,t,u are the barycentric coordinates of the random point.return v0*a + v1*s + v2*t + v3*u;}

Share on other sites
Well I don''t really want to do a bounding frustum check because that could slow things a lot. Say I want to make 1000 particles a frame. Well, if 500 are outside the frustum then they have to be calculated again, and if 250 of those are outside then another expensive calculation... you get the idea.. isn''t there a algo that does this, some has to have wanted to do this before

Share on other sites
It depends on the kind of distribution you want.

To generate a truncated pyramid,

v = vector(rnd() * boxwidth, rnd() * boxheight, rnd() * boxdepth);
v.x *= (v.y / (boxheight - k));
v.z *= (v.y / (boxheight - k));

I think that would work... k is the height were the pyramid is truncated. If k = 0, you get a regular pyramid, non-troncated.

The idea is to transform the box, such that it is scaled proportionally to y.

HTH,

Cédric

Share on other sites
just because someone wanted something dont mean its possible to create a nice simple fast way of doing it. this is very true in this case. the more irregular the shape, the more difficult it becmes to describe the shape with a "simple" math formula. it may even become impossible to do with a single formula depending on the shape (ie particles within the shape of a letter.

the truncated pyramid may be better represented by a cone since it reduces to simply picking a start angle and delta angle (ie look into polar coordinates). ie only allow a portion of a sphere to be valid. granted use of sin/cos and other such trig will be needed, amd it wont be the fastest beast but at least you have a somewhat even distrobution and wont have crazy checks which reject particle positions and require getting a new position.

also doing any sort of scaling along an axis is dangerous because the box must be axis aligned thus require you to then rotate the particles afterward. not a problem, but something you should be aware of.

[edited by - a person on August 17, 2002 4:36:19 AM]

Share on other sites
Aha, a use for all the maths I did all these years!
First some basics of describing lines, planes and volumes.

A line: R = P + tD (R is position, P a point in space, D direction of line and t a scalar for how far along the line you are)

Plane: R = P + t1*D1 + t2*D2
D1 and D2 are any directions as long as they''ye not the same direction. They do NOT need to be at 90 degrees.

Volume: R= P +t1*D1 + t2*D2 + t3*D3
similar again.

So you start with a point and work out which way the diections go - this builds a volume. the t variables describe how big it is. If you make the D vectors the actual lengths used then all the t values are between 0 and 1. Then simply generate 3 random numbers between 0 and 1 and use these for t values. All points are guaranteed to be inside the box, all you do is a few multiplies.

Hope this helps. It works but my explanation may be poor!

NEW (13th August): A new screenshot is up, plus diaries for week #3

John 3:16

Share on other sites
d000hg: Interesting idea, but as far as I can tell, your equations will make a parallepiped. You could play with the coefficients, imposing restrictions like t1 + t2 + t3 < 1. I don''t know what the effect of such restriction will be, but it may be possible...

Cédric

Share on other sites
a bounding box should be just that: a box, nothing more. if you don''t want a box here, don''t call it bb.

---
shurcool
wwdev

1. 1
2. 2
3. 3
frob
12
4. 4
5. 5

• 13
• 14
• 65
• 14
• 15
• Forum Statistics

• Total Topics
632130
• Total Posts
3004286

×