3
$\begingroup$

I'm attempting to find the bounding box for a rotated egg shape without resorting to interpolation if at all possible. In researching this I've come across this link which lists useful equations for plotting the $(x, y)$ coordinates of an egg shape as:

\begin{align*} x &= \frac{r((c-2) \cos \theta + c + 2)(\cos \theta + 1)}{4}, \\ y &= r \cdot \sin \theta. \end{align*}

But if I were to normalize it to the centerpoint of the circular area—$(0, 1)$ in the image below, then rotate it by some arbitrary angle about that new centerpoint­—how can the $x$ and $y$ bounds be found without interpolation?

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Instead of rotating your egg I'd prefer to rotate the bounding box. I hope you are able to translate between these views. Suppose $(a,b)$ is one direction of the box. Then in order to find the points where the curve is maximal or minimal with respect to that direction, you need to find the points where the tangent of the curve is orthogonal to that direction. Orthogonal means dot product is zero, and the tangent direction is the direction of derivatives. So let's start by computing some derivatives (for which I used Sage):

\begin{align*} \frac{\mathrm d\,x}{\mathrm d\theta}&= \frac12r\sin\theta\bigl((2-c)\cos\theta-c\bigr) & \frac{\mathrm d\,y}{\mathrm d\theta}&= r\cos\theta \end{align*}

Now set the dot product equal to zero:

\begin{align*} 0&\overset!=\left\langle\begin{pmatrix}a\\b\end{pmatrix}, \begin{pmatrix}\frac{\mathrm d\,x}{\mathrm d\theta}\\ \frac{\mathrm d\,y}{\mathrm d\theta}\end{pmatrix}\right\rangle= \frac12ar\sin\theta\bigl((2-c)\cos\theta-c\bigr)+br\cos\theta\\ 0&\overset!=a\sin\theta\bigl((2-c)\cos\theta-c\bigr)+2b\cos\theta \end{align*}

Now dealing with trigonometric functions here may make things a bit hard, so I'd use the tangent half-angle substitution here:

$$t:=\tan\frac\theta2\qquad \sin\theta=\frac{2t}{1+t^2}\qquad \cos\theta=\frac{1-t^2}{1+t^2}$$

Using this you can write

\begin{align*} 0&\overset!=a\frac{2t}{1+t^2}\bigl((2-c)\frac{1-t^2}{1+t^2}-c\bigr)+2b\frac{1-t^2}{1+t^2}\\ 0&\overset!=at\bigl((2-c)(1-t^2)-c(1+t^2)\bigr)+b(1-t^2)(1+t^2)\\ 0&\overset!=bt^4+2at^3+2a(c-1)t-b \end{align*}

This is a quartic (i.e. 4th degree) polynomial equation in $t$. Solving those is not beautiful, but you can solve this using radical expressions, without interpolation or resorting to numerical methods. I would expect two real solutions, one corresponding to each boundary. Turn the values $t$ you get back into $\theta$ (or compute $\sin\theta$ and $\cos\theta$ directly from $t$ to avoid the trigonometry) then plug this back into the original formula to obtain the extremal points. Do the same in the orthogonal direction $(-b,a)$ and you have all four points defining your bounding box. Rotate that if you want it aligned with your axes.

Note that the tangent half-angle substitution has a blind spot: $\theta=\pm\pi$ corresponds to $t\to\infty$. So if your direction is not rotated, and you are looking for vertical tangents, be sure to cover that case separately.

Below is a snapshot of one instance of this problem. See this blog page for an interactive version with some additional text.

Figure

$\endgroup$
4
  • $\begingroup$ I voted this up for now but it might take some time to accept. I want to translate it into the minX, minY, maxX, maxY equations needed to make sure it works first and math isn't my strongest suite so it might take some time. $\endgroup$
    – CoryG
    Commented Aug 22, 2018 at 2:47
  • $\begingroup$ As a follow-up, would you be able to give these in the form of the min/max equations, or the equations for the angles of the egg? I'm having serious issues translating these into the required form even with Mathematica. $\endgroup$
    – CoryG
    Commented Aug 22, 2018 at 3:47
  • $\begingroup$ I went ahead and marked this as correct, though the equations I'm using now are substantially more complex due to factors for compression and expansion on independent a and b axis as well as rotational normalization for the result of the independent a and b radius+expansion+compression - interpolation is probably how I need to go about it now. $\endgroup$
    – CoryG
    Commented Aug 22, 2018 at 9:22
  • 1
    $\begingroup$ @CoryG: I created an interactive version for you and other readers. Applying the transformation you applied to the egg to these extremal points as well shouldn't be too hard. Note that only the direction of $(a,b)$ is important, so you might pick $a=\cos\varphi,b=\sin\varphi$ where $\varphi$ depends on the rotation of the egg. I'm not sure what expansion and compression you are talking about. $\endgroup$
    – MvG
    Commented Aug 22, 2018 at 22:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .