# Transformation Of Conics

• Nov 6th 2006, 12:04 PM
spiritualfields
Transformation Of Conics
First, just to clarify the nomenclature used by my text book, an equation of the form:

A(x squared) + Bxy + C(y squared) + Dx + Ey + F = 0

is a conic if A, B, and C are not simultaneously equal to 0.

The text then goes on to discuss 4 topics:

Topic 1: Identifying conics, which shows how a conic can be identified from the above equation when the Bxy term is not present, by multiplying A and C and evaluating the result.

Topic 2: Using a rotation of axes to transform equations, which relates the rotated axes with the original axes by using this theorem:

x = xprime(cos theta) - yprime(sin theta)
y = xprime(sin theta) + yprime(cos theta)

This section develops the idea of how the xy term of the general equation can be eliminated if the x and y axes are rotated through an appropriate angle. The resultant equation then takes on the form of a more recognizable conic equation, with vertices and foci and other characteristics with respect to the rotated axes.

Topic 3: Dicusses one example equation (which contains an xy term), first by a rotation to eliminate the xy term, to arrive at the recognizable equation of a hyperbola, which is then hand drawn. Then the topic gives the procedure for graphing the equation with a graphing utility, by solving the original equation using the quadratic equation.

Topic 4: Identifying Conics without a rotation of axes.

That's it. In my march through my precalculus book, I was greatly anticipating this chapter, but unless I'm missing something entirely, one important thing that I wanted to learn was not covered.

I want to be able to programmatically draw a rotated ellipse on a computer monitor. This means that I can't just hand-swag it in like the book does. Plus I want to determine what the angle of rotation is, which means I have to generate my own equations. The problem is coming up with the equation. For example, let's say I want to draw an ellipse on a set of axes that is rotated through 45 degrees. Let's say that for the transformed axis I want the origin to be in the center, and the major axis to be parallel with the xprime axis. And let's say that its vertices are (-10,0) and (10,0), and its y-intercepts are (0, 5) and (0, -5) with respect to the rotated axes.

What's the equation?

For a non-rotated ellipse, the equation would be

(x squared / 100) + (y squared / 25) = 1

For this non-rotated ellipse, I could simply create a table of x and y values, beginning with x = -10 and working in increments of 1 up to x = 10, I could calculate the y values (y = plus/minus (squareroot(25*(1 - (x squared / 100))))).

But how do I construct the table for an ellipse that has the same vertices and intercepts, but with respect to a rotated set of axes? It looks as if I need to somehow take the original non-rotated ellipse and get it into the general form, where it has an xy term due to the desired amount of rotation. Unfortunately, the text gives no guidance on how to do this.

The only thing I can think of is to use a brute force method, using the transformation theroem equations that relates x and y with xprime and yprime. By calcuating a table for a non-rotated ellipse with the vertices and y-intercepts that I want, I could then use each x and y value in the table as constants into the theorem equations. I would have two equations with two unknowns (one with a known x and unknown xprime and yprime, and one with a known y with an unknown xprime and yprime). I could calculate a table of xprimes and yprimes, with each xprime/yprime pair being calculated from each x/y pair. I'm thinking that this set of xprime/yprime pairs would give the rotated ellipse (since the theorem equations contains the rotation angle as one of the variables).

Is there another way to accomplish this? I'm thinking that there must be, because my method seems too roundabout (plus I'm not even sure if it will work). Ideally, I would like to create an equation that will give me a conic with the characteristics and rotated angle that I want. Is there a way to do this?
• Nov 6th 2006, 12:46 PM
ThePerfectHacker
Here is something you can do.

First draw a non-rotated conic.

For example,
$\frac{x^2}{4}+y^2=1$---> Ellipse.

1)I drew a dotted red line for this ellipse.

2)I drew a new coordinated system rotated 45 degrees. This is in the dotted blue line.

