Xmipp  v3.23.11-Nereus
Classes | Enumerations | Functions
point.h File Reference
#include "defines.h"
Include dependency graph for point.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Point_T
 

Enumerations

enum  Turn_T { COLINEAR =1, LEFT_TURN =2, RIGHT_TURN =3 }
 

Functions

int equal_Point (struct Point_T *p1, struct Point_T *p2)
 
int higher_Point (struct Point_T *p1, struct Point_T *p2, int(*f)(struct Point_T *, struct Point_T *))
 
int lower_X (struct Point_T *p1, struct Point_T *p2)
 
int higher_X (struct Point_T *p1, struct Point_T *p2)
 
int higher_Y (struct Point_T *p1, struct Point_T *p2)
 
int lexicographic_Higher (struct Point_T *p1, struct Point_T *p2)
 
void copy_Point (struct Point_T *p1, struct Point_T *p2)
 
TYPE distance (struct Point_T *p, struct Point_T *q)
 
TYPE signed_Area (struct Point_T *p1, struct Point_T *p2, struct Point_T *p3)
 
enum Turn_T check_Turn (struct Point_T *p1, struct Point_T *p2, struct Point_T *p3)
 
int in_Circle (struct Point_T *p1, struct Point_T *p2, struct Point_T *p3, struct Point_T *q)
 
bool interior_Triangle (struct Point_T *p1, struct Point_T *p2, struct Point_T *p3, struct Point_T *q)
 
int has_Extreme_Coordinates (struct Point_T *p)
 
void print_Point (struct Point_T *point)
 

Enumeration Type Documentation

◆ Turn_T

enum Turn_T
Enumerator
COLINEAR 
LEFT_TURN 
RIGHT_TURN 

Definition at line 10 of file point.h.

10 {COLINEAR=1, LEFT_TURN=2, RIGHT_TURN=3};
Definition: point.h:10

Function Documentation

◆ check_Turn()

enum Turn_T check_Turn ( struct Point_T p1,
struct Point_T p2,
struct Point_T p3 
)

Definition at line 73 of file point.cpp.

74 {
75  TYPE area=0.0; // Signed area.
76  enum Turn_T turn; // Return value.
77 
78  // Compute signed area of the triangle formed by p1, p2 and p3.
79  area = signed_Area( p1, p2, p3);
80 
81 #ifdef DEBUG_CHECK_TURN
82  printf("Area %f. P (%lf,%lf). Q (%lf,%lf). R (%lf,%lf)\n", area, p1->x, p1->y, p2->x, p2->y, p3->x, p3->y);
83 #endif
84 
85  // Higher than zero -> turn left.
86  if (area > COLLINEAR_THRESHOLD)
87  {
88 #ifdef DEBUG_CHECK_TURN
89  printf("LEFT\n");
90 #endif
91  turn = LEFT_TURN;
92  }
93  // Lower than zero -> turn right.
94  else if (area < -COLLINEAR_THRESHOLD)
95  {
96 #ifdef DEBUG_CHECK_TURN
97  printf("RIGHT\n");
98 #endif
99  turn = RIGHT_TURN;
100  }
101  // If area is close to zero then points are collinear.
102  else
103  {
104 #ifdef DEBUG_CHECK_TURN
105  printf("COLLINEAR\n");
106 #endif
107  turn = COLINEAR;
108  }
109 
110  return(turn);
111 }
#define COLLINEAR_THRESHOLD
Definition: point.cpp:9
Turn_T
Definition: point.h:10
POINT_T x
Definition: point.h:14
Definition: point.h:10
#define TYPE
Definition: defines.h:47
POINT_T y
Definition: point.h:15
TYPE signed_Area(struct Point_T *p1, struct Point_T *p2, struct Point_T *p3)
Definition: point.cpp:267

◆ copy_Point()

void copy_Point ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 241 of file point.cpp.

242 {
243  // Copy p1 x and y values into p2.
244  p2->x = p1->x;
245  p2->y = p1->y;
246 }
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15

◆ distance()

TYPE distance ( struct Point_T p,
struct Point_T q 
)

Definition at line 28 of file point.cpp.

29 {
30  TYPE dist=0.0;
31 
32  // Compute distance.
33  dist = Euclidean( p, q);
34 
35  return(dist);
36 }
#define TYPE
Definition: defines.h:47
TYPE Euclidean(struct Point_T *p, struct Point_T *q)
Definition: point.cpp:256

◆ equal_Point()

int equal_Point ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 39 of file point.cpp.

40 {
41  int equal=FALSE; // Return value.
42  POINT_T diff=0.0; // Coordinates difference value.
43 
44  // Check if points are too close.
45  diff = p1->x - p2->x;
46  if ((diff < DELTA_DIFF) && (diff > -DELTA_DIFF))
47  {
48  diff = p1->y - p2->y;
49  if ((diff < DELTA_DIFF) && (diff > -DELTA_DIFF))
50  {
51  equal = TRUE;
52  }
53  }
54  else
55  {
56  equal = FALSE;
57  }
58 
59  return(equal);
60 }
#define POINT_T
Definition: defines.h:50
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15
#define FALSE
Definition: defines.h:24
#define TRUE
Definition: defines.h:25
#define DELTA_DIFF
Definition: defines.h:31

◆ has_Extreme_Coordinates()

int has_Extreme_Coordinates ( struct Point_T p)

Definition at line 172 of file point.cpp.

