-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtor.c
69 lines (62 loc) · 1.93 KB
/
gtor.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
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* gtor.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkushche <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/07 17:48:59 by dkushche #+# #+# */
/* Updated: 2018/02/07 17:49:00 by dkushche ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
double destr_cratch(double res, char **dem)
{
free(dem[0]);
free(dem[1]);
free(dem);
return (res);
}
double gtor(double gr)
{
while (gr >= 360)
gr -= 360;
while (gr <= -360)
gr += 360;
return (M_PI * (gr / 180.0));
}
double atod(char *pom)
{
char **dem;
int first;
int second;
double res;
int sign;
(pom) ? 0 : error("Invalid syntax");
if (ft_strchr(pom, '.'))
{
dem = ft_strsplit(pom, '.');
dem[2] ? error("Invalid number") : 0;
if (!ft_strlen(dem[0]) || ft_strlen(dem[0]) > 9)
error("Invalid number");
first = atoi(dem[0]);
sign = (first < 0) ? -1 : 1;
if (!ft_strlen(dem[1]) || ft_strlen(dem[1]) > 9)
error("Invalid number");
second = atoi(dem[1]);
res = (double)first + (sign * ((double)second\
/ pow(10, ft_strlen(dem[1]))));
res = (res == 0) ? destr_cratch(CRATCH, dem) : destr_cratch(res, dem);
return (res);
}
error("Value must be double");
return (0);
}
t_vec minus(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);
}