POJ 3449 Geometric Shapes(几何相交)

该问题描述了如何处理平面几何图形的相交检测。输入包含一系列图形,包括正方形、矩形、线段、三角形和多边形,需要确定它们之间的相交情况。每个图形由其特定的顶点定义,输出是每个图形与其他图形的相交关系。解决方案涉及判断线段是否相交,并为正方形计算额外的顶点坐标。
摘要由CSDN通过智能技术生成

Description

While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting shapes. It is necessary to detect them and decide how to change the picture.

Given a set of geometric shapes, you are to determine all of their intersections. Only outlines are considered, if a shape is completely inside another one, it is not counted as an intersection.

Input

Input contains several pictures. Each picture describes at most 26 shapes, each specified on a separate line. The line begins with an uppercase letter that uniquely identifies the shape inside the corresponding picture. Then there is a kind of the shape and two or more points, everything separated by at least one space. Possible shape kinds are:

• square: Followed by two distinct points giving the opposite corners of the square.
• rectangle: Three points are given, there will always be a right angle between the lines connecting the first point with the second and the second with the third.
• line: Specifies a line segment, two distinct end points are given.
• triangle: Three points are given, they are guaranteed not to be co-linear.
• polygon: Followed by an integer number N (3 ≤ N ≤ 20) and N points specifying vertices of the polygon in either clockwise or anti-clockwise order. The polygon will never intersect itself and its sides will have non-zero length.

All points are always given as two integer coordinates X and Y separated with a comma and enclosed in parentheses. You may assume that |X|, |Y | ≤ 10000.

The picture description is terminated by a line containing a single dash (“-”). After the last picture, there is a line with one dot (“.”).

Output

For each picture, output one line for each of the shapes, sorted alphabetically by its identifier (X). The line must be one of the following:

• “X has no intersections”, if X does not intersect with any other shapes.
• “X intersects with A”, if X intersects with exactly 1 other shape.
• “X intersects with A and B”, if X intersects with exactly 2 other shapes.
• “X intersects with A, B, …, and Z”, if X intersects with more than 2 other shapes.

Please note that there is an additional comma for more than two intersections. A, B, etc. are all intersecting shapes, sorted alphabetically.

Print one empty line after each picture, including the last one.

Sample Input

A square (1,2) (3,2)
F line (1,3) (4,4)
W triangle (3,5) (5,5) (4,3)
X triangle (7,2) (7,4) (5,3)
S polygon 6 (9,3) (10,3) (10,4) (8,4) (8,1) (10,2)
B rectangle (3,3) (7,5) (8,3)

-
B square (1,1) (2,2)
A square (3,3) (4,4)

-
.
Sample Output

A has no intersections
B intersects with S, W, and X
F intersects with W
S intersects with B
W intersects with B and F
X intersects with B

A has no intersections
B has no intersections

大致题意:给你若干个平面几何的信息,问它们之间的相交关系。如果是线段,则告诉你两个端点的位置,如果是三角形,则告诉你三个端点的位置,如果是正方形,则告诉你对角线上的两个端点的位置,如果是矩形,则告诉你三个端点的位置,如果是n个点的多边形,则告诉你n个端点的位置。

思路:判断两个几何是否相交,只要判断它们的所有线段是否相交即可。然后对于正方形我们还需要求先出它的另外两个点的坐标。
已知 (x0,y0) 和(x2,y2) 可以根据下列关系求(x1,y1),(x3,y3)

x1+x3 = x0+x2;
x1-x3 = y2-y0;
y1+y3 = y0-y2;
y1-y3 = x0-x2;


x1=(x0+x2+y2-y0)/2;
y1=(x0-x2+y0-y2)/2;
x3=(x0+x2+y0-y2)/2;
y3=(x2-x0+y0-y2)/2;

代码如下

#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const double eps=1e-8;

int dcmp(double x) {
    if(fabs(x)<eps) return 0;
    return x<0?-1:1;
}
struct Point {
    double x,y;
    Point() {}
    Point(double  _x,double _y) {
        x=_x;
        y=_y;
    }
    Point operator-(const Point &b) const {
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point &b)const {
        return x*b.x + y*b.y;
    }
    double operator ^(const Point &b)const {
        return x*b.y - y*b.x;
    }

};
struct Line {
    Point a,b;
    Line() {}
    Line(Point _a,Point _b) {
        a=_a;
        b=_b;
    }
};

int inter(Line L1,Line L2)//判断两条线段是否相交,若相交返回1否则0 
{
    return
        max(L1.a.x,L1.b.x) >= min(L2.a.x,L2.b.x) &&
        max(L2.a.x,L2.b.x) >= min(L1.a.x,L1.b.x) &&
        max(L1.a.y,L1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值