整數幾何函式庫

2021-07-17 04:06:22 字數 1628 閱讀 8842

//注意某些情況下整數運算會出界!

#define sign(a) ((a)>0?1:(((a)<0?-1:0)))

struct point;

struct line;

//計算cross product (p1-p0)x(p2-p0)

int xmult(point p1,point p2,point p0)

int xmult(int x1,int y1,int x2,int y2,int x0,int y0)

//計算dot product (p1-p0).(p2-p0)

int dmult(point p1,point p2,point p0)

int dmult(int x1,int y1,int x2,int y2,int x0,int y0)

//判三點共線

int dots_inline(point p1,point p2,point p3)

int dots_inline(int x1,int y1,int x2,int y2,int x3,int y3)

int dot_online_in(point p,line l)

int dot_online_in(point p,point l1,point l2)

int dot_online_in(int x,int y,int x1,int y1,int x2,int y2)

int dot_online_ex(point p,line l)

int dot_online_ex(point p,point l1,point l2)

int dot_online_ex(int x,int y,int x1,int y1,int x2,int y2)

//判兩點在直線同側,點在直線上返回0

int same_side(point p1,point p2,line l)

int same_side(point p1,point p2,point l1,point l2)

//判兩點在直線異側,點在直線上返回0

int opposite_side(point p1,point p2,line l)

int opposite_side(point p1,point p2,point l1,point l2)

//判兩直線平行

int parallel(line u,line v)

int parallel(point u1,point u2,point v1,point v2)

//判兩直線垂直

int perpendicular(line u,line v)

int perpendicular(point u1,point u2,point v1,point v2)

//判兩線段相交,包括端點和部分重合

int intersect_in(line u,line v)

int intersect_in(point u1,point u2,point v1,point v2)

//判兩線段相交,不包括端點和部分重合

int intersect_ex(line u,line v)

int intersect_ex(point u1,point u2,point v1,point v2)

浮點幾何函式庫

include define eps 1e 8 define zero x x 0?x x struct point struct line 計算cross product p1 p0 x p2 p0 double xmult point p1,point p2,point p0 double xm...

函式庫檔案

乙個很簡單的問題除錯了好久,不過還算有收穫。現總結一下 1.vs2008中 math.h 標頭檔案中沒有定義m pi,如果程式確實要用m pi則需自己定義。define m pi 3.14159265358979323846 2.如果程式中自己定義的函式比較多,為了除錯方便使用方便,可以將這些函式都...

標準函式庫

1 rand與srand函式產生偽隨機數 cpp view plain copy print?intrand void void srand unsigned intseed rand返回乙個範圍在0和rand max之間的偽隨機數,為了避免程式每次執行時獲得相同的隨機數序列,可以使用srand函式...