Angle between the normal of a origin-centered semiellipse in a point P and the x axis

120 Views Asked by At

I use a software called Substance Designer which has a Pixel Processor where I can assign to every pixel of a image a gray-scale value defined by a series of operations.

I am basically trying to generate a "normal gradient" generated by the normals of a semi-ellipse with a given a and b semi-major and semi-minor axis.

This semi ellipse is **origin-centered ** and has the principle axes parallel to the x and y axes.

For all points P(x,y) with y≥0, I want to find the angle or direction θ of the outwards-facing ellipse normal that intersects that point. Both when a>b and if possible when b>a "

Here is a visual representation of what I am after, although I only need the values for y>0

I am trying to visualize the blue tangents on the evolute when y> 0. All the points on the same normal will have the same value.

Thanks

3

There are 3 best solutions below

10
On BEST ANSWER

This is an extended comment, to solve the following problem that came up in the comments:

We have an axis-aligned ellipse, centered at origin, width $2$, height $2 h$ — so semi-major axis is $1$ and on $x$ axis, and semi-minor axis is $h$ and on $y$ axis, with $0 \lt h \lt 1$. For all points $(x, y)$ on or outside the ellipse, $x \gt 0$, $y \gt 0$, we want to find the direction (angle or slope) of the ellipse normal that passes through that point.

The eccentricity $\epsilon$ of this ellipse is $$\epsilon = \sqrt{1 - h^2} \quad \iff \quad h = \sqrt{1 - \epsilon^2}$$

Using angle parameter $\varphi$ the points on the ellipse can be parametrized as $$\left\lbrace ~ \begin{aligned} x_{\varphi}(\varphi) &= \cos\varphi \\ y_{\varphi}(\varphi) &= h \sin\varphi \\ \end{aligned} \right .$$ The slope of the normal is $$m = \frac{ -\frac{d x_\varphi(\varphi)}{d \varphi} }{ \frac{d y_\varphi(\varphi)}{d \varphi} } = \frac{1}{h}\tan\varphi$$ Solving for $\varphi$ we find $$\varphi = \arctan\left(m h\right)$$ and reparametrizing the points on the ellipse (in the positive quadrant, $x \gt 0$, $y \gt 0$), we get $$\left\lbrace ~ \begin{aligned} \displaystyle x_m(m) &= \frac{1}{\sqrt{1 + h^2 m^2}} \\ \displaystyle y_m(m) &= \frac{h^2 m}{\sqrt{1 + h^2 m^2 }} \\ \end{aligned} \right .$$ The points on the normal are on a line $y = m x + y_0$, i.e. $$y_m(m) = m x_m(m) + y_0(m)$$ and rearranging and simplifying, we find that $$y_0(m) = \frac{(h^2 - 1) m}{\sqrt{1 + h^2 m^2}}$$ If point $(x, y)$ is on the normal with slope $m$, it too fulfills the equation: $$y = m x + y_0(m) = m x + m \frac{h^2 - 1}{\sqrt{h^2 m^2 + 1}}$$ To solve this for $m$ (remembering that $\theta = \arctan m$) we need to solve a quadric equation: $$\begin{aligned} \left( h^2 x^2 \right) & m^4 \\ + \left( - 2 h^2 x y \right) & m^3 \\ + \left( x^2 - h^4 + h^2 y^2 + 2 h^2 - 1 \right) & m^2 \\ + \left( - 2 x y \right) & m \\ + \left( y^2 \right) & ~ = 0 \\ \end{aligned}$$ This has zero to four real roots $m$. At and outside the ellipse, at $x \gt 0$, $y \gt 0$, there is exactly one real root (because the normals for the positive quadrant only intersect at $y \le 0$).

Unfortunately, there is no simple algebraic expression for the solutions $m$ that fulfill above.

For what it is worth, Maple suggests the following operations to find the four candidate real roots:

