cub3d/inc/vec_math.h
2025-04-25 10:46:34 +02:00

97 lines
3.0 KiB
C

/* ************************************************************************** */
/* */
/* :::::::: */
/* vec_math.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */
/* Updated: 2025/04/25 10:44:33 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef VEC_MATH_H
# define VEC_MATH_H
# include "types.h"
/**
* @brief Calculates the distance between two 2D vectors.
*
* @param a The first 2D vector.
* @param b The second 2D vector.
* @return The distance between vector a and vector b as a float.
*/
float dist(t_vec2 a, t_vec2 b);
/**
* @brief Calculates the norm (length) of a 2D vector.
*
* @param a The 2D vector.
* @return The norm of vector a as a float.
*/
float norm(t_vec2 a);
/**
* @brief Calculates the dot product of two 2D vectors.
*
* @param a The first 2D vector.
* @param b The second 2D vector.
* @return The dot product of vector a and vector b as a float.
*/
float dot(t_vec2 a, t_vec2 b);
/**
* @brief Calculates the distance from a point to a line.
*
* @param point The point to calculate the distance from.
* @param line The line defined by a (support)point and a direction.
* @return The distance from the point to the line as a float.
*/
float dist_point_line(t_vec2 point, t_vec2_line line);
/**
* @brief Adds two 2D vectors.
*
* @param a The first 2D vector.
* @param b The second 2D vector.
* @return The sum of vector a and vector b as a new 2D vector.
*/
t_vec2 add(t_vec2 a, t_vec2 b);
/**
* @brief Subtracts one 2D vector from another.
*
* @param a The first 2D vector.
* @param b The second 2D vector to subtract from the first.
* @return The result of subtracting vector b from vector a as a new 2D vector.
*/
t_vec2 sub(t_vec2 a, t_vec2 b);
/**
* @brief Multiplies a 2D vector by a scalar.
*
* @param a The 2D vector to multiply.
* @param b The scalar to multiply the vector by.
* @return The result of multiplying vector a by scalar b as a new 2D vector.
*/
t_vec2 mul(t_vec2 a, float b);
/**
* @brief Rotates a 2D vector by a given angle.
*
* @param a The 2D vector to rotate.
* @param angle The angle in radians to rotate the vector by.
* @return The rotated vector as a new 2D vector.
*/
t_vec2 rot(t_vec2 a, float angle);
/**
* @brief Calculates the perpendicular vector of a 2D vector.
*
* @param a The 2D vector to calculate the perpendicular of.
* @return The perpendicular vector as a new 2D vector.
*/
t_vec2 perp(t_vec2 a);
#endif // VEC_MATH_H