//多邊形切割
//可用於半平面交
#define maxn 100
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))
struct point;
double xmult(point p1,point p2,point p0)
int same_side(point p1,point p2,point l1,point l2)
point intersection(point u1,point u2,point v1,point v2)
//將多邊形沿
l1,l2
確定的直線切割在
side
側切割,
保證l1,l2,side
不共線
void polygon_cut(int& n,point* p,point l1,point l2,point side)
for (n=i=0;i
if (!i||!zero(pp[i].x-pp[i-1].x)||!zero(pp[i].y-pp[i-1].y))
p[n++]=pp[i];
if (zero(p[n-1].x-p[0].x)&&zero(p[n-1].y-p[0].y))
n--;
if (n<3)
n=0; }
//浮點幾何函式庫
#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)
,0int same_side(point p1,point p2,line l)
int same_side(point p1,point p2,point l1,point l2)
,0int 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)
求任意多邊形面積(凹多邊形和凸多邊形)
遇到問題 已知多邊形的各個左邊點,要求多邊形的面積 然後我搜尋了下看到這篇文章 這個人說的不多,但是簡單明瞭 首先已知各定點的座標分別為 x1,y1 x2,y2 x3,y3 xn,yn 則該多邊形的面積公式為 s 1 2 x1 y2 x2 y1 x2 y3 x3 y2 xk yk 1 xk 1 yk...
驗證多邊形是否為凸多邊形
驗證多邊形是否為凸多邊形 2108 shape of hdu include define debug 0 int crossmulti int x0,int y0,int x1,int y1,int x2,int y2 int main int n,i int f x,f y 第1個點 int s...
Visual C 遊戲程式設計基礎之多邊形繪製
以 0,0 為圓心,半徑為100的圓,它的內接五邊形就是它均分五等分的點連起來,座標 x,y 分別為 100 sin 72 100 cos 72 100 sin 72 2 100 cos 72 2 1.bool polyline hdchdc,const point lppt,int cpoints...