How to find equidistant coordinates of an inner quadrilateral?

425 Views Asked by At

I am trying to find equidistant coordinates from following figure. How can I calculate the coordinates: (x1,y1), (x2, y2), (x3, y3) and (x4, y4)? In this figure, 1. B1 is parallel to B2 2. L1 is parallel to L2 3. T1 is parallel to T2 4. R1 is parallel to R2

For example, I am trying to find if line T2 is 5 distance away from line T1, what will be the value of (x2,y2) and (x3, y3)?

Thanks in advance.

enter image description here

2

There are 2 best solutions below

4
On BEST ANSWER

In principle, at each vertex you have to offset the extensions of the sides that meet at that vertex by a distance $\Delta$ in the appropriate direction and then find the intersection of those two lines. This is a fairly straightforward computation. Let $V_i$ be the homogeneous coordinates of a vertex, and let $V_{i-1}$ and $V_{i+1}$ be the preceding and next vertices, respectively, when traversed counterclockwise. Set $\mathbf l=V_{i-1}\times V_i$ and $\mathbf m=V_i\times V_{i+1}$. These two vectors are the homogeneous coordinate representations $[a:b:c]$ of the lines through those pairs of points. The order of the points in the cross products is chosen so that the normal vector $(a,b)$ to the line points toward the interior of the figure. Offset the two lines by subtracting $\Delta\sqrt{a^2+b^2}$ from the last component to get lines $\mathbf l'$ and $\mathbf m'$ and then compute their intersection with another cross product: $V_i'=\mathbf l'\times\mathbf m'$. Dehomogenize by dividing through by the last component of the resulting vector. (If it’s zero, the lines are parallel, which shouldn’t happen unless you run into numerical instabilities with near-parallel edges.) Of course, when offsetting all of the vertices, you’ll only need to compute each of the offset edge lines once.

If the polygon is convex, there’s another way to compute the offset vertex that may or may not be more convenient for your application. Note that the offset vertex must lie on the angle bisector of the two sides that meet at the given vertex. If the angle between those sides is $\theta$, we have $$\sin\frac\theta2 = {\Delta \over V_iV_i'}.$$ Working in inhomogeneous Cartesian coordinates now, an angle bisector is $$\mathbf u = \|V_{i+1}-V_i\|(V_{i-1}-V_i)+\|V_{i-1}-V_i\|(V_{i+1}-V_i)$$ and so $$V_i' = V_i + {\Delta \over \sin{\theta/2}} {\mathbf u \over \|\mathbf u\|}.$$ The sine of the angle between a pair of vectors can be computed using a determinant: $$\det\begin{bmatrix}\mathbf a & \mathbf b\end{bmatrix} = \|\mathbf a\|\,\|\mathbf b\| \sin\theta.$$ To get $\sin{\theta/2}$ you can therefore compute the sine of the angle between the bisector $\mathbf u$ and either of the sides, say, $\mathbf v=V_{i+1}-V_i$. Since $\mathbf u$ is a linear combination of this vector and $\mathbf w = V_{i-1}-V_i$, from the properties of determinants we have $$\det\begin{bmatrix}\mathbf v & \mathbf u\end{bmatrix} = \det\begin{bmatrix}\mathbf v & \mathbf \|\mathbf w\|\mathbf v + \|\mathbf v\|\mathbf w\end{bmatrix} = \|\mathbf v\|\det\begin{bmatrix}\mathbf v & \mathbf w\end{bmatrix},$$ so $$\sin{\frac\theta2} = {1\over\|\mathbf u\|}\det\begin{bmatrix}\mathbf v & \mathbf w\end{bmatrix}$$ and $$V_i' = V_i + \Delta{\|\mathbf w\|\mathbf v + \|\mathbf v\|\mathbf w \over \left|\det\begin{bmatrix}\mathbf v & \mathbf w\end{bmatrix}\right|}.$$ Note that since we’re taking the absolute value of the determinant and that the formula for the angle bisector is symmetric, it doesn’t matter which of the two sides are called $\mathbf v$ and $\mathbf w$. In terms of computational efficiency, both methods require two square roots, but this one has fewer other operations, so I’d use it when possible. You can encounter numerical instability when the two sides are near parallel with this method, too.

To illustrate, we compute the offset vertex $V_3'$ from your example.

Method 1: $$\mathbf l = V_4\times V_3 = (900.,0.,1.)\times(1000.,800.,1) = (-800.,100.,720000.) \\ \mathbf m = V_3\times V_2 = (1000.,800.,1)\times(100.,1800.,1.) = (-1000.,-900.,1720000.)$$ Offsetting these two lines, $$\mathbf l' = \mathbf l - (0,0,5\sqrt{(-800.)^2+(100.)^2} \approx (-800.,100.,715968.9) \\ \mathbf m' = \mathbf m - (0,0,5\sqrt{(-1000.)^2+(-900.)^2}) \approx (-1000.,-900.,1713273.)$$ and so $V_3' = \mathbf l'\times\mathbf m' \approx (815699300.,654649700.,8200000.0)$ which demohogenizes to approximately $(994.755,798.353)$.

Method 2: $$\mathbf v = V_4-V_3 = (-100.,-800.) \\ \mathbf w = V_2-V_3 = (-900.,1000.) \\ \mathbf u = \|\mathbf w\|\mathbf v + \|\mathbf v\|\mathbf w \approx (-860139.4,-270064.1) \\ \det\begin{bmatrix}\mathbf v & \mathbf w\end{bmatrix} = \begin{vmatrix}-100.&-800.\\-900.&1000.\end{vmatrix} = -820000. \\ V_3' \approx (1000.,800.)+\frac{5.}{820000.}(-860139.4,-270064.1) \approx (994.755,798.353)$$ as with Method 1.

1
On

I'm having trouble posting images, so I'm going to have to ask you to use your imagination. Let's concentrate on the corners of lines L1/L2 and B1/B2. Call the origin point O and call the intersection between L2 and B2 A. Finally drop a perpendicular from A to line B1 and call the point where it lands P

Now, call the angle between L1 and B1 $\theta$. What is its value? The sine of the angle can be determined from the cross-prodcut of L1 and B1:

$ \displaystyle \sin{\theta} =\frac{B1_x L1_y - L1_x B1_y}{|L1||B1|} $

(If you don't know about cross-products, they are useful to know about and you can find many websites about them.)

Plug in the numbers:

$ \displaystyle \sin{\theta} = \frac{900 * 1800 - 100 * 0}{\sqrt{100^2 + 1800^2} * 900} \approx 0.998$

So $\theta$ is really close to 90 degrees, more like 86.82 actually. (Your diagram is not drawn to scale, apparently.) Now, what we really want is angle $\angle POA$ I will leave it to you to demonstrate to yourself that it is one half of $\theta$. This is 43.41 degrees. Now look at triangle $\triangle AOP$. $AP$ has a length of 5 and the distance you are looking for is $AO$. $AO=AP/\sin{(43.41)}$, and that is 5/.687 = 7.28.

I'll leave it to you to apply to the other corners.