Draw an elliptical sine wave
I'd like to write a program that draws sine waves that are based on ellipses instead of circles. I'm strong in math but my actual background is quite weak. Does anyone know if there's a topic in math that deals with this? Any code? All help will be appreciated
What you want is the polar equations of an elipse:
A] If the pole of the elipse is the centre then
r*r = (b*b)/(1 - (e*e*Cosy*Cosy))
r = radius length from centre to point on elipse
b = semi minor axis ie half width of narrowest width of elipse
e = eulers number
y = angle from positive x-axis to radius r
(NB couldn't figure out how to do square of a number)
B] If pole is at one focus of the elipse
r = (b*b)/(a(1 + e*Cosy))
r = radius from one focus
b as above
a = semi major axis ie half longest dimenson
e as above
y as above.
Just pop this in your toaster :-)
WINDOW 1 A! = 30 'minor axis B! = 50 'major axis CALL MOVETO(100+B!,100) FOR t=0 TO 360 y! = A! * SIN(t*3.14/180)+100 x! = B! * COS(t*3.14/180)+100 CALL LINETO (x!,y!) NEXT DO HANDLEEVENTS UNTIL 0
here is a solution that correctly works for angles 0 < phi < pi:
y = a * b * SQRT( TAN(phi) * TAN(phi) / ( a * a * TAN(phi) * TAN(phi) + b * b ))
where a and b are the principal axes of the ellipse. For angles pi < phi < 2*pi, y is negative and so on...
What you get is no longer a harmonic function. Actually it is a distorted sine-wave and I am sure it is quite easy to determine the Fourier coefficients and thus the distortion!
It looks like an interesting exercise. An ellipse can be expressed by the formula
(x/a)^2 + (y/b)^2 = 1 where a is the value of x when y = 0, and b is the height when x = 0.
so any point y on the curve can be represented by
y = b*((a^2 - x^2)/a^2)^.5
Thus at point x, the tangent of the angle from the origin to the point where x intersects the curve can be expressed by y/x.
If I have done the arithmetic right, that comes down to:
sine of angle = b*(1/x^2 - 1/a^2)^.5
Just keep x between -a and +a. Both will give you the same answer since they are both squared, but at least you won't be trying to take the square root of a negative number as would be the case with higher numbers.
Thanks to everyone who replied to my request for information about how to draw an elliptical sine wave. It was nice to have a number of alternate solutions. I haven't tested any of the ideas yet but hope to get on the project soon. I just have a couple of follow-up comments and questions.
I'm taking a course which requires me to analyse a natural system and look for periodicity. Everyone tends to look for evenly spaced wave peaks in natural systems, but to my knowledge nature uses ellipses as often as it uses circles (e.g. orbits of planets and electrons). So I hope to get a good sense of what an elliptical wave looks like and be able to eyeball one in my graphical data. It may not work, but will at the very least be interesting.
Herbie, your solution is much appreciated, but now I'm at a loss—where would I look to get information on how to determine the Fourier coefficients? Also is there some place I could look to learn more about the solution that you gave me? I'm sure I could learn all this reasonably quickly, but the world of higher mathematics is unfamiliar to me and I have little idea of the basic topics and references.
There's a great book on Fourier Analysis called "Who is Fourier? published by the Transnational College of LEX. Found my copy at Border's.
Try the Discrete Fourier Transform Page: