浮點幾何函式庫

2021-07-17 04:05:15 字數 2582 閱讀 5568

#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 xmult(double x1,double y1,double x2,double y2,double x0,double y0)

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

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

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

//兩點距離

double distance(point p1,point p2)

double distance(double x1,double y1,double x2,double y2)

//判三點共線

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

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

int dot_online_in(point p,line l)

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

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

int dot_online_ex(point p,line l)

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

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

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

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

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)

//計算兩直線交點,注意事先判斷直線是否平行!

//線段交點請另外判線段相交(同時還是要判斷是否平行!)

point intersection(line u,line v)

point intersection(point u1,point u2,point v1,point v2)

//點到直線上的最近點

point ptoline(point p,line l)

point ptoline(point p,point l1,point l2)

//點到直線距離

double disptoline(point p,line l)

double disptoline(point p,point l1,point l2)

double disptoline(double x,double y,double x1,double y1,double x2,double y2)

//點到線段上的最近點

point ptoseg(point p,line l)

point ptoseg(point p,point l1,point l2)

//點到線段距離

double disptoseg(point p,line l)

double disptoseg(point p,point l1,point l2)

//向量v以p為頂點逆時針旋轉angle並放大scale倍

point rotate(point v,point p,double angle,double scale)

整數幾何函式庫

注意某些情況下整數運算會出界 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 x...

函式庫檔案

乙個很簡單的問題除錯了好久,不過還算有收穫。現總結一下 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函式...