点与点 点与线的关系
来源:互联网 发布:mac如何关闭所有程序 编辑:程序博客网 时间:2024/04/30 06:34
//// main.cpp// Richard//// Created by 邵金杰 on 16/8/5.// Copyright © 2016年 邵金杰. All rights reserved.////常用常数double PI=acos(-1);double INF=1e20;double EPS=1e-6;typedef pair<double,double> CPoint;//点typedef pair<CPoint,CPoint> CLine;//线struct CPoint{//点 double x,y; CPoint(double x,double y): x(x),y(y) {}};struct CLine{//线 CPoint a,b; CLine(CPoint a,CPoint b): a(a),b(b) {}};struct CVector{ double x,y; CVector(double x,double y): x(x),y(y) {}};CVector operator * (double k,CVector p){//常数乘矢量 return CVector(k*p.x,k*p.y);}double operator * (CVector p,CVector q){//矢量点乘 return p.x*q.x+p.y*q.y;}double length(CVector p){//求矢量的模长 return sqrt(p*p);}double operator ^ (CVector p,CVector q){//矢量叉积 return p.x*q.y-p.y*q.x;}CVector unit(CVector p){//单位向量 return 1/length(p)*p;}double dot(CVector p,CVector q){//矢量点乘 return p.x*q.x+p.y*q.y;}double project(CVector p,CVector q){//投影 return dot(p,unit(q));}bool IsZero(double x){//判断一个数是否为0(用于浮点数) return x<EPS&&x>-EPS;}bool FLarger(double x,double y){//判断x是否大于y return x-y>EPS;}bool FLess(double x,double y){//判断x是否小于y return y-x>EPS;}CVector operator - (CPoint b,CPoint a){//点a到点b的向量AB,用B-A表示 return CVector(b.x-a.x,b.y-a.y);}CPoint operator + (CPoint a,CVector p){//将点a沿矢量p方向平移矢量p的长度得到点b return CPoint(a.x+p.x,a.y+p.y);}double dist(CPoint p,CPoint q){//求两点间线段的长度 return length(p-q);}double vertical_dist(CPoint p,CLine l){//求直线外一点p到直线l的距离 return fabs((p-l.a)^(l.b-l.a))/length(l.b-l.a);}CPoint rotate(CPoint b,CPoint a,double alpha){//把点b绕点a旋转alpha度到点c,并返回c CVector p=b-a; return CPoint(a.x+(p.x*cos(alpha)-p.y*sin(alpha)),a.y+(p.x*sin(alpha)+p.y*cos(alpha)));}int SideOfLine(CPoint a,CPoint b,CPoint p){//判断p在直线a,b的哪一侧 double result=(b-a)^(p-a); if(IsZero(result)) return 0;//p在直线ab上 else if(result>0) return 1;//p在直线ab左侧 else return -1;//p在直线ab右侧}CLine Vertical(CPoint p,CLine l){//过点p作直线l的垂线 return CLine(p,p+(rotate(l.b,l.a,PI/2)-l.a));}CPoint foot(CPoint p,CLine l){//求垂足 return CPoint(l.a+project(p-l.a,l.b-l.a)*unit(l.b-l.a));}
0 0
- 点与点 点与线的关系
- 点与圆的关系
- 点与线、凸凹四边形的关系。
- room [判断点与线的关系]
- 固定点与极限的关系
- 不动点与极限的关系
- 判断点与菱形的关系
- 判断点与多边形的位置关系
- 判断点与多边形的位置关系
- 点与线段的位置关系-算法
- 判断一个点与圆的关系
- zoj1081(点与多边形的位置关系)
- 计算几何问题汇总--点与线的位置关系
- 计算几何问题汇总--点与线的位置关系
- 点与点之间的碰撞检测
- 判断三角形与点的关系的一种实现
- 故事点与功能点
- Direct3D中投影空间内的点坐标与屏幕上点的对应关系
- Floating Action Buttons
- IOS消息机制之------Hit Testing 伪代码
- Spring MVC 4系列教程翻译 问题答疑
- 学习笔记
- spring--事务原理
- 点与点 点与线的关系
- smarty初步框架
- Can't set headers after they are sent
- Java JVM:内存结构和相关参数
- hdu2222
- priority_queue使用方法【优先队列】
- Linux Core 文件在系统排障中的应用
- mysql远程登录
- hdu2577一道很不错的DP