ASCII-GFX  2.0
Classes | Functions
math2d.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Vec2
 2D vector type More...
 
struct  Vec3
 3D vector type More...
 
struct  Mat3
 3D matrix type More...
 

Functions

Vec2 vec2 (float x=0, float y=0)
 2D vector construction from components x and y More...
 
Vec3 vec3 (float x=0, float y=0, float z=1)
 3D vector construction from components x, y and z More...
 
Vec3 vec3 (Vec2 v)
 3D vector construction from 2D vector More...
 
Mat3 mat3 (float r1x=1, float r1y=0, float r1z=0, float r2x=0, float r2y=1, float r2z=0, float r3x=0, float r3y=0, float r3z=1)
 3D matrix construction More...
 
Vec2 add2 (Vec2 a, Vec2 b)
 2D vector addition More...
 
Vec2 sub2 (Vec2 a, Vec2 b)
 2D vector subtraction More...
 
Vec2 mul2 (Vec2 a, Vec2 b)
 2D vector multiplication More...
 
Vec2 mul2s (Vec2 a, float s)
 2D vector multiplication with scalar value More...
 
float dot2 (Vec2 a, Vec2 b)
 2D dot product More...
 
float dot3 (Vec3 a, Vec3 b)
 3D dot product More...
 
Vec3 row1 (const Mat3 &m)
 get 3D matrix row More...
 
Vec3 row2 (const Mat3 &m)
 
Vec3 row3 (const Mat3 &m)
 
Vec3 col1 (const Mat3 &m)
 get 3D matrix column More...
 
Vec3 col2 (const Mat3 &m)
 
Vec3 col3 (const Mat3 &m)
 
Mat3 mul3 (const Mat3 &m1, const Mat3 &m2)
 3D matrix multiplication More...
 
Vec2 mul3v (const Mat3 &m, Vec3 v)
 3D matrix multiplication with right-hand side vector More...
 
int vec2_x (Vec2 v)
 convert x-component of 2D vector to rounded int More...
 
int vec2_y (Vec2 v)
 convert y-component of 2D vector to rounded int More...
 
int vec3_x (Vec3 v)
 convert x-component of 3D vector to rounded int More...
 
int vec3_y (Vec3 v)
 convert y-component of 3D vector to rounded int More...
 
int vec3_z (Vec3 v)
 convert z-component of 3D vector to rounded int More...
 
Mat3 top ()
 get current transformation represented by a 3x3 homogeneous matrix the current transformation is the top of the matrix stack More...
 
void push ()
 push current transformation this duplicates the current matrix on top of the matrix stack More...
 
void replace (const Mat3 &m)
 replace current transformation with a given transformation matrix More...
 
Mat3 pop ()
 pop current transformation this removes the current matrix on top of the matrix stack More...
 
void translate (Vec2 v)
 apply translation vector to current transformation More...
 
void translate (float x, float y)
 apply translation to current transformation More...
 
void rotate (float a, float aspect=2)
 apply clockwise rotation to current transformation More...
 
void scale (float f)
 apply uniform scaling factor to current transformation More...
 
void scale (float s, float t)
 apply non-uniform scaling to current transformation More...
 
Vec2 translation ()
 get current translation vector More...
 
float rotation (float aspect=2)
 get current rotation angle More...
 
float scaling (float aspect=2)
 get current scaling factor More...
 

Function Documentation

◆ add2()

Vec2 add2 ( Vec2  a,
Vec2  b 
)
inline

2D vector addition

◆ col1()

Vec3 col1 ( const Mat3 m)
inline

get 3D matrix column

◆ col2()

Vec3 col2 ( const Mat3 m)
inline

◆ col3()

Vec3 col3 ( const Mat3 m)
inline

◆ dot2()

float dot2 ( Vec2  a,
Vec2  b 
)
inline

2D dot product

◆ dot3()

float dot3 ( Vec3  a,
Vec3  b 
)
inline

3D dot product

◆ mat3()

Mat3 mat3 ( float  r1x = 1,
float  r1y = 0,
float  r1z = 0,
float  r2x = 0,
float  r2y = 1,
float  r2z = 0,
float  r3x = 0,
float  r3y = 0,
float  r3z = 1 
)
inline

