-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated with FDF used functions, particularly ft_math_utils.
- Loading branch information
Matthew Yeow
committed
Aug 23, 2024
1 parent
cb8b85d
commit d016d3c
Showing
56 changed files
with
1,602 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/12 16:48:49 by myeow #+# #+# */ | ||
/* Updated: 2024/05/12 16:50:38 by myeow ### ########.fr */ | ||
/* Updated: 2024/08/05 22:04:41 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -19,5 +19,6 @@ int ft_isascii(int c); | |
int ft_isdigit(int c); | ||
int ft_isprint(int c); | ||
int ft_isspace(int c); | ||
int ft_ishex(int c); | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_math_utils.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/30 20:02:38 by myeow #+# #+# */ | ||
/* Updated: 2024/08/12 19:42:05 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef FT_MATH_UTILS_H | ||
# define FT_MATH_UTILS_H | ||
|
||
# include <stdint.h> | ||
|
||
# ifndef PI | ||
# define PI 3.14159265358979323846 | ||
# endif | ||
|
||
# ifndef PI_2 | ||
# define PI_2 1.57079632679489661923 | ||
# endif | ||
|
||
# ifndef PI_4 | ||
# define PI_4 0.78539816339744830962 | ||
# endif | ||
|
||
# ifndef ATAN_TABLE_ITERS | ||
# define ATAN_TABLE_ITERS 16 | ||
# endif | ||
|
||
# ifndef K_FACTOR | ||
# define K_FACTOR 0.6072529350088812561694 | ||
# endif | ||
|
||
# ifndef QUAT_EPS | ||
# define QUAT_EPS 1e-4 | ||
# endif | ||
|
||
typedef struct s_2d_vector | ||
{ | ||
double x; | ||
double y; | ||
} t_vec2; | ||
|
||
typedef struct s_3d_vector | ||
{ | ||
double x; | ||
double y; | ||
double z; | ||
} t_vec3; | ||
|
||
typedef struct s_quaternion | ||
{ | ||
double w; | ||
t_vec3 v; | ||
} t_quat; | ||
|
||
typedef union s_conv | ||
{ | ||
double d; | ||
uint64_t i; | ||
} t_conv; | ||
|
||
double ft_abs(double d); | ||
double ft_copysign(double x, double y); | ||
void ft_swap(double *a, double *b); | ||
double ft_modf(double d, double *i); | ||
double ft_floor(double d); | ||
double ft_ceil(double d); | ||
double ft_round(double d); | ||
double ft_fractional(double d); | ||
double ft_rev_fractional(double d); | ||
double ft_fmod(double x, double y); | ||
double ft_sqrt_inverse_fast(double x); | ||
double ft_sqrt_fast(double x); | ||
double ft_sqrt(double x); | ||
unsigned long long ft_factorial(int x); | ||
double ft_power(double x, int p); | ||
double ft_atan_table(int i); | ||
double ft_sin(double r); | ||
double ft_cos(double r); | ||
double ft_tan(double r); | ||
double ft_asin(double x); | ||
double ft_acos(double x); | ||
double ft_atan(double x); | ||
double ft_atan2(double y, double x); | ||
|
||
//QUATERNION_UTILS | ||
void ft_quatset(double w, t_vec3 v, t_quat *out); | ||
void ft_quatset_id(t_quat *out); | ||
void ft_quatcpy(t_quat *q, t_quat *out); | ||
int ft_quat_isequal(t_quat *q1, t_quat *q2); | ||
void ft_quat_print(t_quat *q); | ||
void ft_quat_from_axis_angle(t_vec3 *axis, double r, \ | ||
t_quat *out); | ||
void ft_quat_from_xrotation(double r, t_quat *out); | ||
void ft_quat_from_yrotation(double r, t_quat *out); | ||
void ft_quat_from_zrotation(double r, t_quat *out); | ||
double ft_quatget_magnitude(t_quat *q); | ||
void ft_quat_normalise(t_quat *out); | ||
double ft_quat_to_axis_angle(t_quat *q, t_vec3 *out); | ||
void ft_quat_from_euler_zyx(t_vec3 *v, t_quat *out); | ||
void ft_quat_to_euler_zyx(t_quat *q, t_vec3 *out); | ||
void ft_quat_conjugate(t_quat *q, t_quat *out); | ||
void ft_quat_mult(t_quat *q1, t_quat *q2, t_quat *out); | ||
void ft_quat_rotate(t_vec3 *v, t_quat *q, t_vec3 *out); | ||
void ft_quat_slerp(t_quat *q1, t_quat *q2, double t, \ | ||
t_quat *out); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/12 16:50:08 by myeow #+# #+# */ | ||
/* Updated: 2024/05/12 16:50:34 by myeow ### ########.fr */ | ||
/* Updated: 2024/08/11 18:06:22 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,5 +17,7 @@ void ft_putchar_fd(char c, int fd); | |
void ft_putstr_fd(char *s, int fd); | ||
void ft_putendl_fd(char *s, int fd); | ||
void ft_putnbr_fd(int n, int fd); | ||
void ft_putnbr_base_fd(int nbr, char *base, int fd); | ||
void ft_putdbl_fd(double d, int fd); | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/12 16:50:19 by myeow #+# #+# */ | ||
/* Updated: 2024/05/17 17:50:15 by myeow ### ########.fr */ | ||
/* Updated: 2024/08/07 20:05:29 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -16,6 +16,7 @@ | |
# include <stddef.h> | ||
|
||
int ft_atoi(const char *str); | ||
int ft_atoi_base(char *str, char *base); | ||
void ft_free_ft_split(char **str_array); | ||
char *ft_itoa(int n); | ||
char **ft_split(char const *s, char c); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/15 16:11:56 by myeow #+# #+# */ | ||
/* Updated: 2024/05/12 16:50:31 by myeow ### ########.fr */ | ||
/* Updated: 2024/07/30 20:05:47 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_ishex.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/05 22:01:09 by myeow #+# #+# */ | ||
/* Updated: 2024/08/05 22:05:32 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_isdigit(int c); | ||
|
||
int ft_ishex(int c) | ||
{ | ||
if (ft_isdigit(c)) | ||
return (1); | ||
if (c >= 'A' && c <= 'F') | ||
return (1); | ||
if (c >= 'a' && c <= 'f') | ||
return (1); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_abs.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/30 19:56:45 by myeow #+# #+# */ | ||
/* Updated: 2024/07/30 19:58:38 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
double ft_abs(double d) | ||
{ | ||
if (d < 0) | ||
return (-d); | ||
return (d); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_acos.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/10 00:47:32 by myeow #+# #+# */ | ||
/* Updated: 2024/08/11 01:50:32 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_math_utils.h" | ||
|
||
void ft_putendl_fd(char *s, int fd); | ||
|
||
double ft_asin(double x); | ||
|
||
double ft_acos(double x) | ||
{ | ||
if (x < -1.0 || x > 1.0) | ||
{ | ||
ft_putendl_fd("Undefined.", 2); | ||
return (0); | ||
} | ||
return (PI / 2 - ft_asin(x)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_asin.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: myeow <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/10 00:48:44 by myeow #+# #+# */ | ||
/* Updated: 2024/08/11 01:50:07 by myeow ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
void ft_putendl_fd(char *s, int fd); | ||
|
||
double ft_abs(double d); | ||
|
||
double ft_sin(double r); | ||
|
||
double ft_cos(double r); | ||
|
||
double ft_asin(double x) | ||
{ | ||
double y; | ||
int i; | ||
double y_prime; | ||
const double tolerance = 1e-10; | ||
|
||
if (x < -1.0 || x > 1.0) | ||
{ | ||
ft_putendl_fd("Undefined.", 2); | ||
return (0); | ||
} | ||
y = x; | ||
i = -1; | ||
while (++i < 100) | ||
{ | ||
y_prime = y - ((ft_sin(y) - x) / ft_cos(y)); | ||
if (ft_abs(y_prime - y) < tolerance) | ||
return (y_prime); | ||
y = y_prime; | ||
} | ||
return (y); | ||
} |
Oops, something went wrong.