4. Sinewaves

Brackeys video: Sinewaves

Sine and cosine

  • Script reference: Mathf.Sin
  • and are oscillating functions that return a value between and
    • here, is an angle measured in radians (rad).
  • Their form is the same, but is shifted from by rad:

Degrees vs. radians

xx

Sin & Cos triangle definition

xx

Circular motion

xx

Extra: Polar coordinates

Code example

double phi = Mathf.pi/2;
double r = 5.0f;

Vector2 vec = new Vector2(
    r * Mathf.Cos(phi),
    r * Mathf.Sin(phi)
);

From cartesian ( and ) to polar coordinates ( and )

  • What about the other way around?

  • In code:
    Vector2 vec = new Vector2(4.0f, 2,0f);
    
    double r = vec.Magnitude;
    double phi = Mathf.Atan2(vec.y, vec.x);