173 {
174  int has_Extreme=FALSE; // Return value.
175 
176  if ((p->x >= MAX_X_COORD) || (p->y >= MAX_Y_COORD) ||
177  (p->x <= -MAX_X_COORD) || (p->y <= -MAX_Y_COORD))
178  {
179  has_Extreme = TRUE;
180  }
181 
182  return(has_Extreme);
183 }
POINT_T x
Definition: point.h:14
#define MAX_Y_COORD
Definition: defines.h:39
POINT_T y
Definition: point.h:15
#define FALSE
Definition: defines.h:24
#define TRUE
Definition: defines.h:25
#define MAX_X_COORD
Definition: defines.h:38

◆ higher_Point()

int higher_Point ( struct Point_T p1,
struct Point_T p2,
int(*)(struct Point_T *, struct Point_T *)  f 
)

Definition at line 62 of file point.cpp.

63 {
64  return((*f)( p1, p2));
65 }
double * f

◆ higher_X()

int higher_X ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 191 of file point.cpp.

192 {
193  // Return true if y coordinate is higher.
194  return(p1->x > p2->x);
195 }
POINT_T x
Definition: point.h:14

◆ higher_Y()

int higher_Y ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 197 of file point.cpp.

198 {
199  // Return true if y coordinate is higher.
200  return(p1->y > p2->y);
201 }
POINT_T y
Definition: point.h:15

◆ in_Circle()

int in_Circle ( struct Point_T p1,
struct Point_T p2,
struct Point_T p3,
struct Point_T q 
)

Definition at line 114 of file point.cpp.

115 {
116  int ret=0; // Return value.
117  POINT_T value=0.0; // Determinant value.
118  POINT_T temp[9]; // Intermediate values.
119 
120  // Compute Ax - Dx, Ay - Dy and (Ax-Dx)² + (Ay-Dy)²
121  temp[0] = (p1->x - q->x);
122  temp[1] = (p1->y - q->y);
123  temp[2] = (POINT_T) (pow((p1->x - q->x), 2) + pow((p1->y - q->y), 2));
124 
125  // Compute Bx - Dx, By - Dy and (Bx-Dx)² + (By-Dy)²
126  temp[3] = (p2->x - q->x);
127  temp[4] = (p2->y - q->y);
128  temp[5] = (POINT_T) (pow((p2->x - q->x), 2) + pow((p2->y - q->y), 2));
129 
130  // Compute Cx - Dx, Cy - Dy and (Cx-Dx)² + (Cy-Dy)²
131  temp[6] = (p3->x - q->x);
132  temp[7] = (p3->y - q->y);
133  temp[8] = (POINT_T) (pow((p3->x - q->x), 2) + pow((p3->y - q->y), 2));
134 
135  // Compute determinant.
136  value = (temp[0]*temp[4]*temp[8]) +
137  (temp[1]*temp[5]*temp[6]) +
138  (temp[2]*temp[3]*temp[7]) -
139  (temp[2]*temp[4]*temp[6]) -
140  (temp[5]*temp[7]*temp[0]) -
141  (temp[8]*temp[1]*temp[3]);
142 
143  // If positive then point q belongs to p1-p2-p3 circumference.
144  if (value > 0.0)
145  {
146  ret = 1;
147  }
148 
149  return(ret);
150 }
#define POINT_T
Definition: defines.h:50
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15

◆ interior_Triangle()

bool interior_Triangle ( struct Point_T p1,
struct Point_T p2,
struct Point_T p3,
struct Point_T q 
)

Definition at line 152 of file point.cpp.

153 {
154  bool is_In_Triangle=false; // Return value.
155 
156  // Check if new point is interior to triangle formed by p1, p2 and p3.
157  if ((signed_Area( p1, p2, q) > 0) &&
158  (signed_Area( p2, p3, q) > 0) &&
159  (signed_Area( p3, p1, q) > 0))
160  {
161  is_In_Triangle = true;
162  }
163  else
164  {
165  is_In_Triangle = false;
166  }
167 
168  return(is_In_Triangle);
169 }
TYPE signed_Area(struct Point_T *p1, struct Point_T *p2, struct Point_T *p3)
Definition: point.cpp:267

◆ lexicographic_Higher()

int lexicographic_Higher ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 211 of file point.cpp.

212 {
213  int higher=FALSE; // Return value.
214 
215  // Check if Y coordinate is higher.
216  if (p1->y > p2->y)
217  {
218  higher = TRUE;
219  }
220  else
221  {
222  // If Y coordinate is equal then check X coordinate.
223  if ((p1->y == p2->y) &&
224  (p1->x > p2->x))
225  {
226  higher = TRUE;
227  }
228  }
229 
230  return(higher);
231 }
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15
#define FALSE
Definition: defines.h:24
#define TRUE
Definition: defines.h:25

◆ lower_X()

int lower_X ( struct Point_T p1,
struct Point_T p2 
)

Definition at line 185 of file point.cpp.

186 {
187  // Return true if y coordinate is higher.
188  return(p1->x < p2->x);
189 }
POINT_T x
Definition: point.h:14

◆ print_Point()

void print_Point ( struct Point_T point)

Definition at line 67 of file point.cpp.

68 {
69  printf("Point (%f, %f)\n", point->x, point->y);
70 }
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15

◆ signed_Area()

TYPE signed_Area ( struct Point_T p1,
struct Point_T p2,
struct Point_T p3 
)

Definition at line 267 of file point.cpp.

268 {
269  double area=0.0; // Return value.
270 
271  area = (- (double) p2->x*p1->y + (double) p3->x*p1->y + (double) p1->x*p2->y -
272  (double) p3->x*p2->y - (double) p1->x*p3->y + (double) p2->x*p3->y);
273 
274  return(area);
275 }
POINT_T x
Definition: point.h:14
POINT_T y
Definition: point.h:15