Code for helper functions.
More...
◆ AngleToVector()
const Vector2 AngleToVector |
( |
const float |
theta | ) |
|
Compute a unit vector at an angle measured in radians counterclockwise from the positive X-axis. If \(\vec{v} = [v_x, v_y]\) is a unit vector with tail at the Origin and \(\theta\) is the angle between \(\vec{v}\) and the positive X-axis, then \(\sin \theta = v_y\) and \(\cos \theta = v_x\). Hence, \(\vec{v} = [\cos \theta, \sin \theta]\), as shown below. Therefore, this function returns Vector2(cosf(theta), sinf(theta))
.
- Parameters
-
- Returns
- Unit vector at angle theta counterclockwise from positive X.
◆ NormalizeAngle()
void NormalizeAngle |
( |
float & |
theta | ) |
|
Normalize an angle in radians to \(\pm\pi\). If the angle is very large or very small, then this function will be very slow. However, it will be very fast if the angle is not too far out of range.
- Parameters
-
theta | [in, out] An angle in radians. |
◆ VectorNormalCC()
const Vector2 VectorNormalCC |
( |
const Vector2 & |
v | ) |
|
Compute the counterclockwise unit perpendicular to a vector. If \(\vec{v} = [v_x, v_y]\), then both dot products \(\vec{v} \cdot [-v_y, v_x]\) and \(\vec{v} \cdot [v_y, -v_x]\) are equal to zero, and therefore both \([-v_y, v_x]\) and \([v_y, -v_x]\) are perpendicular to \(\vec{v}\). The former (drawn in green below) points counterclockwise from \(\vec{v}\) and the latter (drawn in purple below) points clockwise from \(\vec{v}\). Therefore, this function computes Vector2(-v.y, v.x)
and normalizes it before returning it.
- Parameters
-
v | A vector, not necessarily normalized. |
- Returns
- The counterclockwise unit perpendicular to v.