# Box2D/Box2D/Common/b2Math.h File Reference

`#include <Box2D/Common/b2Settings.h>`
`#include <cmath>`
`#include <cfloat>`
`#include <cstddef>`
`#include <limits>`

Go to the source code of this file.

## Classes
struct | b2Vec2
| A 2D column vector. More...
struct | b2Vec3
| A 2D column vector with 3 elements. More...
struct | b2Mat22
| A 2-by-2 matrix. Stored in column-major order. More...
struct | b2Mat33
| A 3-by-3 matrix. Stored in column-major order. More...
struct | b2Transform
struct | b2Sweep
## Defines
#define | b2Sqrt(x) sqrtf(x)
#define | b2Atan2(y, x) atan2f(y, x)
## Functions
bool | b2IsValid (float32 x)
float32 | b2InvSqrt (float32 x)
| This is a approximate yet fast inverse square-root.
float32 | b2Abs (float32 a)
float32 | b2Dot (const b2Vec2 &a, const b2Vec2 &b)
| Perform the dot product on two vectors.
float32 | b2Cross (const b2Vec2 &a, const b2Vec2 &b)
| Perform the cross product on two vectors. In 2D this produces a scalar.
b2Vec2 | b2Cross (const b2Vec2 &a, float32 s)
b2Vec2 | b2Cross (float32 s, const b2Vec2 &a)
b2Vec2 | b2Mul (const b2Mat22 &A, const b2Vec2 &v)
b2Vec2 | b2MulT (const b2Mat22 &A, const b2Vec2 &v)
b2Vec2 | operator+ (const b2Vec2 &a, const b2Vec2 &b)
| Add two vectors component-wise.
b2Vec2 | operator- (const b2Vec2 &a, const b2Vec2 &b)
| Subtract two vectors component-wise.
b2Vec2 | operator* (float32 s, const b2Vec2 &a)
bool | operator== (const b2Vec2 &a, const b2Vec2 &b)
float32 | b2Distance (const b2Vec2 &a, const b2Vec2 &b)
float32 | b2DistanceSquared (const b2Vec2 &a, const b2Vec2 &b)
b2Vec3 | operator* (float32 s, const b2Vec3 &a)
b2Vec3 | operator+ (const b2Vec3 &a, const b2Vec3 &b)
| Add two vectors component-wise.
b2Vec3 | operator- (const b2Vec3 &a, const b2Vec3 &b)
| Subtract two vectors component-wise.
float32 | b2Dot (const b2Vec3 &a, const b2Vec3 &b)
| Perform the dot product on two vectors.
b2Vec3 | b2Cross (const b2Vec3 &a, const b2Vec3 &b)
| Perform the cross product on two vectors.
b2Mat22 | operator+ (const b2Mat22 &A, const b2Mat22 &B)
b2Mat22 | b2Mul (const b2Mat22 &A, const b2Mat22 &B)
b2Mat22 | b2MulT (const b2Mat22 &A, const b2Mat22 &B)
b2Vec3 | b2Mul (const b2Mat33 &A, const b2Vec3 &v)
| Multiply a matrix times a vector.
b2Vec2 | b2Mul (const b2Transform &T, const b2Vec2 &v)
b2Vec2 | b2MulT (const b2Transform &T, const b2Vec2 &v)
b2Vec2 | b2Abs (const b2Vec2 &a)
b2Mat22 | b2Abs (const b2Mat22 &A)
template<typename T >
T | b2Min (T a, T b)
b2Vec2 | b2Min (const b2Vec2 &a, const b2Vec2 &b)
template<typename T >
T | b2Max (T a, T b)
b2Vec2 | b2Max (const b2Vec2 &a, const b2Vec2 &b)
template<typename T >
T | b2Clamp (T a, T low, T high)
b2Vec2 | b2Clamp (const b2Vec2 &a, const b2Vec2 &low, const b2Vec2 &high)
template<typename T >
void | b2Swap (T &a, T &b)
uint32 | b2NextPowerOfTwo (uint32 x)
bool | b2IsPowerOfTwo (uint32 x)
## Variables
const b2Vec2 | b2Vec2_zero
const b2Mat22 | b2Mat22_identity
const b2Transform | b2Transform_identity

## Define Documentation

#define b2Atan2 | ( | y,
|  | x |  | ) | atan2f(y, x)

#define b2Sqrt | ( | x |  | ) | sqrtf(x)

## Function Documentation

b2Mat22 b2Abs | ( | const b2Mat22 & | A | ) | `[inline]`

b2Vec2 b2Abs | ( | const b2Vec2 & | a | ) | `[inline]`

float32 b2Abs | ( | float32 | a | ) | `[inline]`