3)Using this new coordinate system and the aid of the first ellipse I drew a new rotated ellipse shown in thick red.
• Nov 6th 2006, 01:29 PM
spiritualfields
ThePerfectHacker, what equation did you use to produce the x/y values for the rotated ellipse? I can figure out the non-rotated ellipse, but how to programmatically create the points for the rotated ellipse is much less clear cut. Did you use the transformation theorem:

x = xprime(cos theta) - yprime(sin theta)
y = xprime(sin theta) + yprime(cos theta)

to do it, using substitution, solving for each xprime/yprime pair by using each non-rotated x/y pair and a desired rotation angle?

I'm wondering if there is a way to take the equation for the non-rotated ellipse

x squared/4 + y squared = 1

and transform it into the general form

A(x squared) + Bxy + C(y squared) + Dx + Ey + F = 0

in such a way that the equation defines an ellipse rotated through an angle of your choosing but with the same relative vertices and intercepts as the original non-rotated ellipse? I'm wondering if this is simply not possible or just too complex to achieve easily.
• Nov 6th 2006, 02:00 PM
JakeD
Quote:

Originally Posted by spiritualfields
ThePerfectHacker, what equation did you use to produce the x/y values for the rotated ellipse? I can figure out the non-rotated ellipse, but how to programmatically create the points for the rotated ellipse is much less clear cut. Did you use the transformation theorem:

x = xprime(cos theta) - yprime(sin theta)
y = xprime(sin theta) + yprime(cos theta)

to do it, using substitution, solving for each xprime/yprime pair by using each non-rotated x/y pair and a desired rotation angle?

I'm wondering if there is a way to take the equation for the non-rotated ellipse

x squared/4 + y squared = 1

and transform it into the general form

A(x squared) + Bxy + C(y squared) + Dx + Ey + F = 0

in such a way that the equation defines an ellipse rotated through an angle of your choosing but with the same relative vertices and intercepts as the original non-rotated ellipse? I'm wondering if this is simply not possible or just too complex to achieve easily.

The rotation defined by

$x = x' \cos\theta - y' \sin \theta$
$y = x' \sin\theta + y' \cos \theta$

takes points $(x',y')$ and rotates them anti-clockwise by angle $\theta$ to get points $(x,y)$.

If the points $(x,y)$ are on the ellipse defined by

$\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$

then after substitution the points $(x',y')$ satisfy the equation

$\frac{(x' \cos\theta - y' \sin \theta)^2}{a^2} + \frac{(x' \sin\theta + y' \cos \theta)^2}{b^2} = 1$

which you can expand into your desired form.

But note that this means the original ellipse in $(x,y)$ was rotated clockwise (the opposite direction of your rotation equations) to get the rotated ellipse in $(x',y')$.

I think you actually want to use the inverse of your rotation equations

$x = x' \cos\theta + y' \sin \theta$
$y = - x' \sin\theta + y' \cos \theta$

and then do the substitution. This way the angle $\theta$ measues an anti-clockwise rotation as is conventional.
• Nov 6th 2006, 05:06 PM
spiritualfields
JakeD, using

((xprime (cos theta)) - (yprime (sin theta))) squared / a squared

+

((xprime (sin theta)) + (yprime (cos theta))) squared / b squared

= 1

seems promising. I didn't think of substituting the theorem directly into the equation. I'll start off with known vertices and intercepts, and after expanding the equation (using an angle of rotation of my choosing), I should end up with a form that I can solve with the quadratic formula, right?

My only wonder now is if I can select, as the domain for the expanded equation, the interval (-a, +a) to solve for y. Will that get me the complete rotated ellipse?

You see, when I said I wanted to programmatically solve for a rotated ellipse, I really mispoke, as "programmatically" in this forum could easily be interpreted as "how to get the TI-89 to display a rotated ellipse?" or MathCad, or Mathematica, and so on. What I really meant is that what I want to do is calculate the table of x and y values myself, that represent the rotated ellipse, and using that table of x and y values I would draw the ellipse "programattically" onto a computer screen by setting the x and y pixel points to a certain color, say red against a white background, using a looping algorithm. Figuring out the table of x and y values for a non-rotated ellipse is easy, but a little tricky when you want to calculate the x and y values for a rotated ellipse.

