1

This is heavily related to: This Question

I know that question should have handed me the answer, but I can't quite wrap my head around what I need to do to get coordinates with an arbitrary origin.

This image shows what I have, and what I need

enter image description here

I have the coordinates $(x,y)$, as well as the width $(x)$, and the height $(y)$.

I need two things:

  1. Formula that gives $(x_1,y_1)$ when given $\{ x, y, w, h \}$
  2. Formula that gives $\{ w, h \}$ when given $\{ x, y, x_1, y_1 \}$

Note: $(x_2, y_2)$ is just $(x + w, y + h)$

Note $2$: Sorry about the bad notation. My focus is computer science, and I am not as strong in Math.

Thanks!

kirypto
  • 13
  • To save yourself some confusion, it might be better to use something like $(x_0,y_0)$ or $(l,t)$ for the upper-left corner. – amd May 10 '16 at 18:23

1 Answers1

0

In the interest of avoiding confusion, I’m going to use $(l,t)$ instead of $(x,y)$ for the upper-left corner of the bounding box. The question you reference gives you the equation of an ellipse centered on the origin. If its center is elsewhere, but it’s still aligned with the coordinate axes, then getting its equation is a simple matter of translating the coordinate system: subtract the coordinates of the ellipse center from $x$ and $y$ in the equation. That is, the equation will be of the form $${(x-x_c)^2\over a^2}+{(y-y_c)^2\over b^2}=1.\tag{1}$$ From the previous question, you know that $a=w/2$ and $b=h/2$, so you just have to find the center coordinates. Assuming a right-handed coordinate system ($y$ increases up the page), it’s easy to see that $$x_c = l+\frac w2 \\ y_c = t-\frac h2.$$ Plug these values into equation $(1)$ and you’ve got your first formula.

For the second formula you seek, you’re out of luck unless you’ve got more information about the ellipse. There are many ellipses that pass through a given point and have another given point as a corner of their bounding box. The illustration below shows an example with just two of the possible ellipses for the given points:

enter image description here

Update: If you’re interested in finding the point on the diagonal, as in your diagram, that’s fairly straightforward and doesn’t require direct use of the ellipse equation.

Consider first the unit circle centered on the origin. The half-diagonal length of its bounding box is $\sqrt2$. Denoting the upper-left corner $(l,t)$ of the bounding box as $P_0$, we have for the ratio of the segment lengths along the diagonal:$$\alpha={|P_2-P_0|\over|P_1-P_0|}={2\sqrt2\over\sqrt2+1}=2(2-\sqrt2).\tag{2}$$ Any ellipse that’s aligned with the coordinate axes can be obtained from the unit circle by scaling and translating. Translation doesn’t affect distances, while scaling preserves ratios of lengths along a line, so $(2)$ holds for any such ellipse. It’s a simple matter to derive the two formulas you’re interested in from this equation. Remember that the $x$- and $y$-components of these segments will be in the same proportion.

amd
  • 53,693
  • What you have said about the first part makes perfect sense, thank you.

    I am still wondering about the second part. I thought that the two formulas I was inquiring about would be a kind of opposite of each other. In the first I need to find the coordinates that match that spot on the ellipse. In the second I want to find what the width and height of the ellipse would have to be so that the given coordinates are once again that spot on the ellipse.

    So when you say that you'd need more information, what information would you need?

    – kirypto May 10 '16 at 19:52
  • Oh! I think I understand! There are two ellipsis that match! I understand the image now. So, a clarification, the coordinate system that I am using has the origin at the top-left, not bottom-left. I think that fixes the problem of having two ellipsis that match. – kirypto May 10 '16 at 19:56
  • Wait, my previous comment doesn't help at all. Ignore it please. – kirypto May 10 '16 at 20:05
  • A bounding box completely determines the ellipse, after which you can find any point on the curve. Unfortunately, one point on the ellipse and one corner of the bounding box aren’t enough to determine the ellipse uniquely. You need something else to nail it down. For example, if the point that you have actually is on a diagonal of the bounding box as in your diagram, that gives you the shape of the ellipse and a bit of algebra will get you the one through the given point. – amd May 10 '16 at 20:49
  • @kirypto Added a short discussion of the special case of the point on the diagonal in case that’s what you’re interested in specifically. – amd May 11 '16 at 05:20