-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: added 10 basic vector calculus functions
- Loading branch information
1 parent
92b782c
commit 37da5d9
Showing
5 changed files
with
104 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: tsuchen <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2024/08/15 12:02:08 by tsuchen #+# #+# # | ||
# Updated: 2024/08/27 11:36:32 by tsuchen ### ########.fr # | ||
# Updated: 2024/08/27 13:58:10 by tsuchen ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -22,7 +22,7 @@ SRCS_MAP = map.c | |
|
||
SRCS_RC = raycasting.c | ||
|
||
SRCS_VEC = vector.c | ||
SRCS_VEC = vector.c vector_2.c | ||
|
||
PATH_M = srcs/ | ||
PATH_PS = srcs/parser/ | ||
|
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,21 +6,32 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 10:56:32 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/27 11:41:19 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/08/27 13:55:58 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef VECTOR_H | ||
# define VECTOR_H | ||
|
||
# include <math.h> | ||
# include <limits.h> | ||
# include <stdint.h> | ||
|
||
typedef struct s_vec | ||
{ | ||
double x; | ||
double y; | ||
} t_vec; | ||
|
||
void vec_init(t_vec *vec, double x, double y); | ||
void vec_add(t_vec *vec_a, const t_vec *vec_b); | ||
void vec_sub(t_vec *vec_a, const t_vec *vec_b); | ||
void vec_muls(t_vec *vec, double scalar); | ||
double vec_dot(const t_vec *vec_a, const t_vec *vec_b); | ||
double vec_absv(const t_vec *vec); | ||
double vec_dist(const t_vec *vec_a, const t_vec *vec_b); | ||
void vec_mirror(t_vec *vec); | ||
void vec_transp(t_vec *vec); | ||
void vec_rotate(t_vec *vec, double angle); | ||
t_vec vec_dot(t_vec *vec_a, t_vec *vec_b); | ||
|
||
#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: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 11:11:34 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/27 11:14:06 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/08/27 13:32:54 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,3 +17,29 @@ void vec_init(t_vec *vec, double x, double y) | |
vec->x = x; | ||
vec->y = y; | ||
} | ||
|
||
void vec_add(t_vec *vec_a, const t_vec *vec_b) | ||
{ | ||
vec_a->x = vec_a->x + vec_b->x; | ||
vec_a->y = vec_a->y + vec_b->y; | ||
} | ||
|
||
void vec_sub(t_vec *vec_a, const t_vec *vec_b) | ||
{ | ||
vec_a->x = vec_a->x - vec_b->x; | ||
vec_a->y = vec_b->y - vec_b->y; | ||
} | ||
|
||
void vec_muls(t_vec *vec, double scalar) | ||
{ | ||
vec->x = vec->x * scalar; | ||
vec->y = vec->y * scalar; | ||
} | ||
|
||
double vec_dot(const t_vec *vec_a, const t_vec *vec_b) | ||
{ | ||
double dot; | ||
|
||
dot = (vec_a->x * vec_b->x) + (vec_a->y * vec_b->y); | ||
return (dot); | ||
} |
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,59 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* vector_2.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 13:33:30 by tsuchen #+# #+# */ | ||
/* Updated: 2024/08/27 13:55:09 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "vector.h" | ||
|
||
double vec_absv(const t_vec *vec) | ||
{ | ||
double absv; | ||
|
||
absv = sqrt((vec->x * vec->x) + (vec->y * vec->y)); | ||
return (absv); | ||
} | ||
|
||
double vec_dist(const t_vec *vec_a, const t_vec *vec_b) | ||
{ | ||
double dist; | ||
double del_x; | ||
double del_y; | ||
|
||
del_x = vec_b->x - vec_a->x; | ||
del_y = vec_b->y - vec_a->y; | ||
dist = sqrt((del_x * del_x) + (del_y * del_y)); | ||
return (dist); | ||
} | ||
|
||
void vec_mirror(t_vec *vec) | ||
{ | ||
vec->x = vec->x * -1; | ||
vec->y = vec->y * -1; | ||
} | ||
|
||
void vec_transp(t_vec *vec) | ||
{ | ||
double tmp; | ||
|
||
tmp = vec->x; | ||
vec->x = vec->y; | ||
vec->y = tmp; | ||
} | ||
|
||
void vec_rotate(t_vec *vec, double angle) | ||
{ | ||
double new_x; | ||
double new_y; | ||
|
||
new_x = vec->x * cos(angle) - vec->y * sin(angle); | ||
new_y = vec->x * sin(angle) + vec->y * cos(angle); | ||
vec->x = new_x; | ||
vec->y = new_y; | ||
} |