Trace Engine
A Raycaster Engine in C
Loading...
Searching...
No Matches
trigonometry.h File Reference
#include "trc_world_position.h"
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define PRECISION   0.0001
 
#define DEGREE   0.0174533
 
#define PI   3.1415926535
 
#define UP_DIR   (PI / 2)
 
#define DOWN_DIR   (3 * (UP_DIR))
 
#define LEFT_DIR   (PI)
 
#define RIGHT_DIR   (PI * 0)
 
#define DEG_TO_RAD(angleInDegrees)   (adjust_angle((angleInDegrees) * PI / 180.0))
 
#define RAD_TO_DEG(angleInRadians)   (adjust_angle(angleInRadians) * 180.0 / PI)
 
#define trc_world_position_to_string(X)   trc_world_position_to_string_with_name(X, #X)
 

Functions

char * trc_world_position_to_string_with_name (const trc_world_position_t pos, const char *pos_name)
 
float distance_between (const trc_world_position_t p1, const trc_world_position_t p2)
 
float vector_length (const trc_world_position_t vector)
 
trc_world_position_t normalize_vector (const trc_world_position_t vector)
 
trc_world_position_t scalar_multiplication (const trc_world_position_t vector, const float scalar)
 
float angle_from_vector (trc_world_position_t vector)
 
float adjust_angle (const float angle)
 
bool are_equals (const float f1, const float f2)
 

Macro Definition Documentation

◆ DEG_TO_RAD

#define DEG_TO_RAD (   angleInDegrees)    (adjust_angle((angleInDegrees) * PI / 180.0))

Angle in degrees to angle in radians

◆ DEGREE

#define DEGREE   0.0174533

One degree in radians

◆ DOWN_DIR

#define DOWN_DIR   (3 * (UP_DIR))

270 degrees, or the angle in radians for ↓

◆ LEFT_DIR

#define LEFT_DIR   (PI)

180 degrees, or the angle in radians for ←

◆ PI

#define PI   3.1415926535

An aproximation to pi

◆ PRECISION

#define PRECISION   0.0001

To compare doubles and floats

◆ RAD_TO_DEG

#define RAD_TO_DEG (   angleInRadians)    (adjust_angle(angleInRadians) * 180.0 / PI)

Angle in radians to angle in degrees

◆ RIGHT_DIR

#define RIGHT_DIR   (PI * 0)

0 degrees, or the angle in radians for →

◆ trc_world_position_to_string

#define trc_world_position_to_string (   X)    trc_world_position_to_string_with_name(X, #X)

Only for debug, it returns the position in the form of a string with the format:

"pos_name = (pos.x, pos.y)"

Note
Caller MUST free the memory allocated for the string

◆ UP_DIR

#define UP_DIR   (PI / 2)

90 degrees, or the angle in radians for ↑

Function Documentation

◆ adjust_angle()

float adjust_angle ( const float  angle)

Returns the angle so it's in the range of 0 to 2*PI

Parameters
angleThe angle to adjust, in radians

◆ angle_from_vector()

float angle_from_vector ( trc_world_position_t  vector)

Use the position given as a vector, and returns it's angle

◆ are_equals()

bool are_equals ( const float  f1,
const float  f2 
)

Returns if the first float is equal to the second

Parameters
f1First float
f2Second float

◆ distance_between()

float distance_between ( const trc_world_position_t  p1,
const trc_world_position_t  p2 
)

Returns the distance between p1 and p2

Parameters
p1First point
p2Second point

◆ normalize_vector()

trc_world_position_t normalize_vector ( const trc_world_position_t  vector)

Returns the normalized vector

Note
If it is already normalized, returns one with the same parameters

◆ scalar_multiplication()

trc_world_position_t scalar_multiplication ( const trc_world_position_t  vector,
const float  scalar 
)

Returns the given vector scaled by the given factor

◆ trc_world_position_to_string_with_name()

char * trc_world_position_to_string_with_name ( const trc_world_position_t  pos,
const char *  pos_name 
)
Note
Remember to free the memory allocated for the string!

◆ vector_length()

float vector_length ( const trc_world_position_t  vector)

Returns the distance between the origin and the given vector