1
\$\begingroup\$

How to find the points where it is most extreme on the X and Y axis?

For example lets say I have an equation that describes an ellipse that is rotated:

(x * RadiusX * Rx + y * RadiusX * Ux)^2 + 
(x * RadiusY * Ry + y * RadiusY * Uy)^2 = RadiusY^2 

enter image description here

How can I find the points where it will be most extreme on each axis

Please keep in mind the values for variables RadiusX, RadiusY, Rx, Ry, Ux, Uy are known.

An example with values:

((x * 1 * 0.70711) + (y * 1 * -0.70711))^2 + 
((x * 1.414213 * -0.70711) + (y * 1.414213* -0.70711))^2 = 1.414213 * 1.414213
\$\endgroup\$
1

2 Answers 2

1
\$\begingroup\$

A trick I find often helps with ellipses is to think of them as stretched/rotated copies of the unit circle.

By reversing the transformation, we can map the problem back onto the unit circle, where the math is usually easier, then run the answer back through the transformation to answer our original question about the ellipse.

enter image description here

To roughly outline the steps:

  1. Find the transformation matrix that maps the unit circle to your ellipse, then compute its inverse

  2. Apply its inverse to vectors along the horizontal and vertical axes (1, 0) & (0, 1) - these give you the directions of the edges of the blue bounding box, after it's been squashed to a diamond.

    Our extreme points in our original coordinate system map to where these slanted lines are tangent to the circle.

  3. Take the perpendiculars of these transformed directions (green lines in the diagram above) and normalize them to unit length to snap them onto the unit circle. These are the points of tangency.

  4. Apply your transformation matrix to these tangent points to map them back to the extremes in our original coordinate system.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you very much for your help. This solution does it for me. I had to do a bit of extra work to implement it, but at the end, the solution does indeed give the points on the ellipse that is tangent to the axis directions. This should allow me to create a Cylinder/Plane/Box Collision detection without having to use Lagrange Multiplier. \$\endgroup\$
    – mdshirzada
    Commented Jun 5, 2018 at 22:46
2
\$\begingroup\$

The general equation of an ellipse centered at the origin is:

$$(ax+by)^2+(cx+dy)^2=r^2$$

Expand w.r.t x and y:

$$(a^2+c^2)x^2+(b^2+d^2)y^2+2(ab+cd)xy=r^2$$

An horizontal line has equation y=k. Either it intersects with the ellipse in two points, or it intersects in only one point (it's tangent), or it doesn't intersect at all. We find the intersection by solving the trinomial (in x):

$$(a^2+c^2)x^2+2(ab+cd)kx+(b^2+d^2)k^2-r^2=0$$

There is only one intersection when the discriminant is zero, hence you want to find k such that

$$4(ab+cd)^2k^2-4(a^2+c^2)(b^2+d^2)k^2+4(a^2+c^2)r^2=0$$

Expand and simplify:

$$\left(a^2b^2+c^2d^2+2abcd-a^2b^2-a^2d^2-b^2c^2-c^2d^2\right)k^2+(a^2+c^2)r^2=0$$

$$(2abcd-a^2d^2-b^2c^2)k^2+(a^2+c^2)r^2=0$$

$$(ad-bc)^2k^2=(a^2+c^2)r^2$$

$$k=\pm\frac{r\sqrt{a^2+c^2}}{|ad-bc|}$$

The positive k is the maximum value of y, the negative the minimum value. By symmetry of the ellipse, they are opposite.


The extreme values of x can be found the same way, using a vertical line x=l. The same computation will lead to

$$l=\pm\frac{r\sqrt{b^2+d^2}}{|ad-bc|}$$

The positive l is the maximum value of x, the negative the minimum value. Again, by symmetry of the ellipse, they are opposite.


The expressions found are not defined when ad=bc, but then the two squares in the original equation are proportional and the conic is degenerate (the equation leads to two parallel lines).

\$\endgroup\$

You must log in to answer this question.

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