
Gamedev Tutorial: Trigonometry Basics – Sine and Cosine - mariuz
http://allenchou.net/2019/08/trigonometry-basics-sine-cosine/
======
bayesian_horse
I can remember that I was introduced to sine and cosine through game
programming before it was discussed in school.

Particularly I was trying to make games with Pascal and Assembly on an 80386.
Asphyxia tutorials. No Stack Overflow, no Khan Academy, Wikipedia, in fact no
Internet or even BBS at all. I feel nostalgic towards this time, but I guess
that those feelings are more attached to the curiosity of an analog child
being introduced to the digital magic.

~~~
Sharlin
I remember playing around with these weird sin and cos functions whose return
values seemed to lack any readily discernible pattern. After some
experimenting I ended up plotting something like

    
    
      x=a*sin(t)
      y=a*cos(t)
    

and was delighted to realize that the coordinates traced the arc of a circle!
Not a long time earlier I had wondered how to write a program that displays an
analog clock… The connection to right-angled triangles was revealed to me only
later, although in retrospect they are obviously two sides of the same coin.

~~~
cellular
I made a whiteboard robot to teach/experiment those equations. It's fun to
fill a whiteboard with patterns and let people wonder how they were made:
[https://sites.google.com/view/wbr](https://sites.google.com/view/wbr)

------
punchclockhero
Looks we need more game development in schools, as it's the most math heavy
thing close to modern kids' lives.

~~~
bayesian_horse
Definitively, but it's hard to bring teachers up to speed. For one thing they
often lack the particular curiosity, which may be associated to choosing the
teaching path (unfortunately).

And I suspect it's also dangerous to teach coding to teachers: It's a skill
that can land them much more lucrative and less stressful jobs.

~~~
dorkwood
What’s an example of a non-stressful programmer role? Asking for a friend.

~~~
pfranz
The tricky part about teaching is that it's unbounded.

I've never taught, but I remember transitioning from school to a job and it
was a huge thing for me that I could keep work at work and I could start
focusing on things outside without distraction. For friends that teach there's
a lot of work that's expected that's not scheduled work hours (grading, lesson
planning, etc). Dealing with parents is one of the largest stressors and
that's almost exclusively outside of classroom time.

~~~
bayesian_horse
Depending on the particular school system, teachers can often shut out or
minimize out-of-class work, but it takes a tougher attitude than many teachers
have.

Also, many teachers don't think "no parent engagement" is more desirable than
high parent engagement. Differences in the parents ability to engage the
school (available time, money, language skills etc) contributes to social and
ethnic disadvantages in many nations' school systems.

~~~
pfranz
I was mostly pointing to the out-of-class work as something people who work
other jobs wouldn't expect. I don't think there's a scenario where it doesn't
exist and I'm a bit surprised I don't see better guidelines from either school
districts or teacher's unions. It's something teacher's need to figure out for
themselves. Trying to minimize that time was obvious to me as a student when I
had poor teachers. Planning periods and planning days are nowhere near
adequate to cover their responsibilities.

> Also, many teachers don't think "no parent engagement" is more desirable
> than high parent engagement.

I've never heard a teacher argue for no engagement. My point was that parent
engagement is inevitable and always outside of scheduled class time. It's also
one of the top complaints (along with administration and mandatory testing),
so it's doubly unfortunate its unbounded.

~~~
bayesian_horse
My teachers would have shut down any parent without an extremely urgent issue
trying to contact them after hours.

And I highly doubt that they got above a 40 hour work week including their
lesson preparation.

But I guess expectations and regulations vary and it takes a personal strength
that shouldn't be required of teachers. It's doubly sad that school systems
are increasingly relying on teachers giving in and carrying more than their
contractual burden.

------
JoeAltmaier
Yikes! I use vector math (dot and cross products) to do all my game physics.
Far fewer operations (two multiplies, and add, sometimes a divide). All the
singularity issues were in one place, and meant something special each time,
so could be dealt with in an orderly way. And could be all fixed-point or
integer, no need for floating point at all.

~~~
jacobolus
Yes, trigonometry should be avoided whenever possible (which is much more than
people often expect) in favor of vector methods in pretty much every context.

If someone wants a single number for representing a rotation, consider using
the stereographic projection (instead of angle measure), which takes only 1
division to go back and forth to cartesian coordinates.

Floating point is fine for modern hardware though.

------
tuzemec
I enjoyed the Coding Math series a lot:
[https://www.youtube.com/watch?v=zm9bqSSiIdo](https://www.youtube.com/watch?v=zm9bqSSiIdo)

Here's the trigonometry playlist:
[https://www.youtube.com/watch?v=yAHl_kpqr-k&list=PL7wAPgl1JV...](https://www.youtube.com/watch?v=yAHl_kpqr-k&list=PL7wAPgl1JVvWixFXjWgbulBg9_7Loc13h)

------
harel
This is great. I always had bad math teachers, so my math is like my French:
Tre mal. This here is the first time I actually understood sin/cos. Thank you.

~~~
peignoir
It’s “Très mauvais” :) But I agree and would love to see more work done to
take advantage of animations to teach math concept (e.g 2blue1brown) game is
also cool especially with unity (cf on YouTube : codeadventure)

~~~
harel
Thanks.

My french is bad... Which is made even worst as I'm a French national...

------
nullifidian
Up next: Arithmetic for game developers.

~~~
codesushi42
Vector arithmetic would certainly be useful.

~~~
maccard
2007 has you covered: [http://blog.wolfire.com/2009/07/linear-algebra-for-
game-deve...](http://blog.wolfire.com/2009/07/linear-algebra-for-game-
developers-part-1/)

------
nineteen999
You can use sin/cos to drive leg animations procedurally. This works
particularly well with things like arachnids.

Use one value to drive the forward/backwards motion of the leg. Use the other
to drive the up/ down motion of the leg, although you want to clamp the range
from 0.0 to 1.0 so the foot doesn't clip under the floor (although you could
use realtime inverse kinematics to prevent that as well, in a game engine with
reasonable IK support such as UE4).

You'll also need to negate the values for the leg on the opposing side of the
body, and keep flipping those values for each pair from front to back (ie. the
third pair matches the first pair, the fourth pair matches the second pair).

See
[https://www.youtube.com/watch?v=GtHzpX0FCFY](https://www.youtube.com/watch?v=GtHzpX0FCFY)
for an example of a (hand) animated spider gait.

------
croh
[https://www.youtube.com/watch?v=r18Gi8lSkfM](https://www.youtube.com/watch?v=r18Gi8lSkfM)

~~~
pdm55
beautiful graphics ... thx for link .... helped my understanding of Fourier
Transforms

------
mekane8
Very nice visualizations. I used to build lots of little game-type simulations
like this and I remember working my way through a very similar progression as
I figured out how to draw circles and position things based on angles.

This summary was a nice refresher for me but if I were just learning it (i.e.
looking for a tutorial) I would probably want more in-depth explanation along
the way.

------
filleokus
Even though I'm not really in the target audience for this, pretty good grasp
on trigonometry and not really into making games, it was an excellent read!

If the author is reading this: Try removing the controls attribute on the
videos and see if you like it better that way, I think I would (since they are
so short and looping they are just distracting from the great animations)

~~~
xgulfie
No controls means if autoplay is blocked they will never start though

~~~
filleokus
Aah, my bad

------
Sohcahtoa82
Oh hey my username is relevant.

I've always thought Trigonometry is taught poorly in our high schools. I've
frequently seen people see the animation showing the dot going around the
circle while graphing the X and Y values and suddenly having everything
"click" for them, and question why that animation wasn't shown to them in high
school.

------
hnarn
There's a typo in your post where some HTML has snuck into a code block:

> &amp;lt;

I'd recommend searching for more of them :)

