How To Generate Random Points on the Positive Side of a Plane in 3-D

2.5k Views Asked by At

Edit: The question can also be interpreted as:

How to generate random coplanar points in a cube?

Here is what I am struggling with: I have a cube, whose origin is $(0,0,0)$ and one edge length is $e$.

I am generating random planes with respect to the equation $z = ax + by + c$ In order to generate planes, I randomly generate $a$, $b$ and $c$ first. After that, I put random points on the planes I have generated.

However, I need my points to be in the cube. But when I generate my planes randomly, most of the times, $z$ coordinate is huge.

For instance: If my cube is $(100 \times 100 \times 100)$ and If I generate $x$ coordinate as 9, then only way for my point to be inside the cube is $(9,0,100)$.

I don't want this for two reasons:

The points are distributed so apart, as in example (I generated $10$ different planes and those are three random points on three of them) \begin{eqnarray} z = 11x + 9y + 5 42 \to (3.00,0.00,38.00)\\ z = 13x + 3y + 2 43 \to (2.00,8.00,52.00)\\ z = 11x + 9y + 5 44 \to (6.00,3.00,98.00) \end{eqnarray} Please suggest an algorithm for me to generate proper planes and random points on those planes.

I have tried the following but still, planes and points are not very well distributed:

I have limited $x$ and $y$ \begin{eqnarray} x < \dfrac{e - c}{a}\\\\ y < \dfrac{e - c}{b}\\ \end{eqnarray} Since $a$ and $b$ are too small, the distribution is not quite equal again. Then I tried to adjust the slopes of the planes by \begin{eqnarray} c < e\\\\ -\dfrac{c}{e} < a < \dfrac{c}{e}\\\\ -\dfrac{c}{e} < b < \dfrac{c}{e}\\ \end{eqnarray} But I get coordinates like $10048$ in a $(100\times100\times100)$ cube.

Please help me to solve this problem.

1

There are 1 best solutions below

3
On BEST ANSWER

I am describing a basic approach skipping some details. If you need additional steps, just ask...

First, I suggest you use the following method to generate a random plane which intersects the cube.

Randomly choose a point in the cube $p=(x,y,z)$. You can do this easily by generating three random numbers from 0 to 100. Then generate a random vector $v=(a,b,c)$. You can do this by choosing three random numbers from 0 to 1 and the normalize $v$ to unit length. You can define your plane as passing through $p$ and normal to $v$.

Second, define a transformation from the $x-y-z$ coordinates to a system whose origin is $p$ and whose $x-y$ plane maps to your plane and the $z$ axis maps to $v$. Then, randomly generate your random points in the $x-y$ plane as (x,y,0) using the range $\pm 100\sqrt{3}$. Then, transform them to the plane using your transformation.

Third, test each point to see if it is in the cube. You will have to throw out some points, but this method should give you a uniform distribution of points on a plane in the cube.

EDIT

Second idea: You could also generate a cloud of points and project them onto your plane.

EDIT2

Third idea: Based on the comment of @Ragnar, you could generate three random points within the cube. Let's call them $p_1$, $p_2$, $p_3$. You can then generate a basis for the plane as follows. First define the normal vector.

$$n = (p_2 - p_1)\times(p_3-p_1)$$

Then define your basis as:

$$v_1 = (p_2 - p_1)/\|p_2 - p_1\|$$

and

$$v_2 = n \times v_1$$

Then you can generate random points with two random numbers $(a,b)$ using the range $\pm\sqrt{100}$ as follows:

$$p = a v_1 + b v_2$$

Then if $p$ is in the cube, keep it, if not roll the dice again.