PER Firmware
Loading...
Searching...
No Matches
vector2.h File Reference

2D vector types and operations. More...

#include <math.h>
Include dependency graph for vector2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vector2
 

Typedefs

typedef struct vector2 vector2_t
 

Functions

static vector2_t vector2_add (const vector2_t a, const vector2_t b)
 Add two 2D vectors.
 
static vector2_t vector2_sub (const vector2_t a, const vector2_t b)
 Subtract one 2D vector from another.
 
static vector2_t vector2_scale (const vector2_t vec, const float scalar)
 Scale a 2D vector by a scalar.
 
static float vector2_dot (const vector2_t a, const vector2_t b)
 Dot product of two 2D vectors.
 
static float vector2_cross (const vector2_t a, const vector2_t b)
 Cross product of two 2D vectors.
 
static float vector2_magnitude (const vector2_t vec)
 Calculate the magnitude of a 2D vector.
 
static vector2_t vector2_normalize (const vector2_t vec)
 Normalize a 2D vector.
 
static float vector2_distance (const vector2_t a, const vector2_t b)
 Distance between two 2D points.
 
static vector2_t vector2_midpoint (const vector2_t a, const vector2_t b)
 Midpoint of two 2D points.
 
static vector2_t vector2_perpendicular (const vector2_t vec)
 Rotate a 2D vector 90 degrees counterclockwise.
 

Detailed Description

2D vector types and operations.

Basic floating point 2D vector operations.

Author
Irving Wang (irvin.nosp@m.gw@p.nosp@m.urdue.nosp@m..edu)

Typedef Documentation

◆ vector2_t

typedef struct vector2 vector2_t

Function Documentation

◆ vector2_add()

static vector2_t vector2_add ( const vector2_t a,
const vector2_t b )
inlinestatic

Add two 2D vectors.

Parameters
aThe first input vector
bThe second input vector
Returns
The sum a + b.
Here is the caller graph for this function:

◆ vector2_cross()

static float vector2_cross ( const vector2_t a,
const vector2_t b )
inlinestatic

Cross product of two 2D vectors.

In 2D the cross product has only a Z component, so it reduces to a scalar. Positive means b lies counterclockwise of a, negative means clockwise.

Parameters
aThe first input vector
bThe second input vector
Returns
The Z component of a x b.
Here is the caller graph for this function:

◆ vector2_distance()

static float vector2_distance ( const vector2_t a,
const vector2_t b )
inlinestatic

Distance between two 2D points.

Parameters
aThe first point
bThe second point
Returns
The straight line distance between a and b.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vector2_dot()

static float vector2_dot ( const vector2_t a,
const vector2_t b )
inlinestatic

Dot product of two 2D vectors.

Parameters
aThe first input vector
bThe second input vector
Returns
The scalar dot product.
Here is the caller graph for this function:

◆ vector2_magnitude()

static float vector2_magnitude ( const vector2_t vec)
inlinestatic

Calculate the magnitude of a 2D vector.

Parameters
vecThe input vector
Returns
The magnitude of the vector.
Here is the caller graph for this function:

◆ vector2_midpoint()

static vector2_t vector2_midpoint ( const vector2_t a,
const vector2_t b )
inlinestatic

Midpoint of two 2D points.

Parameters
aThe first point
bThe second point
Returns
The point halfway between a and b.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vector2_normalize()

static vector2_t vector2_normalize ( const vector2_t vec)
inlinestatic

Normalize a 2D vector.

Parameters
vecThe input vector
Returns
The normalized vector, or the zero vector if vec is degenerate.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vector2_perpendicular()

static vector2_t vector2_perpendicular ( const vector2_t vec)
inlinestatic

Rotate a 2D vector 90 degrees counterclockwise.

Parameters
vecThe input vector
Returns
A vector of equal magnitude perpendicular to vec.
Here is the caller graph for this function:

◆ vector2_scale()

static vector2_t vector2_scale ( const vector2_t vec,
const float scalar )
inlinestatic

Scale a 2D vector by a scalar.

Parameters
vecThe input vector
scalarThe value to scale by
Returns
The scaled vector.
Here is the caller graph for this function:

◆ vector2_sub()

static vector2_t vector2_sub ( const vector2_t a,
const vector2_t b )
inlinestatic

Subtract one 2D vector from another.

Parameters
aThe vector to subtract from
bThe vector to subtract
Returns
The difference a - b.
Here is the caller graph for this function: