Interface for geometry functions.
#include "SageDefines.h"
◆ AngleToVector()
| const Vector2 Sage::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.
◆ Normalize() [1/2]
| void Sage::Normalize |
( |
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. |
◆ Normalize() [2/2]
The DirectXTK doesn't have a function that returns a normalized vector, so here it is. We will now be able to use it in constant declarations, for example, const Vector2 u = v.Normalize().
- Template Parameters
-
| t | Vector type, typically Vector2 or Vector3. |
- Parameters
-
- Returns
- A unit vector that points in the direction of v.
◆ ParallelComponent()
| Vector2 Sage::ParallelComponent |
( |
const Vector2 & | v0, |
|
|
const Vector2 & | v1 ) |
Find the component of one vector parallel to another.
- Parameters
-
| v0 | Vector whose component we want. |
| v1 | Vector that the component must be parallel to. |
- Returns
- Component of v0 that is parallel to v1.
◆ Rotate() [1/2]
| const Vector2 Sage::Rotate |
( |
const Vector2 & | v, |
|
|
const float | a ) |
Rotate a vector about the Origin.
- Parameters
-
| v | Vector to be rotated. |
| a | Angle to rotate by, counterclockwise, in radians. |
- Returns
- The vector rotated by the angle.
◆ Rotate() [2/2]
| const Vector2 Sage::Rotate |
( |
const Vector2 & | u, |
|
|
const Vector2 & | v, |
|
|
const float | a ) |
Rotate a vector about a point.
- Parameters
-
| u | Vector to be rotated. |
| v | Center of rotation. |
| a | Angle to rotate by, counterclockwise, in radians. |
- Returns
- The vector rotated by the angle about the center of rotation.
◆ VectorNormalCC()
| const Vector2 Sage::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.
◆ VectorToAngle()
| const float Sage::VectorToAngle |
( |
const Vector2 & | v | ) |
|
Compute the angle to a vector measured in radians counterclockwise from the positive X-axis. Suppose \(\theta\) is the angle between a vector \(\vec{v} = [v_x, v_y]\) and the positive X-axis (see the image below). Then \(\tan \theta = v_y/v_x\), that is, \(\theta = \arctan v_y/v_x\).
Notice that we use function atan2f(v.y, v.x) instead of atanf(v.y/v.x) to compute the arc tangent because atanf returns an angle in the first quadrant, that is, \([0, \pi/2]\). For example, atanf(-1/-1) is atanf(1), which returns \(\pi/4\), whereas atan2(-1, -1) returns the correct result, \(-3\pi/4\).
- Parameters
-
- Returns
- The angle to that vector.