-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgeometry.h
93 lines (70 loc) · 2.75 KB
/
geometry.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* geometry.h
Header file for geometric data types
by: Steven Skiena
*/
/*
Copyright 2003 by Steven S. Skiena; all rights reserved.
Permission is granted for use in non-commerical applications
provided this copyright notice remains intact and unchanged.
This program appears in my book:
"Programming Challenges: The Programming Contest Training Manual"
by Steven Skiena and Miguel Revilla, Springer-Verlag, New York 2003.
See our website www.programming-challenges.com for additional information.
This book can be ordered from Amazon.com at
http://www.amazon.com/exec/obidos/ASIN/0387001638/thealgorithmrepo/
*/
#include "bool.h"
#define PI 3.1415926 /* ratio of circumference to diameter */
#define EPSILON 0.000001 /* a quantity small enough to be zero */
typedef struct {
double a; /* x-coefficient */
double b; /* y-coefficient */
double c; /* constant term */
} line;
#define DIMENSION 2 /* dimension of points */
#define X 0 /* x-coordinate index */
#define Y 1 /* y-coordinate index */
typedef double point[DIMENSION];
#define MAXPOLY 200 /* maximum number of points in a polygon */
typedef struct {
int n; /* number of points in polygon */
point p[MAXPOLY]; /* array of points in polygon */
} polygon;
typedef struct {
point p1, p2; /* endpoints of line segment */
} segment;
typedef point triangle[3]; /* triangle datatype */
typedef struct {
int n; /* number of triangles in triangulation */
int t[MAXPOLY][3]; /* indicies of vertices in triangulation */
} triangulation;
typedef struct {
point c; /* center of circle */
double r; /* radius of circle */
} circle;
/* Comparison macros */
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
void points_to_line(point p1, point p2, line *l);
void point_and_slope_to_line(point p, double m, line *l);
bool parallelQ(line l1, line l2);
bool same_lineQ(line l1, line l2);
void intersection_point(line l1, line l2, point p);
void closest_point(point p_in, line l, point p_c);
double distance(point a, point b);
void copy_point(point a, point b);
void swap_point(point a, point b);
void points_to_segment(point a, point b, segment *s);
void segment_to_points(segment s, point p1, point p2);
bool point_in_box(point p, point b1, point b2);
bool segments_intersect(segment s1, segment s2);
double signed_triangle_area(point a, point b, point c);
double triangle_area(point a, point b, point c);
bool ccw(point a, point b, point c);
bool cw(point a, point b, point c);
bool collinear(point a, point b, point c);
void print_points(point p[], int n);
void print_polygon(polygon *p);
void print_point(point p);
void print_line(line l);
void print_segment(segment s);