码迷,mamicode.com
首页 > 其他好文 > 详细

计算几何。。。?

时间:2018-05-26 23:24:12      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:pre   运算   struct   几何   poi   typedef   har   计算几何   SQ   

没过,不知道哪错了,有人帮我debug吗?

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef double db;
struct point
{
	db x,y;
	point(){}
	point(db _x,db _y)
	{
		x = _x;
		y = _y;
	} 
	friend point operator + (const point &a,const point &b)//重载运算符
	{
		return point(a.x + b.x,a.y + b.y);
	}
	friend point operator - (const point &a,const point &b)
	{
		return point(a.x - b.x,a.y + b.y);
	}
	friend point operator * (const point &a,const db d) 
	{
		return point(a.x * d,a.y *d); 
	}
	friend db operator * (const point &a,const point &b)//叉乘 
	{
		return a.x * b.y - a.y * b.x;
	}
	db norm()
	{
		return sqrt(x * x + y * y);
	}
	friend db dot(const point &a,const point &b)
	{
		return a.x * b.x + a.y * b.y;
	}//点乘
}Point[5];
struct seg
{
	point a,b;
	db d;
	seg(){}
	seg(point _x,point _y)
	{
		a = _x;
		b = _y;
		d = (b.y - a.y) / (b.x - a.x);
	}
	friend point cross(const seg &s,const seg &t)
	{
		db s1 = (s.a - t.a) * (t.b - t.a);
		db s2 = (s.b - t.b) * (t.a - t.b);
		return s.a + (s.b - s.a) * (s1/(s1 + s2));
	}
}Seg[3];
int main()
{
	db x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	Seg[1] = seg(point(x1,y1),point(x2,y2));
	cin>>x1>>y1>>x2>>y2;
	Seg[2] = seg(point(x1,y1),point(x2,y2));
	printf("%lf",cross(Seg[1],Seg[2]));
	return 0;
}

 

计算几何。。。?

标签:pre   运算   struct   几何   poi   typedef   har   计算几何   SQ   

原文地址:https://www.cnblogs.com/DukeLv/p/9094653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!