find a rectangle limited to 4 lines

98 Views Asked by At

I want to find center of rectangle given w = width and h = height. The rectangle is limited to 4 lines:

enter image description here

as you see, all of lines cross trough (0, 0, 0). I know unit vector of each lines (a, b, c, and d). So each point on each line can be shown as:

enter image description here

where a(i), b(i), c(i), and d(i) are unit vectors of L1, L2, L3, and L4, respectively.

My questions are:

1- How can I calculate point C (center of rectangle)?
2- How can I calculate points P1, P2, P3, and P4?
3- Are the points (center and other) unique?

Any pseudo code or real code in Matlab, C++, C, or Python will be appreciated.

1

There are 1 best solutions below

2
On

Since vectors $a,b,c,d$ are known, then to specify the rectangle you have four unknowns which are $t_1, t_2 , t_3, t_4 $. We can assume that $t_1 = 1$ and this will generate all the rectangles parallel to it in space. Now, $t_2, t_3, t_4$ need to satisfy the following orthogonality conditons:

$ P_1 P_2 \perp P_1 P_4 $

$ P_2 P_1 \perp P_2 P_3 $

$ P_3 P_2 \perp P_3 P_4 $

The above equations translate to

$ (\mathbf{b} t_2 - \mathbf{a} ) \cdot ( \mathbf{d} t_4 - \mathbf{a} ) = 0 $

$ (\mathbf{b} t_2 - \mathbf{a} ) \cdot ( \mathbf{c} t_3 - \mathbf{b} t_2 ) = 0 $

$ ( \mathbf{c} t_3 - \mathbf{b} t_2 ) \cdot ( \mathbf{d} t_4 - \mathbf{c} t_3 ) = 0 $

These nonlinear equations can be solved numerically.