0
$\begingroup$

I have two problems I'm hoping to solve with one equation for a game. This game uses a square for its key (rotates) but I'd prefer to treat it as a rectangle instead. I want to find the coordinates so I can find the angle of rotation of the box (programatically) from its perfect horizontal (y1 = y2) alignment.

I have the image below where I'm given X1, Y1, X2, Y2 and the length of a single OR both sides.

I'm trying to find (X2, Y1) and (X1, Y2) as shown below:

enter image description here What I've tried? I tried to use the Pythagorean theorem but I don't have the angle.. I thought about using the distance formula to find the length of the diagonals and calculate the other coords using that but its a rectangle so that doesn't help much.

Any ideas how I can approach it?

$\endgroup$
  • 1
    $\begingroup$ You know a diagonal. A third vertex will lie on two circles: one centred on the midpoint of the diagonal with radius equal to half the diagonal; the other centred on one of the two vertices with radius equal to the known rectangle edge. There will probably be two solutions for the third vertex, based on reflection in the diagonal. The fourth vertex is then easy to find; for example the midpoint of the original diagonal is also the midpoint of the other diagonal. $\endgroup$ – Henry Dec 16 '14 at 0:04
1
$\begingroup$

If you are only given one set of sides and the two points, and don't want to say it is square (which would give you the other set of sides), you don't have enough information to solve the problem. The rectangle could be as you have drawn the left picture, or $L1,L2$ (which are equal) could be shorter and the rectangle more tilted.

If you are given both sides as on the right, you have enough information. Do you need the coordinates of the other corners (which are not the $(X1,Y2)$ you label) or is that just a means to get the angle of the bottom side? You can evaluate the angle of he diagonal $(X1,Y1)$ to $(X2,Y2)$ as Atan2(Y1-Y2,X1-X2). Note that this uses the usual math convention of $+x$ to the right, $+y$ up-you may need to reorient it for your coordinates. The angle from the diagonal to the lower side is $\arctan(\frac {70}{60})$ and the angle of the lower side is the sum of these.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.