t36 = x * x
t33 = y * y
t43 = h * h
t47 = t43 * t43
t48 = t43 * t47
t83 = (t48 + t43) * t36
t32 = t33 * t33
t82 = 3 * t32
t81 = 3 * t33
t26 = 3 * t36
t80 = -3 * t47
t79 = 6 * t48
t49 = t47 * t47
t78 = -3 * t49
t77 = 3 * t49
t74 = -18 * t47
t73 = 12 * t48
t24 = t43 * t33
t64 = t47 - 2 * t43 + 1
t16 = -t24 - t36 + t64
t65 = t47 * t36
t17 = t65 * t82
t35 = t36 * t36
t67 = t43 * t35
t18 = t67 * t81
t21 = t32 * t80
t22 = 3 * t24
t57 = y * t33
t31 = t57 * t57
t23 = t48 * t31
t25 = -3 * t35
t51 = t48 * t48
t28 = t43 * t51
t30 = t43 * t49
t54 = x * t36
t34 = t54 * t54
t45 = cbrt(-1 + 6 * t67 + 18 * t65 - 15 * t47 + 20 * t48 - 15 * t49 - t51 + 6 * t43 + 6 * t30 + t34 + t21 + t22 + t23 + t25 + t26 + t17 + t18 + t36 * t77 + t32 * t78 + t32 * t79 + t35 * t80 + t30 * t81 + 6 * y * sqrt(3 * t17 + 3 * t18 + 3 * t21 + 3 * t22 + 3 * t23 + 3 * t25 + 24 * t28 - 84 * t51 + 168 * t48 - 84 * t47 + 24 * t43 - 3 * t49^2 - 3 + (-2 * t31 - 70) * t77 + 3 * t64 * t34 + 3 * (t31 + 56) * t30 + 3 * (t78 + t73 + t74 + 12 * t43) * t35 + (-3 * t51 + 12 * t30 - 18 * t49 + t73) * t82 + (3 * t28 - 18 * t51 + 45 * t30 - 60 * t49 + 45 * t48 + t74 + (3 * t48 - 6 * t47) * t35 + 21 * (t30 - 4 * t49 + t79 - 4 * t47 + t43) * t36) * t81 + (3 + 3 * t51 - 18 * t30 + 45 * t49 - 60 * t48 + 45 * t47 - 18 * t43 + (t77 - 6 * t48) * t32) * t26) * h * x + (48 * t83 - 12 * t49 - 12 * t47 - 96 * t65 + 18 * t48) * t33 - 12 * t83)
t68 = t16 * t16 / t45
t46 = sqrt((t33 + ((2 * t16) + t45 + t68) / (3 * t43)) / t36)
t66 = t16 / t43
t71 = y / x
t72 = (2 * t71 / t43 + (t66 * y + t57) / t54) / t46
t19 = t71 / 2
t70 = t19 + t46 / 2
t69 = t19 - t46 / 2
t60 = (2 * t33 - ((t45 + t68)/t43 - 4 * t66) / 3) / t36
t62 = sqrt(t60 - 2 * t72) / 2
t61 = sqrt(t60 + 2 * t72) / 2
m1 = t70 + t61
m2 = t70 - t61
m3 = t69 + t62
m4 = t69 - t62

Above, cbrt(...) is the cube root operation (same as pow(..., 1.0/3.0)), and sqrt(...) is the square root operation. If the argument of the square root is negative (but note that it could be effectively zero, due to rounding errors and such, even if strictly speaking negative; you should round those to positive zero instead), then those candidate solutions do not exist. Remember that you do still need to verify that $m \gt 0$, to get the desired result, $\theta = \arctan m$.

(Also remember that if $y = 0$ and $x \gt 0$, then $\theta = 0$; if $y \gt 0$ and $x = 0$, then $\theta = 90^o$. The rest of the quadrants are symmetric.)

Because of this, it might be worth the effort to consider approximations to the problem; for example, instead of a real ellipse, consider approximating the ellipse using one or two cubic polynomials (perhaps with four cubic Bézier curves). Cubic approximations should yield at least two significant digits of precision (less than 1% of error), and would definitely suffice for human perception and "visual arts". I am not sure if that approach yields any better answers, but it would be the avenue I would explore next.

7
On

This figure may help those who wish to solve this problem:

enter image description here

