Sin & Cos: The Programmer's Pals!

102 bookmarks. First posted by gnaritas march 2008.

This article will explain sine, cosine, vectors, atan2, and some useful special effects such as how to make homing missiles and how bitmap rotation works.
gamedev  programming  trigonometry  math  sine  cosine
march 2018 by jakobb
In this article I shall discuss several game programming techniques, all revolving around a central theme: the sine and cosine functions.
programming  math  development  gamedev  games  algo  via:popular
march 2018 by jonlabelle
Okay, so now we know there are two ways to store a vector - with polar coordinates and with Cartesian coordinates - and that in this case they both have their advantages. So which one do we actually use? Well, it wouldn't be a big problem if we knew a way to calculate the angle and speed from the x- and y-coordinates, and vice versa.

And I wouldn't be writing this article if that wasn't possible!

First I'll talk about converting from polar to Cartesian coordinates. It is, of course, also possible to convert the other way, but I will talk about that later on.

There are two functions available to us to accomplish this. These functions are sine and cosine (sin and cos). Whoa! You didn't see that coming, did you?

The sine can be used to calculate the y-coordinate of a vector, and the cosine can be used to calculate the x-coordinate. (Sometimes you see this the other way round, and one or both coordinate values may be negated. I encourage you to think about the effect this would have when you have learned more about the functions.) The sin() and cos() functions take only one parameter: the angle. They return a number between -1 and 1. If you multiply this number by the length of the vector, you will get the exact Cartesian coordinates of the vector. So your code will look like this:

speed_x = speed_length * cos (speed_angle);
speed_y = speed_length * sin (speed_angle);
So that's it: for a racing game you just store the angle and the length of the velocity vector. You adjust these according to the player's input, and you calculate the x- and y-coordinates when you are ready to update the position of the racing car.
games  algorithm  engineering
march 2018 by janpeuker
fixed point math mentioned
Allegro library
arduino
march 2018 by synergyfactor
Sine & Cosine coded in C.
development
march 2018 by snafubar
HelixSoft Home Follow me on twitter! @mpvaniersel amarillion@yahoo.com Introduction In this article I shall discuss several game programming techniques, all…
from instapaper
march 2018 by alexdunae
Sin and Cos: The Programmer's Pals
math  programming
march 2018 by jasonlong
HelixSoft Home Follow me on twitter! @mpvaniersel amarillion@yahoo.com Introduction In this article I shall discuss several game programming techniques, all…
from instapaper
march 2018 by peterwhelan
Sin & Cos: The Programmer's Pals! amarillion@yahoo.com Introduction In this article I shall discuss several game programming techniques, all revolving around a central theme: the sine and cosine functions. This article will explain sine, cosine, vectors, atan2, and some useful special effects suc
gamedev  geometry
october 2014 by umrain
Learn how to program some gaming algorithms.
coding  development  games  game  programming  code
february 2011 by jbydesign
In this article I shall discuss several game programming techniques, all revolving around a central theme: the sine and cosine functions. This article will explain sine, cosine, vectors, atan2, and some useful special effects such as how to make homing missiles and how bitmap rotation works.
article  gamedev  math  programming  sine  cosine  3d  graphics
february 2011 by raphman
In this article I set out to answer some of the most common questions on sine and cosine, or trigonometry in general. I could give you a more mathematical explanation of sine and cosine, but I wanted this article to be of practical use to game programmers, especially to Allegro game programmers, not to give an encyclopedic description of abstract mathematics.
math  programming
february 2011 by joshcarter
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://pinboard.in/url:2972b99553d52fddbc54ba860e054bdc2d3d8322", "fetch_time": 1529523302000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2018-26/segments/1529267863834.46/warc/CC-MAIN-20180620182802-20180620202802-00162.warc.gz", "warc_record_offset": 689585420, "warc_record_length": 9144, "token_count": 953, "char_count": 4111, "score": 4.15625, "int_score": 4, "crawl": "CC-MAIN-2018-26", "snapshot_type": "latest", "language": "en", "language_score": 0.9112316370010376, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00012-of-00064.parquet"}