TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcimgp
point.c
Go to the documentation of this file.
1
5
/***********************************************************************/
6
7
/***********************************************************************/
8
#include "
libtpcimgp.h
"
9
/***********************************************************************/
10
11
/***********************************************************************/
15
int
pRound
(
17
float
number
18
) {
19
if
(number - floor(number) < 0.5){
20
return
floor(number);
21
}
22
return
ceil(number);
23
}
24
/***********************************************************************/
25
26
/***********************************************************************/
31
float
getDistance
(
33
point
begin,
35
point
end
36
) {
37
float
dx, dy, dz;
38
39
dx = begin.
x
- end.
x
;
// Difference in x coordinates.
40
dy = begin.
y
- end.
y
;
// Difference in y coordinates.
41
dz = begin.
z
- end.
z
;
// Difference in z coordinates.
42
return
sqrt(dx*dx + dy*dy + dz*dz);
43
}
44
/***********************************************************************/
45
46
/***********************************************************************/
55
float
getAngle
(
57
point
begin,
59
point
center
60
) {
61
float
dx, dy;
62
dx = begin.
x
- center.
x
;
// Difference in x coordinates.
63
dy = begin.
y
- center.
y
;
// Difference in y coordinates.
64
65
// Check trivial cases.
66
if
(dx == 0.0){
67
if
(dy == 0.0)
return
-360.0;
68
if
(dy > 0.0)
return
90.0;
69
else
return
270.0;
70
}
71
if
(dy==0.0){
72
if
(dx > 0.0)
return
0.0;
73
else
return
180.0;
74
}
75
76
// If it was not a trivial case, then calculate angle in...
77
// ...the second and the third quarter.
78
if
(dx<0.0)
return
180.0 + atan(dy/dx)*180.0/M_PI;
79
80
// ...the first quarter.
81
if
(dy>0.0)
return
atan(dy/dx)*180.0/M_PI;
82
83
// ...the fourth quarter.
84
return
360.0 + atan(dy/dx)*180.0/M_PI;
85
}
86
/***********************************************************************/
87
88
/***********************************************************************/
libtpcimgp.h
Header file for libtpcimgp.
getAngle
float getAngle(point begin, point center)
Definition
point.c:55
getDistance
float getDistance(point begin, point end)
Definition
point.c:31
pRound
int pRound(float number)
Definition
point.c:15
point
Definition
libtpcimgp.h:41
point::z
float z
Definition
libtpcimgp.h:47
point::y
float y
Definition
libtpcimgp.h:45
point::x
float x
Definition
libtpcimgp.h:43
Generated on
for TPCCLIB by
1.17.0