Draw a cascade of walls

42 Views Asked by At

In a render engine, I want to build a random cascade of walls. Each wall has a unique angle between each other, and the coordinate of the wall is its center-point. For now, each wall has the same width $w$. If it is easy to create difference size-walls, that would be great too.

Here is an illustration what I want to do:

enter image description here

After calculated the parameters, the drawing procedure would be like this:

  • Draw wall 1 with width $w$ at coordinate $P_1$ with angle $a_0$
  • Draw wall 2 with width $w$ at coordinate $P_2$ with angle $a_1$
  • Draw wall 3 with width $w$ at coordinate $P_3$ with angle $a_2$

What I have done so far

If wall X is orthogonal to the world's y-axis, and the angle between wall X and wall Y is $a$, then the vector is like this:

enter image description here

$\Delta x = \frac{w}{2} \cdot sin(a - 90^{\circ}) + \frac{w}{2}$

$\Delta y = \frac{w}{2} \cdot cos(a - 90^{\circ})$^

$\vec{v} = (\Delta x, \Delta y)$

This works so far.

Now I need to address 2 more issues:

  1. The first wall should be located arbitary in the room
  2. Find a procedure to find the center-points of all walls

Next step

Given are all angles $a_1$, $a_2$, ... Given are are coordinate $(x_0, y_0)$ and Angle $a_0$ of first wall.

Searched are coordinates of the walls $P_2$, $P_2$, ...

After finding the offset between wall X and wall Y, I probably would need to apply an rotation matrix with all previous angles. But that doesn't work.

Here is an example what I tried:

Wall 1 is still orthogonal in the room. (Has to be addressed later):

$a_0 = 0$

$P_1 = (0,0)$

Apply previously mentioned working method for vector between $P_1$ and $P_2$:

$m_x = \Delta x (P1 to P2) = \frac{w}{2} \cdot sin(a_2 - 90^{\circ}) + \frac{w}{2}$

$m_y = \Delta y (P1 to P2) = \frac{w}{2} \cdot cos(a_2 - 90^{\circ})$

$\vec{m} = (m_x, m_y)$

Finding the vector between $P_2$ and $P_3$:

$n_x = \Delta x (P2 to P3) = \frac{w}{2} \cdot sin(a_2 - 90^{\circ}) + \frac{w}{2}$

$n_y = \Delta y (P2 to P3) = \frac{w}{2} \cdot cos(a_2 - 90^{\circ})$

$\vec{n} = (n_x, n_y)$

Apply rotation matrix to that vector because wall 2 is not orthogonal in the room:

$r_x = n_x \cdot cos(a_0 + a_1) - n_y \cdot sin(a_0 + a_1)$

$r_y = n_x \cdot sin(a_0 + a_1) + n_y \cdot cos(a_0 + a_1)$

$\vec{r} = (r_x, r_y)$

The parameters for drawing wall 3 are:

  • Angle = $a_0 + a_1 + a_2$
  • Position = $P_1 + \vec{m} + \vec{r}$

However, the result is similar to that:

enter image description here

I am trying to figure out this formula since a few days, and don't find a solution. What am I doing wrong? What is the correct procedure to find $P_i$ for given $a_i$ , including the fact that wall 1 can have an arbitary position and angle in the room? A wonderful would be to allow individual $w_i$ for each wall.