By the way, here are three origin-centered ellipses with the same eccentricity $e=2$ that go through the same point, so if the OP wants a unique and hence solvable problem, it should be restated as I have, above.

enter image description here

15
On

Consider an axis-aligned ellipse centered at origin, height $2$ (semimajor axis $1$), width $2\chi$ (semiminor axis $\chi \lt 1$), parametrized using angle variable $\varphi$: $$\vec{p}(\varphi) = \left [ \begin{matrix} p_x(\varphi) \\ p_y(\varphi) \end{matrix} \right ] = \left [ \begin{matrix} \chi \cos \varphi \\ \sin\varphi \end{matrix} \right ] \tag{1}\label{EQ1}$$ The eccentricity $\epsilon$ of this ellipse is $$\epsilon = \sqrt{1 - \chi^2} \quad \iff \quad \chi = \sqrt{1 - \epsilon^2} \tag{2}\label{EQ2}$$ The tangent vector $\vec{t}(\varphi)$ is $$\vec{t}(\varphi) = \nabla\vec{p}(\varphi) = \left [ \begin{matrix} \displaystyle \frac{d p_x(\varphi)}{d \varphi} \\ \displaystyle \frac{d p_y(\varphi)}{d \varphi} \\ \end{matrix} \right ] = \left [ \begin{matrix} t_x(\varphi) \\ t_y(\varphi) \end{matrix} \right ] = \left [ \begin{matrix} - \chi \sin \varphi \\ \cos \varphi \end{matrix} \right ]\tag{3}\label{EQ3}$$ The normal vector $\vec{n}(\varphi)$ is the tangent vector rotated $90^o$ clockwise (since the angle parameter traverses the ellipse counterclockwise): $$\vec{n}(\varphi) = \left [ \begin{matrix} t_y(\varphi) \\ -t_x(\varphi) \end{matrix} \right ] = \left [ \begin{matrix} n_x(\varphi) \\ n_y(\varphi) \end{matrix} \right ] = \left [ \begin{matrix} \cos\varphi \\ \chi\sin\varphi \end{matrix} \right ] \tag{4}\label{EQ4}$$ The angle $\vec{n}(\varphi)$ makes with the $x$ axis with $0^o \le \varphi \le 180^o$ is $\theta$, $$\theta = \operatorname{arctan}\left( \frac{n_y(\varphi)}{n_x(\varphi)} \right) = \operatorname{arctan}\left( \chi \frac{\sin\varphi}{\cos\varphi} \right) = \operatorname{arctan}\left(\chi \tan\varphi\right)$$

This means that for an axis-aligned ellipse that is taller than it is wide, the relationship between the angle parameter $\varphi$ and the angle between the ellipse normal and the positive $x$ axis $\theta$ is $$\theta = \operatorname{arctan}\left(\sqrt{1 - \epsilon^2} \tan\varphi\right) \tag{5a}\label{EQ5a}$$ and conversely (by solving above for $\varphi$), $$\varphi = \operatorname{arctan}\left(\frac{1}{\sqrt{1-\epsilon^2}}\tan\theta\right)\tag{5b}\label{EQ5b}$$


This same ellipse also fulfills $$\frac{x^2}{\chi^2} + \frac{y^2}{1^2} = 1$$ which we can solve for $y$: $$y(x) = \pm \sqrt{1 - \frac{x^2}{\chi^2}} = \pm\sqrt{1 - \frac{x^2}{1 - \epsilon^2}}$$ Since $\eqref{EQ1}$ says that $x = \chi\cos\varphi$, the angle parameter $\varphi$ is $$\varphi = \operatorname{arccos}\left(\frac{x}{\chi}\right) = \operatorname{arccos}\left(\frac{x}{\sqrt{1 - \epsilon^2}}\right)$$ and the angle $\theta$ relationship to parameter $\varphi$ simplifies to $$\theta = \operatorname{arctan}\left(\frac{1}{x}\sqrt{\frac{1 - \epsilon^2 - x^2}{1 - \epsilon^2}}\right)$$ in the positive quadrant ($x \ge 0$, $y \ge 0$).