The Shapes Library
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
ShapeMath.h File Reference

Handy math functions for the collision module.

#include <d3d11_2.h>
#include <dxgi1_3.h>
#include <DirectXMath.h>
#include "SimpleMath.h"
Include dependency graph for ShapeMath.h:
This graph shows which files directly or indirectly include this file:

Macros

#define FailIf(x)
 

Functions

float Shapes::NormalizeAngle (float)
 Normalize angle to \([0, 2\pi)\).
 
Vector2 Shapes::Normalize (Vector2)
 Normalize a vector, ie. make it unit length.
 
Vector2 Shapes::perp (const Vector2 &)
 Perpendicular vector.
 
Vector2 Shapes::AngleToVector (const float)
 Normal vector from orientation.
 
Vector2 Shapes::RotatePt (Vector2, const Vector2 &, const float)
 Rotate point.
 
Vector2 Shapes::ParallelComponent (const Vector2 &, const Vector2 &)
 Compute parallel component of vector.
 

Macro Definition Documentation

◆ FailIf

#define FailIf ( x)
Value:
if(x)return false;

Fail by returning false if a given condition is true.

Parameters
xCondition for failure.

Function Documentation

◆ AngleToVector()

Vector2 Shapes::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
thetaAngle in radians.
Returns
Unit vector at angle theta counterclockwise from positive X.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Normalize()

Vector2 Shapes::Normalize ( Vector2 v)

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().

Parameters
vA vector.
Returns
A unit vector that points in the direction of v.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NormalizeAngle()

float Shapes::NormalizeAngle ( float a)

Normalize angle to \([0, 2\pi)\).

Parameters
aAngle in radians.
Returns
Normalized angle, that is, in the range \([0, 2\pi)\).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParallelComponent()

Vector2 Shapes::ParallelComponent ( const Vector2 & v0,
const Vector2 & v1 )

Find the component of one vector parallel to another. The component of \(\vec{v}_0\) parallel to \(\vec{v}_1\) is \((\vec{v}_0 \cdot \hat{v}_1)\hat{v}_1\).

Parameters
v0Vector whose component we want.
v1Vector that the component must be parallel to.
Returns
Component of v0 that is parallel to v1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ perp()

Vector2 Shapes::perp ( const Vector2 & v)

Compute the counterclockwise perpendicular of a vector, preserving length. 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}\).

Parameters
vA vector, not necessarily normalized.
Returns
The counterclockwise perpendicular to v of the same length.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RotatePt()

Vector2 Shapes::RotatePt ( Vector2 u,
const Vector2 & v,
const float a )

Rotate a point about an arbitrary center.

Parameters
uPoint to be rotated.
vCenter of rotation.
aAngle of rotation in radians counterclockwise.
Returns
Rotated point.
Here is the call graph for this function:
Here is the caller graph for this function: