-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_3.c
56 lines (49 loc) · 1.43 KB
/
math_3.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
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvarussa <vvarussa@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/24 18:11:05 by vvarussa #+# #+# */
/* Updated: 2021/09/27 20:23:59 by vvarussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
t_dunit negate(t_dunit a)
{
a.x = -a.x;
a.y = -a.y;
a.z = -a.z;
a.w = -a.w;
return (a);
}
t_dunit multiply(t_dunit a, double n)
{
a.x = a.x * n;
a.y = a.y * n;
a.z = a.z * n;
return (a);
}
t_dunit divide(t_dunit a, double n)
{
a.x = a.x / n;
a.y = a.y / n;
a.z = a.z / n;
return (a);
}
double magnitude(t_dunit a)
{
return (sqrt((a.x * a.x) + (a.y * a.y) + (a.z * a.z)));
}
t_dunit normalize(t_dunit a)
{
double mag;
mag = magnitude(a);
if (mag == 0)
return (a);
a.x = a.x / mag;
a.y = a.y / mag;
a.z = a.z / mag;
return (a);
}