KiCad PCB EDA Suite
math_for_graphics.h
Go to the documentation of this file.
1 #ifndef MATH_FOR_GRAPHICS_H
2 #define MATH_FOR_GRAPHICS_H
3 // math stuff for graphics, from FreePCB
4 
5 /* Function FindLineSegmentIntersection
6  * find intersection between line y = a + bx and line segment (xi,yi) to (xf,yf)
7  * if b > DBL_MAX/10, assume vertical line at x = a
8  * return false if no intersection or true if intersect
9  * return coords of intersections in *x1, *y1, *x2, *y2
10  * if no intersection, returns min distance in dist
11  */
12 bool FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int yf,
13  double * x1, double * y1, double * x2, double * y2, double * dist=NULL );
14 
15 /* Function FindSegmentIntersections
16  * find intersections between line segment (xi,yi) to (xf,yf)
17  * and line segment (xi2,yi2) to (xf2,yf2)
18  * returns true if intersection found
19  */
20 bool FindSegmentIntersections( int xi, int yi, int xf, int yf,
21  int xi2, int yi2, int xf2, int yf2 );
22 
36 bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y1f,
37  int x2i, int y2i, int x2f, int y2f,
38  int * x=NULL, int * y=NULL, double * dist=NULL );
39 
40 /* Function GetClearanceBetweenSegments
41  * Get clearance between 2 segments
42  * Returns coordinates of the closest point between these 2 segments in x, y
43  * If clearance > max_cl, just returns max_cl+1 and doesn't return x,y
44  */
45 int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int w1,
46  int x2i, int y2i, int x2f, int y2f, int w2,
47  int max_cl, int * x, int * y );
48 
56 double GetPointToLineSegmentDistance( int x, int y, int xi, int yi, int xf, int yf );
57 
58 /* Function GetPointToLineDistance
59  * Get min. distance from (x,y) to line y = a + bx
60  * if b > DBL_MAX/10, assume vertical line at x = a
61  * returns closest point on line in xpp, ypp
62  */
63 double GetPointToLineDistance( double a, double b, int x, int y,
64  double * xp=NULL, double * yp=NULL );
65 
66 inline double Distance( double x1, double y1, double x2, double y2 )
67 {
68  return hypot( x1 - x2, y1 - y2 );
69 }
70 
71 #endif
static const int dist[10][10]
Definition: dist.cpp:57
double GetPointToLineDistance(double a, double b, int x, int y, double *xp=NULL, double *yp=NULL)
bool FindSegmentIntersections(int xi, int yi, int xf, int yf, int xi2, int yi2, int xf2, int yf2)
double GetPointToLineSegmentDistance(int x, int y, int xi, int yi, int xf, int yf)
Function GetPointToLineSegmentDistance Get distance between line segment and point.
int GetClearanceBetweenSegments(int x1i, int y1i, int x1f, int y1f, int w1, int x2i, int y2i, int x2f, int y2f, int w2, int max_cl, int *x, int *y)
bool FindLineSegmentIntersection(double a, double b, int xi, int yi, int xf, int yf, double *x1, double *y1, double *x2, double *y2, double *dist=NULL)
double Distance(double x1, double y1, double x2, double y2)
bool TestForIntersectionOfStraightLineSegments(int x1i, int y1i, int x1f, int y1f, int x2i, int y2i, int x2f, int y2f, int *x=NULL, int *y=NULL, double *dist=NULL)
Function TestForIntersectionOfStraightLineSegments Test for intersection of line segments If lines ar...