首页 > 代码库 > Geometry
Geometry
模版 未完成
#include <bits/stdc++.h>using namespace std;/*点、直线、线段、三角形、正方形、矩形、凸多边形、多边形点/向量与点/向量: 旋转 点积叉积 定比分点 判平行 求两点的中垂线 * 判三点共线直线与直线: 判关系 求交点 求距离线段与直线: 判关系 求交点线段与线段: 判关系(端点) 求交点点与直线: 判关系 求对称点 求距离 最近点点与线段: 判关系 求距离 最近点 * 两点在线段同侧/异侧* 镜面反射问题*/const double eps = 1e-8;const double pi = acos(-1.0);inline int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}//弧度与角度互换double radian_to_angle(double r) {return r*180/pi;}double angle_to_radian(double a) {return a*pi/180;}struct point { double x,y; point(double _x=0, double _y=0) {x=_x;y=_y;} void in() {scanf("%lf%lf",&x,&y);} void out() {printf("%lf %lf\n",x,y);} friend bool operator < (point &a, point &b) {return a.x<b.x || (a.x==b.x && a.y<b.y);} friend point operator + (point &a, point &b) {return point(a.x+b.x,a.y+b.y);} friend point operator - (point &a, point &b) {return point(a.x-b.x,a.y-b.y);} friend double operator * (point a, point b) {return a.x*b.x+a.y*b.y;} friend double operator ^ (point a, point b) {return a.x*b.y-a.y*b.x;} void transXY(double B) // 逆时针旋转B度,B是弧度 { double tx = x, ty = y; x = tx*cos(B) - ty*sin(B); y = tx*sin(B) + ty*cos(B); }};typedef point Vector;double dot(point &a,point &b) {return a*b;}double cross(point &a, point &b) {return a^b;}double dist(point &a, point &b) {return sqrt((a-b)*(a-b));}bool Vector_para(Vector a, Vector b){ return dcmp(a^b)==0;}bool three_point_in_line(point &a,point &b,point &c){ return Vector_para(b-a,c-a);}struct line { point u,v; double a,b,c; line() {} line(point _u,point _v) { u=_u,v=_v; a = v.y-u.y; b = -(v.x-u.x); c = v.y*(v.x-u.x)-v.x*(v.y-u.y); }};// 判断两直线位置,0重合,1平行,2相交//verson1: use u,vint judge_2line_coincide_or_para_or_inter_v1(line &a,line &b){ if(dcmp((a.u-a.v)^(b.u-b.v))==0) return dcmp((a.u-b.v)^(b.u-b.v))!=0; else return 2;}//verson2: use a,b,cint judge_2line_coincide_or_para_or_inter_v2(line &a,line &b){ if(dcmp(a.a*b.b-b.a*a.b)==0) return dcmp(a.a*b.c-a.c*b.a)!=0; else return 2;}// 求两直线交点,需要先判重合平行//verson1: use u,vpoint interpoint_of_2line(line &a,line &b){ point res = a.u; double t = ((a.u-b.u)^(b.u-b.v))/((a.u-a.v)^(b.u-b.v)); res.x += (a.v.x-a.u.x)*t; res.y += (a.v.y-a.u.y)*t; return res;}//verson2://判断两线段相交int main(){ freopen("case.txt","r",stdin); point a,b; int _; cin>>_; while(_--) { a.in(); b.in(); cout<<Vector_para(a,b)<<endl; } return 0;}
Geometry
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。