views:

2873

answers:

3

I have an ellipse centered at (0,0) and the bounding rectangle is x = [-5,5], y = [-6,6]. The ellipse intersects the rectangle at (-5,3),(-2.5,6),(2.5,-6),and (5,-3)

I know nothing else about the ellipse, but the only thing I need to know is what angle the major axis is rotated at.

seems like the answer must be really simple but I'm just not seeing it... thanks for the help!

+2  A: 

The gradient of the ellipse is identical to the gradient of the intersects with the bounding rectangle along one side of the ellipse. In your case, that's the line from (-2.5,6) to (5,-3), the top side of your ellipse. That line has a vertical drop of 9 and a horizontal run of 7.5.

So we end up with the following right-angled triangle.

(-2.5,6)
  *-----
  |\x
  | \
  |  \
9 |   \
  |    \
  |    x\
  +------* (5,-3)
    7.5

The angle we're looking for is x which is the same in both locations.

We can calculate it as:

   -1
tan   (9/7.5)

which gives us an angle of -50.19 degrees

paxdiablo
"The gradient of the ellipse is identical to the gradient of the intersects with the bounding rectangle along one side of the ellipse." Assuming that it correct, yours is a much more elegant solution than mine
Andy Brice
The ellipse is mirrored around the major axis so the upper line and lower line are parallel (and also parallel with the major axis itself). I can't prove that from first principles but it is correct and you can tell from the mirror nature of the four intersects.
paxdiablo
Of course, I could be wrong; it's been 20 years since I did geometry and trigonometry :-).
paxdiablo
The chords are parallel, but not necessarily also with the major axis of the ellipse, You can create many bounding rectangles that do not necessarily have the major axis parallel to the diagonal of the rectangle
There's only ONE bounding rectangle that's x-axis-parallel AND has four intersects with the ellipse. You'd be right if the rectangle weren't x-axis-parallel. However, it is, so the ellipse major axis gradient is parallel with the line segments formed between the intersection points.
paxdiablo
hmm, your coordinate system is self-defined, and given any ellipse, you can shrink down a rectangle that has 4 intersection points in any coordinate system
@GSS, I just noticed that an earlier comment of used stated "parallel to the diagonal of the rectangle". I'm not talking about the line between the rectangle corners but the line between the two intersect points (on the 'top' of the ellipse) - just wanted to clear that up.
paxdiablo
@GSS, re your "hmm..." comment, are you agreeing or arguing :-) ? Or just commenting?
paxdiablo
right, I'm saying the major axis of the ellipse is not necessarily parallel to the diagonal, but that the intersection points are, so the angle you calculate is not necessarily equal to the rotation of the major axis
heh, anyway I found a different way I believe solves the problem (and gives a different answer) but I suppose now this is getting into mathematical proofs that might not be relevant to this forum (willing to agree to disagree) :)
+1  A: 

If (0, 0) is the center, than equation of Your ellipse is:

F(x, y) = Ax^2 +By^2 + Cxy + D = 0

For any given ellipse, not all of the coefficients A, B, C and D are uniquely determined. One can multiply the equation by any nonzero constant and obtain new equation of the same ellipse.

4 points You have, give You 4 equations, but since those points are two pairs of symmetrical points, those equations won't be independent. You will get 2 independent equations. You can get 2 more equations by using the fact, that the ellipse is tangent to the rectangle in hose points (that's how I understand it).

So if F(x, y) = Ax^2 +By^2 + Cxy + D Your conditions are:
dF/dx = 0 in points (-2.5,6) and (2.5,-6)
dF/dy = 0 in points (-5,3) and (5,-3)

Here are four linear equations that You get

F(5, -3) = 5^2 * A + (-3)^2 * B + (-15) * C + D = 0  
F(2.5, -6) = (2.5)^2 * A + (-6)^2 * B + (-15) * C + D = 0  
dF(2.5, -6)/dx = 2*(2.5) * A + (-6) * C = 0  
dF(5, -3)/dy = 2*(-3) * B + 5 * C = 0

After a bit of cleaning:

   25A +  9B - 15C + D = 0 //1
6.25A + 36B - 15C + D = 0 //2
   5A       -  6C     = 0 //3
      -  6B +  5C     = 0 //4

Still not all 4 equations are independent and that's a good thing. The set is homogeneous and if they were independent You would get unique but useless solution A = 0, B = 0, C = 0, D = 0.

As I said before coefficients are not uniquely determined, so You can set one of the coefficient as You like and get rid of one equation. For example

   25A + 9B - 15C = 1 //1
   5A      -  6C = 0 //3
      - 6B +  5C = 0 //4

From that You get: A = 4/75, B = 1/27, C = 2/45 (D is of course -1)

Now, to get to the angle, apply transformation of the coordinates:

x = ξcos(φ) - ηsin(φ)
y = ξsin(φ) + ηcos(φ)

(I just couldn't resist to use those letters :) )
to the equation F(x, y) = 0

F(x(ξ, η), y(ξ, η)) = G(ξ, η) =
  A (ξ^2cos^2(φ) + η^2sin^2(φ) - 2ξηcos(φ)sin(φ))
+ B (ξ^2sin^2(φ) + η^2cos^2(φ) + 2ξηcos(φ)sin(φ))
+ C (ξ^2cos(φ)sin(φ) - η^2cos(φ)sin(φ) + ξη(cos^2(φ) - sin^2(φ))) + D

Using those two identities:

2cos(φ)sin(φ) = sin(2φ)
cos^2(φ) - sin^2(φ) = cos(2φ)

You will get coefficient C' that stands by the product ξη in G(ξ, η) to be:

C' = (B-A)sin(2φ) + Ccos(2φ)

Now your question is: For what angle φ coefficient C' disappears (equals zero)
There is more than one angle φ as there is more than one axis. In case of the main axis B' > A'

Maciej Hehl
Why does dF/dx=dF/dy=0 at the point of intersection?And how do you get from the coefficients to the angle of the ellipse?
Andy Brice
You've only got two formulae here with four unknowns so you can't work out A, B, C and D at all. So this isnt really a solution.
paxdiablo
Andy I'm not a native speaker so I may be wrong of course, but I understand bounding rectangle as a rectangle in which the ellipse is contained and that the ellipse is tangent to the sides of the rectangle. So word intersects is a bit misleading here.
Maciej Hehl
Pax In fact I have 3, I mean 3 independent linear equationsI'll edid my "solution" in the moment to explain it
Maciej Hehl
I was thinking this would be the solution, but why are the dF/dx = 0 and dF/dy = 0 equations not independent of the others? Why are the coefficients for the ellipse not uniquely determined? This solution troubles me because the points at which you evaluate the extrema of F should be switched...hmm
I don't know why they are not independent, but they are not and that's easy to check. Calculate the determinant of the main matrix of that set. Why are the coefficients not uniquely determined? As I said 2x^2 + 3y^2 + 2xy - 5 = 0 is exactly the same ellipse as 4x^2 + 6y^2 + 4xy - 10 = 0
Maciej Hehl
Those points are actoally not the exrtema of F. F has one extremum in point (0, 0). Gradient of F must be horizontal (vertical component = dF/dy must be zoro) in point (5, -3) and vertical (horizontal component = dF/dx must be zero) in point (2.5, -6)
Maciej Hehl
The answer is: -55,06815171 degrees = -0,96112056 rad
Maciej Hehl
heh, not sure what you are saying, but if you draw out the ellipse, dF/dx = 0 @ (5,-3) and dF/dy = 0 @ (2.5,-6)
Look herehttp://en.wikipedia.org/wiki/Implicit_function#Formula_for_two_variables
Maciej Hehl
ah, nice! I'm not sure I have encountered this before... did you just notice that was the case because it is an implicit fcn?
You are misinterpreting F. Ok I'll try another way. At the point (2.5, -6) tangent to the ellipse is horizintal, so dy/dx = 0. Not dF/dy, but dy/dx. Now in case of our equation F(x, y) = 0, y is an implicit function of x and derivative dy/dx=-(dF/dx)/(dF/dy).
Maciej Hehl
I wrote the comment again, because this time i wrote dF/dx instead of dF/dy :)
Maciej Hehl
Do You know what gradient is? I rather thought about all this in terms of Function of 2 variables and it's equipotential curve from the begining. implicit function was my other atempt to convince You :) Just try to calculate the angle and coefficients A', B' and C' nad see what you get
Maciej Hehl
Plot the ellipse based on those results and then try Your way :)
Maciej Hehl
A: 
  1. Set the angle of the ellipse = 0
  2. Calculate the 4 points of intersection
  3. Work out the error between the calculated intersection points and the desired ones (i.e. sum the 4 distances).
  4. If error is too large use the secant method or Newton-Rhapson to work out a new angle for the ellipse and go to 2.

I used a similar approach to work out another ellipse problem:

http://successfulsoftware.net/2008/07/18/a-mathematical-digression/

http://successfulsoftware.net/2008/08/25/a-mathematical-digression-revisited/

See also:

http://en.wikipedia.org/wiki/Secant_method

http://en.wikipedia.org/wiki/Newton_Rhapson

Andy Brice