-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec2_math.c
47 lines (40 loc) · 1.32 KB
/
vec2_math.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec2_math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrophy <dbrophy@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/23 11:54:30 by dbrophy #+# #+# */
/* Updated: 2020/02/23 11:54:30 by dbrophy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftmath.h"
double vec2_mag(t_vec2 *vec)
{
double x;
double y;
x = vec->x;
y = vec->y;
return (ft_sqrt(x * x + y * y));
}
void vec2_norm(t_vec2 *vec)
{
double x;
double y;
double mag;
x = vec->x;
y = vec->y;
mag = ft_sqrt(x * x + y * y);
vec->x = x / mag;
vec->y = y / mag;
}
void vec2_muls(t_vec2 *vec, double s)
{
vec->x *= s;
vec->y *= s;
}
double vec2_dot(t_vec2 *a, t_vec2 *b)
{
return (a->x * b->x + a->y * b->y);
}