PDA

View Full Version : Math Lesson Request: Sin and Cos?

 Mooncalf01-29-2004, 01:10 AMHi y'all, So I was going through the Auto-Breathe tutorial over at kiaran.net Everything works fine, but I'm not content just to see that it DOES work; I want to know WHY. To put it briefly, the whole auto-breathe is controlled by an expression that looks like this: mouthControl.breatheIn=abs(sin(time*mouthControl.frequency))*mouthControl.depth; I'm sure this is pretty basic fare. And I understand what it's doing, for the most part. But I'm having trouble visualizing how the sin works. I vaguely remember sin and cos and tan from 10th grade, but that was a long time ago. I know it's a wave...I'd like to know a few things: a) Exactly the value it is multiplying the rest of the equation by? (I recognize it is not a constant value) Is there a way to visually represent this for me to understand? b) I tried replacing sin with cos and got a nearly identical result. I say "nearly" because I couldn't tel the difference, though I'm sure there is one. What IS the difference? And what would be an example where I would use cos instead of sin? c) How about tan? Is that a totally other kind of equation? (replacing "sin" with "tan" had some interesting results) Any help understanding would be appreciated... as I appreciate your patience with my learning curve. :) - M
verbal007
01-29-2004, 01:28 AM
Just test it out. Basically it creates in infinite cycle. Soo... as you feed it numbers, lets say, 1 through 100, it will return a value that will smoothly cycle up and down from 1 to -1 (I think). I would draw a rough graph for ya, but it wouldn't be very accurate and might just confuse ya later down the line.

But that's basically how it's being used here.

Play around with it in a simple... *few minutes later* Run this and look at the results. You'll see what I mean.

float \$n;
float \$res;
for (\$n = 1; \$n < 100; \$n++) {
\$res = (sin(\$n));
print(\$res+"...\n");
}
print("sweet eh?");

Funny you posted this, because I've been looking around for a good/cheap trig book to study from.

- J

Mooncalf
01-29-2004, 01:49 AM
Hey J,

I found this link earlier today:

http://www.ies.co.jp/math/java/samples/graphSinX.html

If you click "draw" then use the + and - buttons, it gives a really good indication of why the sin falls on he graph the way it does.

(and if you're looking for other trig stuff, the /math root of that link might interest you)

So then, sin will never EVER be >1 and never EVER be <-1 ? Is that right?

I'm still interested in how cos differs. (that site had a cos graph, too, but it looked like the same wave on a different axis--and I don't think the axis is what makes cos different)

- M

zachgrachan
01-29-2004, 01:49 AM
sin is a simple up and down wave from -1 to 1 to -1 to 1.... cos is the same wave only phase shifted by half, which means that where sin is up, cos is down and where sin is down, cos is up. tan is a rather different wave. more info here:
http://www.gcseguide.co.uk/sin,_cos,_tan.htm

Mooncalf
01-29-2004, 02:09 AM
Thanks Zach,

Yeah, that tangent graph definitely looks like what happened when I put it into the equation.

So, if sin and cos are the same except (I hope I have these terms right), the crests are reversed, then would I be right in assuming that the only difference sin and cos make in an equation is if you care where the wave begins? (say, if you wanted a light to start blinking on/off/on/off instead of off/on/off/on?)

- M

zachgrachan
01-29-2004, 03:57 PM
yep, that would be it. the only other difference would be when using them for actual trig/geometry calculations. in that situation the difference is that sin is the opposite/hypotenuse and cos is the adjacent/hypotenuse. but that's a whole different can of worms...

Mooncalf
01-29-2004, 04:15 PM
Thanks again, Zach.... I'll stay away from other worm cans for now. ;)

One final question, then:

It appears to me as if the sin cycle is constant and the effects are altered only when it is multiplied by other numbers.
Is that how it works?

That is:
Does sin (and cos, for that matter) always cycle at the exact same rate?

- M

ajk48n
01-29-2004, 09:52 PM
The sin and cos cycles are constant. They will always go smoothly from -1 to 1 and back again. To change this, such as the variables in you equation did, you can do a few things.

The most basic way sin (or cosine) is usd is with time:

sin(time);

This result is what gives you a the transition form -1 to 1, since time is constantly getting bigger, and making the result constantly move.

If you multiply time by anything, you change the time it takes for sin to cycle.

sin(time*5) will cycle faster.

If you add something to time, you offset the atarting point.

sin(time + 5) will have a different starting point.

If you multiply everything by a number, your results will be scaled accordingly.

5 * sin(time) will give you a range from -5 to 5.

Adding something to everything will offset the result.

5 + sin(time) will give you a range of 4 to 6

One final note ot confuse things a bit. In Maya there are two different sine and cosine commands. One is "sin", while ther other is "sind".

"Sin" works with radians, and "sind" works with degrees. If you have no idea what that means, that's allright, since it doesn't matter for understanding how the variables work. If you want more explanation on that, one of the sites that was in this thread probalby has it, or just ask.

I hope this helps, and isn't too confusing.

Mooncalf
01-30-2004, 03:47 AM
ajk48n:

Wow. What a wonderful, straight-forward, easy-to-understand explanation. Thanks sooo much! :)

I think the whole thing is a lot clearer to me now. (but I won't ask about sind at the moment)

I can now nearly visualize the graph in my head, altered by any number of variables.

I'm definitely bookmarking this thread to come back to reference time and again.

Thanks, everyone, for your patience and tutelage!

- M

CGTalk Moderation
01-17-2006, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.