Finding Coordinate along Ellipse Perimeter with Arbitrary Origin Coordinates

1.2k Views Asked by At

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!

1

There are 1 best solutions below

5
On BEST ANSWER

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.