I'm going to try it with your suggested substitutin method first. If that doesn't work, I'll try the brute force method that I mentioned in my opening post.
• Nov 6th 2006, 05:22 PM
ThePerfectHacker
Quote:

Originally Posted by spiritualfields

You see, when I said I wanted to programmatically solve for a rotated ellipse, I really mispoke, as "programmatically" in this forum could easily be interpreted as "how to get the TI-89 to display a rotated ellipse?" or MathCad, or Mathematica, and so on. What I really meant is that what I want to do is calculate the table of x and y values myself, that represent the rotated ellipse, and using that table of x and y values I would draw the ellipse "programattically" onto a computer screen by setting the x and y pixel points to a certain color, say red against a white background, using a looping algorithm. Figuring out the table of x and y values for a non-rotated ellipse is easy, but a little tricky when you want to calculate the x and y values for a rotated ellipse.

I'm going to try it with your suggested substitutin method first. If that doesn't work, I'll try the brute force method that I mentioned in my opening post.

What you can do is solve for the 'y' variable.
But this is done in two seperate parts. First you need a positive and negative function.
To demonstrate.

You want the equation in TI-89 for the parabola I used,
$\frac{x^2}{4}+y^2=1$
That means,
$y=\pm \sqrt{1-\frac{x^2}{4}}$
Note there are two functions.
First you graph,
$y=\sqrt{1-\frac{x^2}{4}}$
And then you graph,
$y=-\sqrt{1-\frac{x^2}{4}}$
Because both of these give you semi-ellipses.
Now you do not need to find the domain because the machine does that him-self.

So when you want to rotate that ellipse by 45 degree the all new set of points satisfy,
$\frac{(x \sqrt{2}/2-y\sqrt{2}/2)^2}{4}+(x\sqrt{2}/2+y\sqrt{2}/2)^2=1$
Multiply by four and open parantheses,
$\frac{1}{2}x^2-\frac{1}{2}xy+\frac{1}{2}y^2+2x^2-2xy+2y^2=4$
Multiply by two,
$x^2-xy+y^2+4x^2-4xy+4y^2=8$
Thus,
$5y^2-5xy+5x^2=8$
$5y^2+y(-5x)+(5x^2-8)=0$
Thus, you have,
$A=5,B=-5x,C=5x^2-8$
The solution for 'y' are,
$y=\frac{5x\pm\sqrt{25x^2-100x^2+160x}}{10}$
Thus,
$y=\frac{5x\pm \sqrt{160x-75x^2}}{10}$
Note the $\pm$ which indicates the two semi-ellipses. You will set this function one for positive and negative on you machine and he will graph it for you.

~~~
I just realized there is a way to graph ellipses much more elegantly thrught polar-coordinate, do you know what those are? I can show you how.
• Nov 6th 2006, 05:37 PM
spiritualfields
ThePerfectHacker, that's it! I wasn't sure how to work the non-rotated equation into the general form that "contained" the rotated angle. Through substitution of the theorem into the "recognizable" ellipse equation, and then expansion, it can be accomplished. JakeD had the same suggestion, and your example worked it out completely. My display area is going to be a window in a Windows program, with the coordinate points (x,y) mapping to pixel coordinates. The programming library that I use has a function that draws an ellipse of any size, but the constraint is that the major axis has to be parallel with the display's horizontal or vertical axis. With the transformation theorem, I should be able to "roll my own" now.

Thank you and JakeD too!
• Nov 6th 2006, 05:53 PM
JakeD
Quote:

Originally Posted by spiritualfields
JakeD, using

((xprime (cos theta)) - (yprime (sin theta))) squared / a squared

+

((xprime (sin theta)) + (yprime (cos theta))) squared / b squared

= 1

