Computer Science Canada Elliptical Path |
Author: | whoareyou [ Fri Mar 09, 2012 9:43 pm ] | ||
Post subject: | Elliptical Path | ||
I'm trying to have a basic circle follow in a circular path around the console window. However, the console window isn't a perfect square, so an elliptical path makes more sense. Before I can implement the PATH, I need to first understand how to draw an actual ellipse. I'm trying to follow the formulas found on the Wikipedia site for an Ellipse: Link: http://en.wikipedia.org/wiki/Ellipse#General_parametric_form When I implemented this in my Java program, it produced this image: This path, draw in the black, goes off of the console window, and I'm trying to make the x and y coordinates so that I can use it with a different object (perhaps a rectangle following an elliptical path across the console window). I want the path to look like the ellipse in RED, but everything I do doesn't seem to work. Any suggestions?
|
Author: | whoareyou [ Fri Mar 09, 2012 9:58 pm ] |
Post subject: | RE:Elliptical Path |
Never mind, I figured out the problem, although I don't know why it worked ... What do "a" and "b" represent in the equation? They had to be switched to make the right shape? I though "a" was the major axis, which would've been the c.maxx() and "b" would be the c.maxy(). I'm confused. |
Author: | Raknarg [ Fri Mar 09, 2012 10:48 pm ] |
Post subject: | RE:Elliptical Path |
My guess would be the radius of the ellipse. (a for x radius, b for y radius) |
Author: | Zren [ Fri Mar 09, 2012 11:30 pm ] | ||||
Post subject: | RE:Elliptical Path | ||||
Ellipses are basically just squished circles. A circle uses: x = cos(ang) // -1 .. 1 y = sin(ang) // -1 .. 1 Normally we scale both variables by the same amount to retain a circle. For an ellipse, just change it to xRadius and yRadius. Circle: x = radius * cos(ang) y = radius * sin(ang) Ellipse: x = xRadius * cos(ang) y = yRadius * sin(ang) The rest is just necessary translation. I have no idea what that formula does however. Edit: Okay I may be pulling a lot of shit out of my ass due to my lack of education in this (matrixes and polar), but I think the formulas you posted combine itself with the rotation matrix. Why I think it's rotation. [url]http://en.wikipedia.org/wiki/Rotation_(mathematics)[/url] <-- I hate you too compsci
So basically it's:
|
Author: | Dreadnought [ Sat Mar 10, 2012 1:35 am ] |
Post subject: | Re: Elliptical Path |
The value 'a' is in fact the major axis of the ellipse and 'b' would be the axis perpendicular to the major axis. The reason you had to swap their values to obtain the proper shape is, as Zren explained, because you have rotated your ellipse 90 degrees, effectively placing the major axis along the y axis. |
Author: | whoareyou [ Sat Mar 10, 2012 2:35 pm ] |
Post subject: | RE:Elliptical Path |
Thanks very much Zren and Dreadnought! I understand my mistake now! |