/* ************************************************************************** */ /* */ /* :::::::: */ /* vec_math.h :+: :+: */ /* +:+ */ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/04/25 10:11:44 by whaffman #+# #+# */ /* Updated: 2025/05/12 12:11:59 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 double. */ double 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 double. */ double 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 double. */ double 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 double. */ double 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, double 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, double 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); /** * @brief Rotates a 2D vector by a given direction vector. * * @param vec The 2D vector to rotate. * @param dir The direction vector to rotate by. * @return The rotated vector as a new 2D vector. */ t_vec2 rot_by_dir(t_vec2 vec, t_vec2 dir, t_vec2 axis); /** * @brief Converts a 2D vector to a 2D integer vector. * * @param vec The 2D vector to convert. * @return The converted 2D integer vector. */ t_vec2_int vec2_to_int(t_vec2 vec); /** * @brief Converts a 2D integer vector to a 2D vector. * * @param vec The 2D integer vector to convert. * @return The converted 2D vector. */ t_vec2 vec2_from_int(t_vec2_int vec); /** * @brief Calculates the fractional part of each component of a 2D vector. * * This function takes a 2D vector as input and returns a new vector where * each component is the fractional part of the corresponding component * in the input vector. The fractional part of a number is the part * after the decimal point. * * @param vec The input 2D vector. * @return A 2D vector containing the fractional parts. */ t_vec2 get_fraction(t_vec2 vec); #endif // VEC_MATH_H