# lil math help needed

Hi.

I was wondering how i can generate a random point inside a cube (or any polyhedron in general.)

any help is appreciated.

Satish.

Well… a cube would be really easy if all the edges were parallel to axes.

For instance, a cube with vertices at (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0), and (1,1,1). To get a random point inside that, just get a random number between 0 and 1 for each of the three axes.

Beyond cubes and rectangles like the one above, it’d get really tricky, and I’d have to do some studying to figure that one out, hehe.

One thought though… if you can find an algorithm to determine if a point is in a polyhedron, it would be fairly easy. Create a rectangle large enough to hold your polyhedron, then start finding random points within that rectangle. Use your found algorithm to determine whether or not the point is in the polyhedron, if it is you’re done, if not, do it again. Of course, that would mean you found such an algorithm, and if you found that, you might be able to find a different one that does what you want more efficiently.

Imp

gee thanx buddy.

a cube will work for now.

also, I just got hold of something called Barycentric coordinates.
what it says is

is P0, P1, P2 are 3 points(rather position vectors)

and a, b, c are real numbers
such that a+b+c = 1.0;

then a point P = aP0 + bP1+c*P2 is inside the polygon(P0, P1,P2)

thanx again.

Satish.