【计算几何】CDOJ1720 几何几何


#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define EPS 0.00000001
struct Point{
double x,y;
}a[2],b[2];
typedef Point Vector;
Vector operator * (const double &a,const Vector &v){
return (Vector){a*v.x,a*v.y};
}
Vector operator - (const Point &a,const Point &b){
return (Vector){a.x-b.x,a.y-b.y};
}
Vector operator + (const Vector &a,const Vector &b){
return (Vector){a.x+b.x,a.y+b.y};
}
double Cross(const Vector &a,const Vector &b){
return a.x*b.y-a.y*b.x;
}
Point GetIntersection(Point P,Vector v,Point Q,Vector w){
return P+(Cross(w,P-Q)/Cross(v,w))*v;
}
bool inLine(Point p,Point a,Point b){
if(a.x>b.x){
swap(a,b);
}
if(p.x-a.x>-EPS && b.x-p.x>-EPS){
return 1;
}
return 0;
}
int main(){
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a[0].x,&a[0].y,&a[1].x,&a[1].y,&b[0].x,&b[0].y,&b[1].x,&b[1].y)!=EOF){
if(fabs(a[0].y-a[1].y)<EPS || fabs(b[0].y-b[1].y)<EPS){
puts("0.00");
continue;
}
if(fabs(Cross(a[0]-a[1],b[0]-b[1]))<EPS){
puts("0.00");
continue;
}
if(a[0].y<a[1].y){
swap(a[0],a[1]);
}
if(b[0].y<b[1].y){
swap(b[0],b[1]);
}
Point p=GetIntersection(a[0],a[1]-a[0],b[0],b[1]-b[0]);
if((!inLine(p,a[0],a[1])) || (!inLine(p,b[0],b[1]))){
puts("0.00");
continue;
}
if(a[0].y<b[0].y){
swap(a[0],b[0]);
swap(a[1],b[1]);
}
if(fabs(a[0].y-b[0].y)<EPS){
printf("%.2f\n",fabs(a[0].x-b[0].x)*0.5*fabs(p.y-a[0].y));
continue;
}
if((!fabs(a[0].x-a[1].x)<EPS) && (!fabs(b[0].x-b[1].x)<EPS)){
double ka=(a[0].y-a[1].y)/(a[0].x-a[1].x);
double kb=(b[0].y-b[1].y)/(b[0].x-b[1].x);
if((ka>EPS && kb>EPS) || (ka<EPS && kb<EPS)){
if(fabs(ka)-fabs(kb)>EPS){
if((a[0].x-b[0].x<EPS && p.x-b[0].x>-EPS) || (a[0].x-b[0].x>-EPS && p.x-b[0].x<EPS)){
puts("0.00");
continue;
}
}
}
}
double rr=(b[0].y-p.y)/(a[0].y-p.y);
Point bc=p+rr*(a[0]-p);
printf("%.2f\n",0.5*(b[0].y-p.y)*fabs(bc.x-b[0].x));
}
return 0;
}
【计算几何】CDOJ1720 几何几何的更多相关文章
- Geometry 判断几何是否被另一个几何/线段分割成多段
如下图,如何判断几何多边形A被多边形B,切割为多段几何? 几何A被几何B切割 1. 获取几何A与几何B的交集C var intersectGeometry = new CombinedGeometry ...
- [知识点]计算几何I——基础知识与多边形面积
// 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...
- UVA12304 2D Geometry 110 in 1! 计算几何
计算几何: 堆几何模版就能够了. . .. Description Problem E 2D Geometry 110 in 1! This is a collection of 110 (in bi ...
- 计算几何 val.2
目录 计算几何 val.2 几何单位结构体板子 旋转卡壳 基础概念 求法 模板 半平面交 前置芝士:线段交 S&I算法 模板 最小圆覆盖 随机增量法 时间复杂度 模板 后记 计算几何 val. ...
- LA 3263 好看的一笔画 欧拉几何+计算几何模板
题意:训练指南260 #include <cstdio> #include <cstring> #include <algorithm> #include < ...
- NOIP2002矩形覆盖[几何DFS]
题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...
- Direct2D 几何计算和几何变幻
D2D不仅可以绘制,还可以对多个几何图形对象进行空间运算.这功能应该在GIS界比较吃香. 这些计算包括: 合并几何对象,可以设置求交还是求并,CombineWithGeometry 边界,加宽边界,查 ...
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...
- Direct2D教程III——几何(Geometry)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
随机推荐
- 大聊Python----SocketServer
什么是SocketServer? SocketServer的最主要的作用是实现并发处理,也就是可以多个用户同时上传和下载文件. socketserver模块简化了编写网络服务器的任务. sockets ...
- IOException while loading persisted sessions:
严重: IOException while loading persisted sessions: java.io.EOFException java.io.EOFException at java. ...
- mysql in/no in/like
% 任意字符 _ 任意一个字符 in (value,......) 在这里 not in (value,......) 不在这里 mysql> select 'a' not in (1,2,3, ...
- Django-【views】decorators.csrf
views下导入方法 from django.views.decorators.csrf import csrf_exempt,csrf_protect csrf_exempt是全局需要,唯独这个 ...
- iptables 操作
iptables --list 查看列表 iptables删除规则 iptables -nL --line-number Chain INPUT (policy ACCEPT)num target p ...
- C json实战引擎 三 , 最后实现部分辅助函数
引言 大学读的是一个很时髦的专业, 学了四年的游戏竞技. 可惜没学好. 但认真过, 比做什么都认真. 见证了 ...... 打的所有游戏人物中 分享一位最喜爱 的 “I've been alone ...
- webapi-2 接口参数
1. 实例 using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sys ...
- 动画基础--基于Core Animation(3)
参考:https://zsisme.gitbooks.io/ios-/content/ 前面的文章动画基础--基于Core Animation(1),动画基础--基于Core Animation(2) ...
- linux命令--head
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 具体使用参考链接: h ...
- leetcode 之Partition List(16)
思路就是定义两个链表,一个放大的,一个放小的,最后将两个连起来,注意细节问题. ListNode *partionList(ListNode *head, int value) { ListNode ...