-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_op.c
54 lines (46 loc) · 1.63 KB
/
vector_op.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vector_op.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tdemay <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/13 14:24:37 by bmikaeli #+# #+# */
/* Updated: 2014/03/16 15:30:10 by tdemay ### ########.fr */
/* */
/* ************************************************************************** */
#include "vector.h"
float vector_lenght(t_vect *vect)
{
return (sqrt(SQUARE(vect->x) + SQUARE(vect->y)+ SQUARE(vect->z )));
}
void vector_normalize(t_vect *vect)
{
float lenght;
lenght = vector_lenght(vect);
if (lenght > 0)
{
//lenght = 1 / lenght;
vect->x = vect->x / lenght;
vect->y = vect->y / lenght;
vect->z = vect->z / lenght;
}
}
t_vect *vector_sub(t_vect *dest, t_vect *src)
{
t_vect *result;
result = NEW(t_vect);
result->x = dest->x - src->x;
result->y = dest->y - src->y;
result->z = dest->z - src->z;
return (result);
}
t_vect *vector_mult_scal(t_vect *dest, float scalaire)
{
t_vect *result;
result = NEW(t_vect);
result->x = dest->x * scalaire;
result->y = dest->y * scalaire;
result->z = dest->z * scalaire;
return (result);
}