3D matrix construction

◆ mul2()

Vec2 mul2 ( Vec2  a,
Vec2  b 
)
inline

2D vector multiplication

◆ mul2s()

Vec2 mul2s ( Vec2  a,
float  s 
)
inline

2D vector multiplication with scalar value

◆ mul3()

Mat3 mul3 ( const Mat3 m1,
const Mat3 m2 
)
inline

3D matrix multiplication

◆ mul3v()

Vec2 mul3v ( const Mat3 m,
Vec3  v 
)
inline

3D matrix multiplication with right-hand side vector

◆ pop()

Mat3 pop ( )

pop current transformation this removes the current matrix on top of the matrix stack

◆ push()

void push ( )

push current transformation this duplicates the current matrix on top of the matrix stack

◆ replace()

void replace ( const Mat3 m)

replace current transformation with a given transformation matrix

◆ rotate()

void rotate ( float  a,
float  aspect = 2 
)

apply clockwise rotation to current transformation

  • the current transformation matrix is multiplied with a rotation matrix
  • defined by a rotation angle a given in degrees
  • the rotation aspect is 2 by default for characters two times higher than wide

◆ rotation()

float rotation ( float  aspect = 2)

get current rotation angle

  • does not work for non-uniformly scaled transformations
  • the rotation aspect is 2 by default for characters two times higher than wide

◆ row1()

Vec3 row1 ( const Mat3 m)
inline

get 3D matrix row

◆ row2()

Vec3 row2 ( const Mat3 m)
inline

◆ row3()

Vec3 row3 ( const Mat3 m)
inline

◆ scale() [1/2]

void scale ( float  f)

apply uniform scaling factor to current transformation

  • the current transformation matrix is multiplied with a scaling matrix
  • defined by the scaling factor f in x- and y-direction

◆ scale() [2/2]

void scale ( float  s,
float  t 
)

apply non-uniform scaling to current transformation

  • the current transformation matrix is multiplied with a scaling matrix
  • defined by the scaling factors in x- and y-direction s and t

◆ scaling()

float scaling ( float  aspect = 2)

get current scaling factor

  • does not work for non-uniformly scaled transformations
  • the rotation aspect is 2 by default for characters two times higher than wide

◆ sub2()

Vec2 sub2 ( Vec2  a,
Vec2  b 
)
inline

2D vector subtraction

◆ top()

Mat3 top ( )

get current transformation represented by a 3x3 homogeneous matrix the current transformation is the top of the matrix stack

◆ translate() [1/2]

void translate ( float  x,
float  y 
)

apply translation to current transformation

  • the current transformation matrix is multiplied with a translation matrix
  • defined by the translation vector (x, y)

◆ translate() [2/2]

void translate ( Vec2  v)

apply translation vector to current transformation

  • the current transformation matrix is multiplied with a translation matrix
  • defined by the translation vector v

◆ translation()

Vec2 translation ( )

get current translation vector

◆ vec2()

Vec2 vec2 ( float  x = 0,
float  y = 0 
)
inline

2D vector construction from components x and y

◆ vec2_x()

int vec2_x ( Vec2  v)
inline

convert x-component of 2D vector to rounded int

◆ vec2_y()

int vec2_y ( Vec2  v)
inline

convert y-component of 2D vector to rounded int

◆ vec3() [1/2]

Vec3 vec3 ( float  x = 0,
float  y = 0,
float  z = 1 
)
inline

3D vector construction from components x, y and z

  • homogeneous coordinate z is 1 by default

◆ vec3() [2/2]

Vec3 vec3 ( Vec2  v)
inline

3D vector construction from 2D vector

  • homogeneous coordinate is complemented to be 1

◆ vec3_x()

int vec3_x ( Vec3  v)
inline

convert x-component of 3D vector to rounded int

◆ vec3_y()

int vec3_y ( Vec3  v)
inline

convert y-component of 3D vector to rounded int

◆ vec3_z()

int vec3_z ( Vec3  v)
inline

convert z-component of 3D vector to rounded int