TPCCLIB
Loading...
Searching...
No Matches
point.c File Reference

A three dimensional point. More...

#include "libtpcimgp.h"

Go to the source code of this file.

Functions

int pRound (float number)
float getDistance (point begin, point end)
float getAngle (point begin, point center)

Detailed Description

A three dimensional point.

Author
Riku Klén

Definition in file point.c.

Function Documentation

◆ getAngle()

float getAngle ( point begin,
point center )

Calculates xy-projection of angle FCX in degrees, where F=first point, C=centre point and X=point with higher x coordinate (y and z coordinate remain the same).

This is used to calculate polar angle with two dimensional points (z=constant).

Returns
Angle first - centre - x in degrees (0-360) and -360.0 if first point is equal to centre point.
See also
getDistance
Parameters
beginFirst point.
centerCentre point.

Definition at line 55 of file point.c.

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}
float y
Definition libtpcimgp.h:45
float x
Definition libtpcimgp.h:43

◆ getDistance()

float getDistance ( point begin,
point end )

Calculate distance between points

See also
getAngle
Returns
Distance.
Parameters
beginFirst point
endSecond point

Definition at line 31 of file point.c.

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}
float z
Definition libtpcimgp.h:47

◆ pRound()

int pRound ( float number)

Round float to int.

Returns
Rounded value.
Parameters
numberAny number

Definition at line 15 of file point.c.

18 {
19 if(number - floor(number) < 0.5){
20 return floor(number);
21 }
22 return ceil(number);
23}