b2Vec2 b2Clamp | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | low,
|  | const b2Vec2 & | high |
| ) |  |  | `[inline]`

template<typename T >

T b2Clamp | ( | T | a,
|  | T | low,
|  | T | high |
| ) |  |  | `[inline]`

b2Vec3 b2Cross | ( | const b2Vec3 & | a,
|  | const b2Vec3 & | b |
| ) |  |  | `[inline]`

Perform the cross product on two vectors.

b2Vec2 b2Cross | ( | float32 | s,
|  | const b2Vec2 & | a |
| ) |  |  | `[inline]`

Perform the cross product on a scalar and a vector. In 2D this produces a vector.

b2Vec2 b2Cross | ( | const b2Vec2 & | a,
|  | float32 | s |
| ) |  |  | `[inline]`

Perform the cross product on a vector and a scalar. In 2D this produces a vector.

float32 b2Cross | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

Perform the cross product on two vectors. In 2D this produces a scalar.

float32 b2Distance | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

float32 b2DistanceSquared | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

float32 b2Dot | ( | const b2Vec3 & | a,
|  | const b2Vec3 & | b |
| ) |  |  | `[inline]`

Perform the dot product on two vectors.

float32 b2Dot | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

Perform the dot product on two vectors.

float32 b2InvSqrt | ( | float32 | x | ) | `[inline]`

This is a approximate yet fast inverse square-root.

bool b2IsPowerOfTwo | ( | uint32 | x | ) | `[inline]`

bool b2IsValid | ( | float32 | x | ) | `[inline]`

This function is used to ensure that a floating point number is not a NaN or infinity.

b2Vec2 b2Max | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

template<typename T >

T b2Max | ( | T | a,
|  | T | b |
| ) |  |  | `[inline]`

b2Vec2 b2Min | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

template<typename T >

T b2Min | ( | T | a,
|  | T | b |
| ) |  |  | `[inline]`

b2Vec2 b2Mul | ( | const b2Transform & | T,
|  | const b2Vec2 & | v |
| ) |  |  | `[inline]`

b2Vec3 b2Mul | ( | const b2Mat33 & | A,
|  | const b2Vec3 & | v |
| ) |  |  | `[inline]`

Multiply a matrix times a vector.

b2Mat22 b2Mul | ( | const b2Mat22 & | A,
|  | const b2Mat22 & | B |
| ) |  |  | `[inline]`

b2Vec2 b2Mul | ( | const b2Mat22 & | A,
|  | const b2Vec2 & | v |
| ) |  |  | `[inline]`

Multiply a matrix times a vector. If a rotation matrix is provided, then this transforms the vector from one frame to another.

b2Vec2 b2MulT | ( | const b2Transform & | T,
|  | const b2Vec2 & | v |
| ) |  |  | `[inline]`

b2Mat22 b2MulT | ( | const b2Mat22 & | A,
|  | const b2Mat22 & | B |
| ) |  |  | `[inline]`

b2Vec2 b2MulT | ( | const b2Mat22 & | A,
|  | const b2Vec2 & | v |
| ) |  |  | `[inline]`

Multiply a matrix transpose times a vector. If a rotation matrix is provided, then this transforms the vector from one frame to another (inverse transform).

uint32 b2NextPowerOfTwo | ( | uint32 | x | ) | `[inline]`

"Next Largest Power of 2 Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next largest power of 2. For a 32-bit value:"

template<typename T >

void b2Swap | ( | T & | a,
|  | T & | b |
| ) |  |  | `[inline]`

b2Vec3 operator* | ( | float32 | s,
|  | const b2Vec3 & | a |
| ) |  |  | `[inline]`

b2Vec2 operator* | ( | float32 | s,
|  | const b2Vec2 & | a |
| ) |  |  | `[inline]`

b2Mat22 operator+ | ( | const b2Mat22 & | A,
|  | const b2Mat22 & | B |
| ) |  |  | `[inline]`

b2Vec3 operator+ | ( | const b2Vec3 & | a,
|  | const b2Vec3 & | b |
| ) |  |  | `[inline]`

Add two vectors component-wise.

b2Vec2 operator+ | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

Add two vectors component-wise.

b2Vec3 operator- | ( | const b2Vec3 & | a,
|  | const b2Vec3 & | b |
| ) |  |  | `[inline]`

Subtract two vectors component-wise.

b2Vec2 operator- | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

Subtract two vectors component-wise.

bool operator== | ( | const b2Vec2 & | a,
|  | const b2Vec2 & | b |
| ) |  |  | `[inline]`

## Variable Documentation

const b2Mat22 b2Mat22_identity

const b2Transform b2Transform_identity

const b2Vec2 b2Vec2_zero