-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector1.c
63 lines (52 loc) · 1.54 KB
/
vector1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: okupin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/21 18:03:00 by okupin #+# #+# */
/* Updated: 2018/05/21 18:03:14 by okupin ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
t_v3 v_diff(t_v3 a, t_v3 b)
{
t_v3 c;
c.x = a.x - b.x;
c.y = a.y - b.y;
c.z = a.z - b.z;
return (c);
}
t_v3 v_add(t_v3 a, t_v3 b)
{
t_v3 c;
c.x = a.x + b.x;
c.y = a.y + b.y;
c.z = a.z + b.z;
return (c);
}
t_v3 v_cross(t_v3 a, t_v3 b)
{
t_v3 c;
c.x = a.y * b.z - a.z * b.y;
c.y = a.z * b.x - a.x * b.z;
c.z = a.x * b.y - a.y * b.x;
return (c);
}
t_v3 v_scale(t_v3 a, float scalar)
{
t_v3 c;
c.x = a.x * scalar;
c.y = a.y * scalar;
c.z = a.z * scalar;
return (c);
}
float v_dot(t_v3 a, t_v3 b)
{
return (a.x * b.x + a.y * b.y + a.z * b.z);
}
void v_print(char *str, t_v3 a)
{
printf("---%s--- x: %f y: %f z: %f\n", str, a.x, a.y, a.z);
}