-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec_math.c
63 lines (52 loc) · 1.49 KB
/
vec_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkushche <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/31 17:28:47 by dkushche #+# #+# */
/* Updated: 2018/03/31 17:28:47 by dkushche ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
t_vec plus(t_vec a, t_vec b)
{
t_vec res;
res.x = a.x + b.x;
res.y = a.y + b.y;
res.z = a.z + b.z;
return (res);
}
double dot(t_vec a, t_vec b)
{
double res;
res = a.x * b.x + a.y * b.y + a.z * b.z;
return (res);
}
t_vec norm(t_vec a)
{
t_vec res;
double len;
len = sqrt(dot(a, a));
res.x = a.x / len;
res.y = a.y / len;
res.z = a.z / len;
return (res);
}
t_vec vxs(t_vec a, double b)
{
t_vec res;
res.x = a.x * b;
res.y = a.y * b;
res.z = a.z * b;
return (res);
}
t_vec gener(double x, double y, double z)
{
t_vec res;
res.x = x;
res.y = y;
res.z = z;
return (res);
}