I really suck at math, I admit it. Can someone please show me an equation for generating a sine wave? :rolleyes:
Printable View
I really suck at math, I admit it. Can someone please show me an equation for generating a sine wave? :rolleyes:
Wow. Math is wierd. :) So I just try this random equation and though it doesn't give me a sine wave, it creates fascinating patterns. If you run Windows try it out:
Some interesting frequencies to try are 16, 11, 22, 400, 98, 99, 77, 3.1, 3.14, to name just a few.
[edit] oops...the equation:
y = amplitude * sin(frequency * x);
..."frequency" is just a name for the variable. I have no idea what it truly represents. :p
BTW: Is there a formal name for this equation?
[edit]
I have posted a newer version at the bottom of this page.
Please try it out. :)
[/edit]
Looks good, sorry I didn't see the question earlier I could have actually answered it. Oh well.
Well, actually, I don't think it's the basic sine-wave equation (though it seems to generate them as a side-effect). Do you know that one?
It depends upon what you are using for 'x'. Could you post your source or something?
It's just the x coord.
Code:void DrawEquation(double a_frequency, double an_amplitude){
double
x = 1,
y = 1,
cx = box.Left(),
cy = box.VerticalCenter(),
maxX = box.Right(),
maxY = box.Top();
BrushFill();
GetPen(box_color, 4); // ...get a 4-pixel wide pen...
DrawRectangle(box);
box.Inflate(5);
DrawRectangle(box);
box.Inflate(-5);
GetPen(line_color);
MoveTo(cx, cy);
for( ; ((x + cx) < maxX); ++x){
y = an_amplitude * sin(a_frequency * x);
y = -y;
if((y + cy) > maxY)
LineTo(x + cx, y + cy);
}
DrawText();
Invalidate();
}
The code looks sound. ANy of the side-effects you are referring to are common in all sine wave programs. You can force the user to keep their amplitude within a fixed range to avoid making the sine wave get out of control.
Interesting. Ok, thanks.
It is a discrete sine. A property of discrete sines is that they do not necessarily need to be periodic. That is why you get your patterns.Quote:
y = amplitude * sin(frequency * x);
..."frequency" is just a name for the variable. I have no idea what it truly represents.
BTW: Is there a formal name for this equation?
>..."frequency" is just a name for the variable. I have no idea what it truly represents.
The input parameter for sin is an angle in radians. You get a quarter oscillation every pi/2 radians.
In other words, if sin(0) will give you 0, sin(pi/2) will give you +1, sin(pi) gives you 0 and sin(3pi/2) gives you -1.
Therefore if you wanted your sine wave to render a quarter osicallation every 100 pixels, you would calculate your frequency to be:
f = pi / 100 / 2
so that you would get a complete oscillation every 400 pixels along the x-axis. In otherwords, you frequency is expressed as oscillations per 400 pixels.
You may also want to extend your equation with x/y offsets to give you positioning control over the sine wave. I.e.
y = yoffset + (amp*sin(f* (x + xoffset)))
>It is a discrete sine. A property of discrete sines is that they do not necessarily need to be periodic. That is why you get your patterns.
I've no idea what this means. As far as I am aware it's just an equation for a sine wave.
>It is a discrete sine.
Just tried the program. I see what is meant by discrete now. It is rendered it in discrete steps.
>I've no idea what this means. As far as I am aware it's just an
>equation for a sine wave.
Sebastiani used the equation to calculate numbers for certain values of x, he probably used a loop to let x vary from a start value to an end value and found patterns in the output which were not sine waves. This is because the sine equation is discrete, a computer can't work with continue signals, only with discrete signals. The output Sebastiani has seen is the output of a discrete sine.
At the risk of sounding pedantic, I beg to differ.
>This is because the sine equation is discrete
The equation is not discrete. However, the algorithm Sebastiani uses to render the wave is. There is a subtle difference.
I really appreciate your input, Davros, Shiro. And Davros, thank you for the informative equations. I will try them out.
I don't understand. Does this mean that if I were to output the equation on an ocillascope the pattern would be different?Quote:
Sebastiani used the equation to calculate numbers for certain values of x, he probably used a loop to let x vary from a start value to an end value and found patterns in the output which were not sine waves. This is because the sine equation is discrete, a computer can't work with continue signals, only with discrete signals. The output Sebastiani has seen is the output of a discrete sine.
Thank you so much. It works beautifully now.
Ok, swell. I've corrected the original equation, added some fine-tuning control over it, and animated it to boot. :) Not a bad little proggie, actually.
Oh, and thanks again to all the math geeks who helped me out. :D
- cheers.
I never thought I'd get to show this proggie off, but this is an appropriate place. I did it when we were talking about electro magnetic radiation in chemistry.
oh and sebastanti your program just closes when I go to run it so I have no clue what you actually did in your program
here is a second version i just made. I'll give 20 bucks to anyone who can look at it for 20 mins without barfing.
Interesting. But what is it? :p It sort of looks like one of those hippie "trip" movies you're supposed to watch on LSD. :D
So, did anyone else have trouble running my program?
>> here is a second version i just made. I'll give 20 bucks to anyone who can look at it for 20 mins without barfing. <<
I'm a bit disappointed. I could do 20 minutes...er--I mean did 20 minutes where's my money :p
[edit]
Btw, you program looks much nicer Sabastiani.
[/edit]
yeah your program looks pretty cool, it took me forever to figure out how to change the things in the textbox lol
would mine be better if you could change the amplitutde, wavelength, frequency, sleeptime, etc in my prog?
I have a question, what exactly is the 'res' and what did you use sebastiani (windows GDI?) for the waves.
I actually watched the your animation for some time. Interesting patterns. And sure, it'd be cool if you could tinker with the settings. So what did you use to code it in and what are the algo's based on?
I used straight Win32, no DX or anything, but luckily I could make use of a C++ library I've been working on, which was rewarding.
'Rez' is just the relative resolution, or how often the calculation is performed, with 1 (pixel) being the highest resolution. Interesting effect when you set rez, amp, and freq to the same values, too.
I really suck at math and that's what I appreciate about the program, is that I do enjoy tangible applications of mathematical principles...anyway, I would like it to eventually parse equations and add some other features too. Let me know if you have any suggestions.
just win32api and opengl.Quote:
So what did you use to code it in and what are the algo's based on?
The equations used in both our apps are almost exactly the same, except with mine they are all hard coded into the program. Color (which is randomly assigned each frame creating seizure causing flashing),and length of the spiral are also hard coded into the program. The biggest difference between the apps is that in mine both the horizontal and vertical movement is controlled by sine waves as a function of time, and it moves over the z axis causing the spiral effects (this should be familiar to people who have played quake II/III because the railgun uses a similar spiral except I think the amplitude decreases as z increases). Yours is better because you can actually interact with it, mine is just like a screensaver.
ohhhhh boy there are so many cool things you can draw with equations. Here's something I did using inverse power models, i.eQuote:
applications of mathematical principles...anyway, I would like it to eventually parse equations and add some other features too. Let me know if you have any suggestions.
y = 'size' / x^power
i.e in this attached proggie it's
25/time^2; for the first
and 50/time^2 for the second
the second is farther away and they are both connected by lines in my program
if you have a ti83 graph the following :
y1 = 5 /x
y2= -5 / x
y3 = 1 / x
y4 = -1/x
y5 = 5 / x^2
y6 = -5 / x^2
that should give you a good idea
and also my math teacher was explaning how to use the polarity mode on the ti 83 to produce spirals, ill find more about that next school week
here is that prog that demonstrates inverse powermodel usage, again everything is hard coded into the program, however you can use the following keys to move around
left arrow, right arrow, up arrow, down arrow
if the view gets too screwed up press r to reset the view
here is that file
EDIT: I changed the equation to y = size / time instead of raising it to any power (it looks better this way). so now im not sure what you call it (model of inverse variation?) but it's no longer an inverse power model because I'm not raising anything to any powers.
yeah...
Ok, thanks. I'll post a parsing version sometime next week that will allow equations like these. Also, a grid might be nice, and I need to save settings in the next version too. I wonder how hard z-order implementation would be? I'll look into it.
Thanks for all of the input.
>ohhhhh boy there are so many cool things you can draw with
>equations.
I totally agree. Just take a look at fractals. For example, the Mandelbrot set:
http://www.olympus.net/personal/dewey/mandelbrot.html
Cool site. Have you heard of the 'archimedes spiral' or something like that? You draw it by setting your ti 83 to radian mode, then instead of 'func' set it to 'pol' which means polarity. Then you do the sine/cosines of theta (I think that's what it is) and it creates spirals that seem to somewhat resemble those fractals. I might be describing that process a little inaccurately, but chances are if you're in or passed college you've already done it and know what I really mean :) I'm dumb!Quote:
Originally posted by Shiro
[B
I totally agree. Just take a look at fractals. For example, the Mandelbrot set:
http://www.olympus.net/personal/dewey/mandelbrot.html [/B]