seems promising. I didn't think of substituting the theorem directly into the equation. I'll start off with known vertices and intercepts, and after expanding the equation (using an angle of rotation of my choosing), I should end up with a form that I can solve with the quadratic formula, right?

My only wonder now is if I can select, as the domain for the expanded equation, the interval (-a, +a) to solve for y. Will that get me the complete rotated ellipse?

You see, when I said I wanted to programmatically solve for a rotated ellipse, I really mispoke, as "programmatically" in this forum could easily be interpreted as "how to get the TI-89 to display a rotated ellipse?" or MathCad, or Mathematica, and so on. What I really meant is that what I want to do is calculate the table of x and y values myself, that represent the rotated ellipse, and using that table of x and y values I would draw the ellipse "programattically" onto a computer screen by setting the x and y pixel points to a certain color, say red against a white background, using a looping algorithm. Figuring out the table of x and y values for a non-rotated ellipse is easy, but a little tricky when you want to calculate the x and y values for a rotated ellipse.

I'm going to try it with your suggested substitutin method first. If that doesn't work, I'll try the brute force method that I mentioned in my opening post.

As TPH shows, either method will work.

As a computer programmer, I would choose the method that produces the code that is simplest to understand (both for you and other programmers). That may not be the most elegant or shortest code. For me, the brute force method would produce the simplest code: you generate a table of (x,y) values using the simpler equation, then transform those (x,y) values using a matrix multiplication.

I wouldn't call it the brute force method: when working with computer graphics, using matrix transformations is standard, so the brute force method is really the standard method.
• Nov 6th 2006, 07:34 PM
spiritualfields
JakeD, the more I think about this, the more the brute force method seems a better choice. I haven't actually started programming this yet, as I'm still thinking about how to proceed. The thing about the brute force method is that it appears adaptable to ellipses of any rotation. You always start out with a non-rotated ellipse, with a desired set of vertices and intercepts. The non-rotated table of x/y values is always calculated the same way for like ellipses (one form for ellipses where the major axis is parallel to the x-axis, and one form for ellipses where the major axis is parallel with the y-axis). The variables for the a and b values change, depending on the specific ellipse, but they always plug into the same slot in the equation with no deviation. Likewise, the transformations from these non-rotated x/y values to arrive at the rotated values will always use the same transformation equations, with the only deviation being the desired angle. I can visualize this working. I think this method could also work with rotated ellipses with a center different from the origin. An extra set of variables representing the center would have to be input into the non-rotated equation.

But converting from the non-rotated ellipse to the general equation, and then running it through the quadratic formula, however, I don't think can be standardized into an algorithm that could work for any ellipse. I think the exact algebra would be different for each specific ellipse.
• Nov 6th 2006, 07:58 PM
ThePerfectHacker
Given a general non-rotated ellipse, $a,b>0$
$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$

The polar coordinates,
$r=\frac{ab}{\sqrt{a^2\sin^2 \theta+b^2\cos^2 \theta}}$
Graph a compete ellipse.

Now, if you wanna rotate by 45 degree then substitute $\theta - 45^o$ (be sure the calculator is in degree mode). (Also, note the negative sign if it were positive it will rotate the ellipse clockwise).

Thus, you have,
$r=\frac{ab}{\sqrt{a^2\sin^2 (\theta-45^o)+b^2\cos^2 (\theta -45^o)}}$

$\frac{x^2}{4}+y^2=1$
We see that,
$a=2,b=1$
Thus, in polar coordinates,
$r=\frac{2}{\sqrt{2\sin^2 \theta+\cos^2 \theta}}$
You can greatly simplify that because,
$2\sin^2\theta+\cos^2\theta=\sin^2 \theta+\sin^2 \theta+\cos^2\theta=1+\sin^2\theta$
Thus,
$r=\frac{2}{\sqrt{1+\sin^2\theta}}$
To rotate just write,
$r=\frac{2}{\sqrt{1+\sin^2(\theta-45^o)}}$

