PDA

View Full Version : Need some help with waves

Felipe Ruiz
05-01-2010, 10:32 PM
Hi there all!

One of my teachers asked my class to do some standing waves thing using openGL, GLUT and GLUI. Well, I managed to do the waves just fine but they're not how the teacher wants them. He said he wants something like this: Harmonics (http://id.mind.net/~zona/mstm/physics/waves/standingWaves/standingWaves2/StandingWaves2.html)
Which means the waves are open at both ends.

Sadly, all I get is this:
http://img36.imageshack.us/img36/8708/harmonics.jpg

I've done some math and found out that the only way to make the waves open is if I move the even harmonics a bit to the side. The only issue with that is they don't get aligned. Any ideas on how to make them aligned, whitout making the even harmonics being closed?

Y-tension
05-02-2010, 07:56 AM
You have made moving waves which means each point at x has a y value of sin(x - ft) (Actually this wave moves to the right) where f; is the frequency of the wave, k is the wave number. To produce standing waves you have to add two waves, one moving to the right(sin(kx - ft)) and one moving to the left(sin(kx + ft)). Now what happens is that the two waves will counter each other, producing points where there is no movement at all, called nodes. So, sin(kx - ft) + sin(kx + ft) = sin(kx)cos(ft) - sin(ft)cos(kx) + sin(kx)cos(ft) + sin(ft)cos(kx) = 2sin(kx)cos(ft).
Immediately you can see that at x = 2(pi)n/k where n is integer the amplitude of the wave is zero(node). Now, to 'align' the two ends(Actually what you want is to make one the opposite of the other, if you want to make them like they are in the video), you have to make their kx values differ by n(pi); where n is an odd integer so all in all what you need to do is:
1)y is calculated by y = 2sin(kx)cos(ft). You can substitute 2 with any amplitude value you like, of course.
2)Make sure that the vertex at the center of your screen has a y value calculated at a node point x = 2(pi)n/k (x = 0 is the simplest case)
3)Make the endpoint vertices so that their kx values always differ by n(pi); where n is an odd integer(1 is the simplest case but you can try higher numbers to see more periods of the wave) and linearly interpolate the x values of the vertices in between.

I hope it helps. I'm not going to say any more because this is supposed to be a project, right?

Felipe Ruiz
05-02-2010, 06:57 PM
I already had the waves figured out, my isssue is that some of the waves would always be fixed at the outer points. But I already figured out how to fix it. All I needed to do was calculate (x,y) and then do glVertex2d(x-waveLength/4,y).
Thanks anyways