Results 1 to 3 of 3

Thread: Find Ellipse knowing 2 points, half-axises, rotation angle

  1. #1
    Jun 2013

    Question Find Ellipse knowing 2 points, half-axises, rotation angle


    I am implementing a SVG renderer and I just found a very nasty trigonometry problem. I already wrote a lot of geometric code, but nothing gave me so many headaches like "elliptical arcs" which area feature of SVG =D

    Basically I receive as input 2 points which bellong to the ellipse, the rotation of the ellipse in relation to axis X, and the sizes of the half-axises of the ellipse.

    And I want to find the center of the ellipse. I know that there are 2 solutions to the problem, and I need both.

    There are images ilustrating the problem here:

    Path - Elliptical Curve
    SVG Basics Tutorials - Elliptical Arcs with SVG

    Here is what I tried so far:

    I know the following information:

    X,Y -> this is a point which bellongs to the ellipse. I have this point, but I don't know which parameter t=t2 is at this point
    Xstart,Ystart -> Another point of the ellipse that I know, has parameter t=t1
    CX,CY -> This is what I want! The center of the ellipse!

    solve 4 equations and 4 unknown values (CX, CY, t1, t2)
    X,Y has t=t2 // Xstart,Ystart has t=t1
    CX := X - RX*Cos(t2)*Cos(XRotation) + RY*Sin(t2)*Sin(XRotation);
    CX := XStart - RX*Cos(t1)*Cos(XRotation) + RY*Sin(t1)*Sin(XRotation);
    CY := Y - RY*Sin(t2)*Cos(XRotation) - RX*Cos(t2)*Sin(XRotation);
    CY := YStart - RY*Sin(t1)*Cos(XRotation) - RX*Cos(t1)*Sin(XRotation);

    Substituting we get 2 equations and 2 unknown values (t1, t2)
    X - RX*Cos(t2)*Cos(XRotation) + RY*Sin(t2)*Sin(XRotation) = XStart - RX*Cos(t1)*Cos(XRotation) + RY*Sin(t1)*Sin(XRotation)
    Y - RY*Sin(t2)*Cos(XRotation) - RX*Cos(t2)*Sin(XRotation) = YStart - RY*Sin(t1)*Cos(XRotation) - RX*Cos(t1)*Sin(XRotation)


    A = RX*Cos(XRotation)
    B = RY*Cos(XRotation)
    C = RY*Sin(XRotation)
    D = RX*Sin(XRotation)

    X - A*Cos(t2) + C*Sin(t2) = XStart - A*Cos(t1) + C*Sin(t1)
    Y - B*Sin(t2) - D*Cos(t2) = YStart - B*Sin(t1) - D*Cos(t1)

    Attempt to corner Sin(t1):

    X - A*Cos(t2) + C*Sin(t2) = XStart - A*sqrt(1-Sin(t1)^2) + C*Sin(t1)
    X - A*Cos(t2) + C*Sin(t2) - XStart - C*Sin(t1) = - A*sqrt(1-Sin^2(t1))
    Mega = X - A*Cos(t2) + C*Sin(t2) - XStart
    Mega^2 - 2*Mega*C*Sin(t1) + C^2*Sin^2(t1) = A^2*(1-Sin^2(t1))
    Mega^2 - A^2 - 2*Mega*C*Sin(t1) + (C^2+A^2)*Sin^2(t1) = 0


    AB = (C^2+A^2)
    BB = -2*Mega*C
    CB = Mega^2


    Now roll it back!

    X - A*Cos(t2) + C*Sin(t2) = XStart - A*sqrt(1-Sin(t1)^2) + C*Sin(t1)

    But at this point I am totally lost ... the fully expanded equation is *huge*! And I have no idea if I am getting anywhere...

    Does anyone know what I could do to solve this in a simpler way? Because the way that I am trying so far is really big and nasty....
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Sep 2012

    Re: Find Ellipse knowing 2 points, half-axises, rotation angle

    Hey sekelsenmat.

    Why don't you rotate the points so that the axis are aligned with y and z axes and use parameterized equations to get the solution?

    If you have a general ellipse at some custom CX,CY then an axis aligned parameterization would be:

    EX = CX + RX*cos(t)
    EY = CY + RY*sin(t)

    From here you need to find the values of t that give CX and CY and the values that do this will be t = 0 and t = pi/2.

    If the ellipse has been rotated, then you need to rotate it so that it is axis aligned. You can rotate something by the inverse of its angle quite easily with a standard rotation matrix (with -theta as your argument).

    Overall though, once you get it so that the rotation axis are aligned to Y and Z, then given your points for EX and EY for two points, you obtain values of RX and RY by picking a value of t that eliminates the RX RY terms to get CX and CY (like mentioned above).
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor
    Dec 2012
    Athens, OH, USA

    Re: Find Ellipse knowing 2 points, half-axises, rotation angle

    I think it's easier if you don't use parametric equations. The attachment indicates a solution using the "standard" equations for an ellipse. As you probably know, arbitrary values for the current point, (xEnd,yEnd), rx and ry can possibly have no solution. I don't know what SVG does in this case; I didn't look very hard to find what happens. However, your code should take this possibility into account. If you have trouble turning the discusssion into code, post your questions in this thread and I'll try to answer.

    Find Ellipse knowing 2 points, half-axises, rotation angle-mhfellipsesa.png

    Find Ellipse knowing 2 points, half-axises, rotation angle-mhfellipsesb.png
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. How to find rotation angle given output of cos?
    Posted in the Trigonometry Forum
    Replies: 1
    Last Post: Sep 9th 2012, 06:09 PM
  2. Replies: 3
    Last Post: May 29th 2011, 06:48 AM
  3. Replies: 2
    Last Post: Mar 17th 2011, 12:35 PM
  4. Find equation of curve, by rotation of ellipse ?
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: Mar 10th 2011, 11:15 PM
  5. Replies: 3
    Last Post: Feb 27th 2009, 07:52 AM

Search Tags

/mathhelpforum @mathhelpforum