Many circular curves are most easily expressed through polar coordinates furthermore rotation is extremely easy (though translation is extremely complicated).
If you know polar I think that is the method with least complexity.
• Nov 6th 2006, 08:26 PM
spiritualfields
ThePerfectHacker, the next chapter in my text gets into Polar coordinates of conics. I'm not sure what r represents, though the equation does look easier to work with than the others. Ultimately, I'll need the coordinate points (x,y) of the rotated elipse, because I'll be setting individual pixels on a computer display, to draw the ellipse.
• Nov 6th 2006, 08:55 PM
JakeD
Quote:

Originally Posted by spiritualfields
JakeD, the more I think about this, the more the brute force method seems a better choice. I haven't actually started programming this yet, as I'm still thinking about how to proceed. The thing about the brute force method is that it appears adaptable to ellipses of any rotation. You always start out with a non-rotated ellipse, with a desired set of vertices and intercepts. The non-rotated table of x/y values is always calculated the same way for like ellipses (one form for ellipses where the major axis is parallel to the x-axis, and one form for ellipses where the major axis is parallel with the y-axis). The variables for the a and b values change, depending on the specific ellipse, but they always plug into the same slot in the equation with no deviation. Likewise, the transformations from these non-rotated x/y values to arrive at the rotated values will always use the same transformation equations, with the only deviation being the desired angle. I can visualize this working. I think this method could also work with rotated ellipses with a center different from the origin. An extra set of variables representing the center would have to be input into the non-rotated equation.

But converting from the non-rotated ellipse to the general equation, and then running it through the quadratic formula, however, I don't think can be standardized into an algorithm that could work for any ellipse. I think the exact algebra would be different for each specific ellipse.

Sure it could be done. Instead of using specific values in TPH's solution, keep the $\cos \theta$ and $\sin \theta$ and other parameters in the formula. But it's too complicated and not worth doing.
• Nov 9th 2006, 01:25 PM
spiritualfields
Quote:

Sure it could be done. Instead of using specific values in TPH's solution, keep the and and other parameters in the formula. But it's too complicated and not worth doing.
I get a headache just thinking about it. The general form has the x and y terms spread throughout the formula, and in the first and second degree. What if there is no rotation, and thus no xy term? Programming a general function to draw any type of ellipse, rotated or not, based on the general equation might not actually be doable for all test inputs (at any event, the resulting speghetti code would be nearly unintelligible to all but the originator). Using the transformation equations, however, an algorithm could be written that is simpler, more understandable, and, most important, independent of the input, and thus more universal. For example if the ellipse undergoes no rotation, then the xprimes and yprimes simply resolve to the x and y values of the non-rotated ellipse.

All this conjecturing on my part, so far, is in the abstract. I'll wait until I get through the polar coordinates and conics chapter, and, if this brute force method (using the transformation equations) still seems the easiest way to go about programming a function to draw an ellipse (rotated or not), then I will write the function, test it, and post it here.

After that, I'll try to write an algorithm using the general form. I have to allow that it might not be as hard as I think it will be, since I haven't yet tried to work anything out. From past experience, when going from the abstract to the concrete, I find that what was conjectured to be hard and what was conjectured to be easy is not always so. For an algorithm using the general form, I can almost see a function with two branches, one branch to handle non-rotated ellipses (and thus the general form without an xy term), and one branch to handle rotated elipses (the general form with an xy term).

For the brute force case, the function would be defined like this:

void DrawEllipse(int a, int b, int x, int y, int angle, BOOL xMajorAxis = TRUE)
{
1. build a table of x and y values representing a non-rotated ellipse

2. using the x and y values, the angle, and the transformation equations, build a table of xprimes and yprimes.

3. set the pixel coordinates of the xprimes and yprimes
}

Where a and b are the vertices and intercepts, respectively, x and y are the center coordinates, angle the angular amount of rotation. The xMajorAxis parameter would be a boolean to orient the major axis of the ellipse, the default being the x-axis, and if the argument for that parameter was a FALSE, then the ellipse would be constructed with the major axis parallel with the y-axis.