θ (Theta) is the number you pass to math.sin
/ math.cos
. Then from there you can follow the illustration to figure out other things.
true. I couldn’t get a thing. Very true
Noice ! I learned that before learn it in school
Well, theta (θ
) is the angle you pass to the function, in radians. The lines (annotated with things like “cos” and “sin”) are the values you get out of it. ie calling math.cos(angle)
gives you the blue line.
The center of the circle is 0, positive values are up/right, negative is down/left. The circle has a radius of 1.
I definitely think you need some knowledge before to understand cosine and sine, but
this explain everything easier and more understandble then most video out on the internet.
I love sin, it’s like one of my favorite math functions of all time.
It’s SO GOOD for things like procedural animations due it’s natural and curvy behavior.
You can use it for things like head bobbing in games, leg movement, you can animate the legs of a mechsuit with it.
Almost anything can be animated using sine waves, whether it’s for making things move u and down, left and right, looping in a circle.
By stacking multiple sines onto each other with different frequencies and amplitudes, more advanced and complicated yet still natural-looking movement can be achieved.
If you’re too lazy to animate something, just slap a sin() onto it and you’re all good.
If I recall, sin(), cos() and tan() can also be used to calculating angles or something on triangles but I forgot how exactly that worked, I would greatly appreciate if someone could explain me or refresh my mind on that.
Most of these functions, particularly ones like cosecant and versine are really useless. the basic trigonometrical functions are the most useful.
SOHCAHTOA is the acronym to use:
Sine is Opposite over Hypotenuse - SOH (S = O / H)
Cosine is Adjacent over Hypotenuse - CAH (C = A / H)
Tangent is Opposite over Adjacent - TOA (T = O / A)
Now, this doesn’t really do much. How do you use it? Well, let’s say we have a right - angled triangle and want to find out the length of one side, assuming we have the measure of an angle and another side’s length. First, label the sides - the one Opposite to the angle, the Hypotenuse and the one Adjacent to the angle. Secondly, plug in the right formula and voila, all done!
For example, we want to find X.
Labelling everything, we get that X is the adjacent and that 13 is the hypotenuse. We don’t need to label the opposite since we don’t know and don’t need to find out what it is. So, looking at our formulas, we need to use cosine because we have the hypotenuse’s length and want to find out the adjacent’s length. So, the formula is Cosine is Adjacent over Hypotenuse. Rearranging, the adjacent’s length is hypotenuse’s length multiplied by the cosine of the angle. Plugging it in, we get:
x = cos(60) x 13
which is 6.5cm. Yay!
What about angles? Let’s try:
Here, the sides have been labelled for us. But when we use the right function, tan, we run into a problem. tan(x) = 5/7
is a big problem because we can’t get rid of the big tan
stuck in the way! If only we could remove it…
We can! We can use tan−1 (written as tan to the power of -1, said as “arctan”). We solve to get x = tan-1(5/7), which is 35.5 degrees! Yay!
Cosine is the exact same as sine, except offset by π/2 to the right. This is why it is known as complementary to sine.
You might notice that tan is completely different to both of these and doesn’t follow a “curve” like structure. I would steer clear of tan for animation. Just take a look at this, lol:
Sine and cosine are rather rigid too. Here are some ways to adapt them to fit your needs. First, a quick crash course on waves:
I’ll show you how to manipulate wavelength and amplitude, as well as offset.
For reference, here is the original:
- Changing the wavelength
Simply multiply the x by a coefficient.
- Changing the amplitude
All you need to do is multiply the whole function by a coefficient.
- Changing the offset on the Y axis
Just add a number on to the end of the whole function.
- Changing the offset on the X axis
Just add a number on to the end inside the sine function.
Hope this helped!
Thank you! Also dayum that name is a mouthful.
One of the reasons I want to learn how to use sin/cos/tan functions is because Roblox doesn’t have polygon objects yet and I’m figuring out how I can size and CFrame 2 wedges to form a triangle for things like procedural terrain and whatnot.
Or use them to calculate how much I have to rotate a player’s neck to make the head look at a certain point in space.
I know plenty of math, though formulas and reading certain symbols sometimes still go a bit over my head.
I love math and maybe I have a thing for it due being autistic, though I struggle with some concepts unless properly explained with simple visuals and whatnot and why X does Y or why we need Z in the equation.
Apologies, I got quite carried away…
Trigonometry is really, really useful when it’s needed.
It’s fine, I find your explanations very useful and interesting to read!
I know some basics of sine and cosine since of course I use it a lot for procedural stuff, animating things and making effects with code.
Though I have rarely applied it to trigonometry before, it’s a subject I haven’t really gotten in school before in my country.
I learn most things at home to be honest and from seeing other game developers apply it in various ways and explaining how it works.
I feel like trigonometry can also be really useful in game development, I just have rarely used it and usually find my way with look vectors for problems like making a player’s head move.
Most of the time simple CFrame math and the use of directional vectors solves the issue.
Though, maybe I can optimize code or make some functions faster and use less CPU by using trigonometry and leaving out some of the unnecessary CFrame math?
Trigonometry doesn’t come in very frequently in programming, but when it does, it is really quite useful. But realistically, you’re more likely to see things like CFrame math and Vector math over advanced trigonometrical functions. I wouldn’t stress about it, sine and cosine are really only used for bobbing and smooth curves.
Though, not sure how exactly you’d compress CFrames through trig…
Providing those in the diagram hurts no one. Was I supposed to find one that only had cos
, sin
, and tan
? Nobody’s getting confused just because the other functions are present.
No, they don’t hurt. They just aren’t needed. Just providing my take that in programming, these trigonometrical functions are generally unneeded. And according to some of the replies to your comment, it did confuse a few people…
Nonetheless, a very interesting and cool diagram. It’s always nice to find where they come from and their connection to other parts of maths like circles (who would’ve guessed, triangles are related to circles!)
Not understanding θ
will happen regardless of whether or not the other functions are included, so your point makes no sense.
Just providing my take that in programming, these trigonometrical functions are generally unneeded.
Didn’t say they were. I’ve never used anything except for sin, cos, and atan2. But seeing how all the functions relate to each other, the big picture, is extremely helpful for me, and seriously if you ever need to reach for something like even tan
, seeing how it’s built up geometrically is a huge bonus.
Your comments don’t add any value to the thread, they are Generally Unneeded.
All I said was that the other trigonometrical functions were useless. What you misinterpreted it to mean was “the other trigonometrical functions are not needed in your diagram”. Your misunderstanding of my point led to you escalating this far more than it needed to be done. I was merely providing the additional info you failed to include in your original post; that the extra ones are generally not used in programming.
Sure, it’s helpful for you, and it’s a great way to see how they come together and are derived. Not denying that.
I feel like my comments have added quite a significant amount of value to the thread, particularly this one: How to use Cos and Sin - #18 by ValtryekRBLX, whereas your primary comment confused quite a few as you didn’t really explain it. Considering that the vast majority of people who have read this post do not know that much about sin and cos, your post should’ve explained clearly what everything meant in order to provide even a small degree of educational value.
Regardless, you’ve unnecessarily stirred this up into something far greater than it should’ve been. No need to continue this rather futile argument.
to add to this post and cos and sin’s usecases:
pyseph dev a while ago made a pebble rotate a player with a lot of code
i recommended to him that it could be done with just sine and cosine on the x and z coordinates, since they are 90* out of phase
heres an example
local part = part
RunService.Heartbeat:Connect(function()
part.CFrame = script.Parent.CFrame * CFrame.new(4 * math.sin(os.clock()), 0, 4 * math.cos(os.clock()))
end)
this code makes a part orbit around another part the scripts parented to
SOH CAH TOA is a much better way of explaining sin cos and tan
Yeah, I’m not reading the rest of this post, have fun with whatever big deal you made out of this for no reason.
I’m sorry? The point was not to downplay your own explanation at all.
Muting the thread.