How to calculate missing corners of rectangle based on the length to width ratio?

615 Views Asked by At

Explanatory draw

The black 2 points (geographical coordinates) are the two points we know.​ The first coordinate is latitude, the second is longitude.

P1 = (51.071833, 6.237205)
P2 = (51.071836, 6.237195)

I can build a black diagonal of the rectangle.​ Any symetric 2 other points of the circle would​ build rectangle to this diagonal (i.e.​ the red box).​

In my script I did exactly the red rectangle.​ I went down on the yaxis from the left​ upper corner to the lower edge, and to​ the right from the upper left corner to the​ right edge. Then, P3 and P4 have a coordinates:

P3 = (51.071833, 6.237195)
P4 = (51.071836, 6.237205)

Then (red rectangle) is exactly the north/south orientated rectange to the diagonal we have.

But that is not rectangle that I looking for. I looking for exactly pink rectangle.

From the project, the image that I am trying to reproduce (pink correct rectangle), I know that the rectangle has to be 94*8mm wide and 8mm high. So the ratio between length and width is 1/94 (the ratio is predefined, it does not result from any of my calculations or drawing).

With this information, I should be able to calculate the exact position (pink rectangle) of the two other vertices (P3' and P4'), but I don't know how to do it.

I expect that the pink rectangle should not be oriented exactly the north/south orientated to the diagonal we have.

Do you have any idea how to calculate the two other vertices of the pink rectangle P3' and P4' (geographic coordinates), taking into account the predefined ratio between length and width?

Thanks

2

There are 2 best solutions below

0
On

If a rectangle's diagonal makes angle $\theta$ with its base, then its height/width ratio is $\tan\theta$ and the angle between the two diagonals is $2\theta$. So to get your other diagonal, rotate your known diagonal by $2\tan^{-1}(1/94)$ radians in either direction around the midpoint. (Using $94$ instead of $1/94$ works too but gives you an angle close to $\pi$ instead of close to $0$.)

0
On

Suppose you have the coordinates of two points, $P_1$ and $P_2,$ and you want them to be diagonally opposite vertices of a rectangle one of whose sides is $k$ times as long as the adjacent side.

The segment $P_1P_2$ is therefore one of the diagonals of the desired rectangle.

For the moment, let's consider just one other vertex of the rectangle; call that vertex $P_3'.$ The angle between the sides at $P_3'$ must be a right angle, so $\triangle P_1 P_3' P_2$ is a right triangle.

Suppose the side $P_2P_3'$ is $k$ times as long as the side $P_1P_3'.$ That is, if the lengths of the sides of the rectangle are $P_1P_3' = a$ and $P_2P_3' = b,$ then $b = ka.$

Drop a perpendicular of length $h$ from $P_3'$ to the segment $P_1P_2,$ dividing that segment into segments of length $m$ and $n$ as shown in the figure below. (Note that in the figure I chose a small value of $k$ so that it would be easier to see the various points and the labels on the distances between them, but the calculations we will do will work for any positive value of $k.$)

enter image description here

Now right triangle $\triangle P_1 P_3' P_2$ and right triangle $\triangle P_1 Q P_3'$ share an angle at $P_1$ while right triangle $\triangle P_1 P_3' P_2$ and right triangle $\triangle P_2 Q P_3'$ share an angle at $P_2,$ so $\triangle P_1 P_3' P_2 \sim \triangle P_1 Q P_3'$ and $\triangle P_1 P_3' P_2 \sim \triangle P_2 Q P_3'.$ That is, $h = km$ and $n = kh,$ so $n = k^2 m.$

The first length we can calculate explicitly is the length of the diagonal $P_1P_2,$ since we now the coordinates of both endpoints. Let's call this length $d.$ Then $$d = m + n = m + k^2m = (1+k^2)m.$$

So we find that $$ m = \frac{d}{1+k^2} \quad \text{and} \quad h = km = \frac{kd}{1+k^2}. $$

Write $v = P_2 - P_1$ to represent the vector from $P_1$ to $P_2$; you can think of this notation as representing a pair of numbers, the difference in the first coordinates of $P_1$ and $P_2$ and then the difference in the second coordinates. For example, given $P_1 = (51.071833, 6.237205)$ and $P_2 = (51.071836, 6.237195),$ we find that $v = P_2 - P_1 = (0.000003, -0.00001).$ The distance between these two points is $d.$ To get from $P_1$ to $Q$ we want to go exactly $\frac{1}{1+k^2}$ of that distance from $P_1$ toward $P_2,$ so we take just $\frac{1}{1+k^2}$ of each of the coordinates of $v = P_2 - P_1$ and add those amounts to the corresponding coordinates of $P_1$:

$$ Q = P_1 + \frac{1}{1+k^2} v. $$

Now let $v_\perp$ be the vector $v$ rotated $90$ degrees. We do this by swapping the two coordinates of the vector and then flipping the sign of one coordinate. For example, if $v = (0.000003, -0.00001)$ then we could say $v_\perp = (0.00001, 0.000003).$ (The other possibility is $(-0.00001, -0.000003),$ representing a rotation in the other direction.)

Now we are ready to find the coordinates of $P_3'$ by working our way from $Q$ traveling perpendicular to the line $P_1P_2.$ The length of $v_\perp$ is the same as the length of $v$ when we construct the vectors in the way shown above, but we need the distance from $Q$ to $P_3'$ to be $k$ times the distance from $P_1$ to $Q,$ so we want

$$ P_3' = Q + \frac{k}{1+k^2} v_\perp. $$

To summarize how we get to $P_3'$ given $P_1$ and $P_2,$

$$ P_3' = P_1 + \frac{1}{1+k^2} v + \frac{k}{1+k^2} v_\perp. $$

Finding the coordinates of $P_4'$ is a symmetric operation working from $P_2$ instead of $P_1.$ Just imagine the triangle in the figure above rotated $180$ degrees.

Note that if you rotate $v$ in the other direction to get $v_\perp$ then the end result is that $P_3'$ is on the other side of the line $P_1P_2.$ There are two rectangles with diagonally opposite vertices $P_1$ and $P_2$ and the desired ratio of side lengths, and the choice of direction of rotation of $v$ determines which of the two rectangles you get.


A few notes:

In your particular case, if you only use coordinates to six places of precision past the decimal point, and if you set $k = 94,$ the point $P_3'$ will be so close to $P_1$ that the coordinates of both points will come out the same after you round to six places. That is, given out close your diagonal points $P_1$ and $P_2$ are, you just do not have enough precision in your numbers to accurately represent a rectangle with sides in the ratio $94$ to $1.$ If you really want to create such a rectangle and it is important for the drawing to be even the least bit accurate and representative, you need to use numbers with a lot more digits.

As it is, with input numbers rounded to just six places after the decimal point, the possible distance that $P_1$ may have moved due to rounding its coordinates to this precision is much larger than the distance between $P_1$ and $P_3'.$ If you are worried about accurately placing $P_3',$ perhaps you should also worry about accurately placing $P_1.$

The words "latitude" and "longitude" usually refer to coordinates on a curved surface such as a sphere, not coordinates in a plane. You also mentioned the $y$ axis, which is part of a way people typically define coordinates on a plane. Using $x$ and $y$ coordinates in a plane is much more universally recognized than using latitude and longitude.