Find the coordinates of all corners of a box in 2D when knowing its length and height and the coordinates of two opposite corners

161 Views Asked by At

Update: Down voting my question helps no one if you don't explain why you are doing that. In fact you are only doing wrong and it's kind of against this community main idea.


So I have the following situation:

Problem

in which I know the coordinates of point B and D. I also know the length of BC and CD.

What would be a formula to find out the coordinates of A and C?

Here's what I tried:

The first thing I tried is finding C's coordinates based on the distance between B & C and D & C which I know.

So I know the following:

$$BC = \sqrt{(C_x - B_x) ^ 2 + (B_y - C_y) ^ 2}$$ $$DC = \sqrt{(C_x - D_x) ^2 + (C_y - D_y) ^ 2}$$

So it's basically a system of two equations with 2 unkowns. But my math skills failed me and I could never solve it :(

Tried the intersection points of the two circles in the image also. But dropped it when I figured out that the 2 circles might intersect in 2 points and I couldn't figure it out how to determine which of the 2 I need.

Later tries:

Taking the equations expressed before I've managed to express $C_x$ as follows:

$$C_x = B_x-\sqrt{2 B_y C_y-B_y^2-C_y^2+BC^2}$$

or (based on WolframAlpha):

$$C_x = \sqrt{2 B_y C_y-B_y^2-C_y^2+BC^2} + B_x$$

Now, this is probably because, as I've drawn in the image the 2 circles can intersect into two different points?

Anyway. Say I take the 1st case. Now that results in my 2nd equation being transformed to:

$$DC^2 = (B_x-\sqrt{2 B_y C_y-B_y^2-C_y^2+BC^2} - D_x) ^2 + (C_y - D_y) ^ 2$$

Now that's were I got stuck. I couldn't solve $C_y$ from there no matter what I did :( And WolframAlpha didn't helped either anymore :(

2

There are 2 best solutions below

1
On

Define the circle with centre $B$ as $c_B:\:(x-B_x)^2+(y-B_y)^2=BC^2$ and the circle with centre $D$ as $c_D:\:(x-D_x)^2+(y-D_y)^2=DC^2$. Find the intersection of $c_B$ and $c_D$ to get $C$ and the other intersection. Deduce which is $C$ and find $A$ by symmetry.

If we rearrange the equation for $c_B$, we have that $y=\sqrt{BC^2-(x-B_x)^2} +B_y$. We can rearrange the equation for $c_D$ to solve for $x$ and then find $C$. I've gone through some of the algebra for you but it's very long-winded and messy but at least it's a solution.

$y=\sqrt{BC^2-(x-B_x)^2} +B_y=\sqrt{DC^2-(x-D_x)^2} +D_y$

Move $B_y$ to the RHS to get rid of the radical on the LHS.

$\sqrt{BC^2-(x-B_x)^2}=\sqrt{DC^2-(x-D_x)^2} +D_y-B_y$

Square both sides.

$BC^2-(x-B_x)^2=DC^2-(x-D_x)^2 +2(D_y-B_y)\sqrt{DC^2-(x-D_x)^2}+(D_y-B_y)^2$

To get rid of the radical on the RHS, move everything else to the LHS.

$BC^2-(x-B_x)^2-DC^2+(x-D_x)^2 -(D_y-B_y)^2=2(D_y-B_y)\sqrt{DC^2-(x-D_x)^2}$

Set $\alpha=BC^2-DC^2-B_x^2+D_x^2-(D_y-B_y)^2$ and $\beta=4(D_y-B_y)^2(DC^2-D_x^2)$ to simplify the LHS.

$\begin{align}\text{LHS}&=BC^2-DC^2-x^2+2B_xx-B_x^2+x^2-2D_xx+D_x^2-(D_y-B_y)^2 \\ &=BC^2-DC^2+2B_xx-B_x^2-2D_xx+D_x^2-(D_y-B_y)^2 \\ &=2(B_x-D_x)x+\alpha \end{align}$

$$\left(2(B_x-D_x)x+\alpha\right)^2=(2(D_y-B_y))^2(DC^2-(x-D_x)^2)$$

$$\text{LHS}=4(B_x-D_x)^2x^2+4\alpha(B_x-D_x)x+\alpha^2$$

$$\begin{align}\text{RHS}&=4(D_y-B_y)^2(DC^2-x^2+2D_xx-D_x^2) \\ &=-4(D_y-B_y)^2x^2+8D_x(D_y-B_y)^2x+\beta \end{align}$$

Hence, we have a quadratic in $x$.

$$\left[4(B_x-D_x)^2+4(D_y-B_y)^2\right]x^2+\left[4\alpha(B_x-D_x)-8D_x(D_y-B_y)^2\right]x+\alpha^2-\beta=0$$

We solve the quadratic for $x$.

$x=\frac{-\left[4\alpha(B_x-D_x)-8D_x(D_y-B_y)^2\right]\pm\sqrt{\left[4\alpha(B_x-D_x)-8D_x(D_y-B_y)^2\right]^2-4\left[4(B_x-D_x)^2+4(D_y-B_y)^2\right](\alpha-\beta)}}{2\left[4(B_x-D_x)^2+4(D_y-B_y)^2\right]}$

$=\frac{-\alpha(B_x-D_x)+2D_x(D_y-B_y)^2\pm\sqrt{\left[\alpha(B_x-D_x)-2D_x(D_y-B_y)^2\right]^2-\left[(B_x-D_x)^2+(D_y-B_y)^2\right](\alpha-\beta)}}{2(B_x-D_x)^2+2(D_y-B_y)^2}$

Which would have a rather tedious simplification. But the point is, we've found $C_x$ and can then find $C$ and $A$ quite easily.

0
On

Since you know the lengths of all three sides of $\triangle BCD$, you can find $\angle BDC$ and $\angle CBD$, which then allows you to find $C$ and $D$ via rotations. Note that, without further conditions, there are two solutions corresponding to the two intersection points of the circles.

As you may know, counterclockwise rotation through an angle $\theta$ can be expressed as the matrix $$R_\theta=\pmatrix{\cos\theta&-\sin\theta\\\sin\theta&\cos\theta},$$ so we don’t really need to recover the angle itself. We just need its sine and cosine, which are just ratios of the segment lengths.

Let $\theta=\angle BDA=\angle DBC$. We have $$\cos\theta = {|BC|\over|BD|},\sin\theta={|CD|\over|BD|}$$ so our rotation matrix is $$R_\theta=\pmatrix{{|BC|\over|BD|}&-{|CD|\over|BD|}\\{|CD|\over|BD|}&{|BC|\over|BD|}}.$$ Let $\mathbf u=(B-D)/|BD|$, a unit vector pointing from $D$ to $B$. Then $A=D+|BD|R_\theta\mathbf u$ and $C=B-|BD|R_\theta\mathbf u$. The other solution is found by reversing the rotation, which amounts to taking the transpose of $R_\theta$. A solution in the same vein can be found by using $\angle BDC$ and applying a clockwise rotation.