2
$\begingroup$

enter image description here

I have Cartesian coordinates $A$ and $B$.

Line $AB$ is the axis (center) of the rectangle.

And I have $H$ (height).

I need Cartesian coordinates blue rectangle.

  • 0
    Could you please try to explain more clearly what information you are given, and what you need to find?2011-08-28
  • 0
    little has changed post2011-08-28
  • 0
    What sort of coordinates do you have? Cartesian coordinates? What sort of coordinates are you looking for? The Cartesian coordinates of the corners of the rectangle? Also, in the image the rectangle looks axis-parallel. Is that intentional? Or do you need the answer for a rectangle with arbitrary orientation with respect to the coordinate axes? Also, there seems to be an implication that A and B lie on the centres of the vertical sides. Is that true? If you want to make such assumptions, you should explicate them; without making them, the problem is underspecified.2011-08-28
  • 0
    Ok. Do you know if A and B cuts the side into half?2011-08-28
  • 1
    If the coordinates of A and B are $(x_A,y_A), (x_B,y_B)$ and $H$ is the width, then your figure *suggests* that the coordinates of the four vertices are $(x_A,y_A+H/2),(x_A,y_A−H/2),(x_B,y_B+H/2)$ and $(x_B,y_B−H/2)$.2011-08-28
  • 0
    Américo's coordinates correspond to the assumption I asked about in my previous comment. If those are not the assumptions you wanted to make, you'll have to specify the problem more completely. @Américo: one of the $y_B-H/2$ should have a $+$ instead.2011-08-28
  • 0
    @joriki: corrected.2011-08-28

1 Answers 1

2

To get the coordinates of the corner points, we need to displace $A$ and $B$ by $\pm h$ along the normal of the line connecting them (i.e. along a vector pointing 90° away from the line).

Let $A = (A_x, A_y)$ and $B = (B_x, B_y)$. Then the vector from $A$ to $B$ is

$$v = B-A = (v_x, v_y),$$

where

$$v_x = B_x-A_x \text{ and } v_y = B_y-A_y.$$

Rotating this vector by 90° is equivalent to swapping its coordinates and negating one of them, giving the normal vector

$$n = (v_y, -v_x) = (B_y-A_y,\ A_x-B_x).$$

However, the length of $n$ is the same as the length of $v$; we need to scale it down to $1$ before multiplying it with $\pm h$. To do this, we can divide $n$ by its length $|n| = |v| = \sqrt{v_x^2+v_y^2}$ to get the unit normal vector

$$\hat n = \frac{n}{|n|} = \left({\frac{v_y}{\scriptstyle \sqrt{v_x^2+v_y^2}},\ \frac{-v_x}{\scriptstyle \sqrt{v_x^2+v_y^2}}}\right).$$

We can then calculate the coordinates of the four corners as $A + h \hat n$, $A - h \hat n$, $B + h \hat n$ and $B - h \hat n$.