poj 2624 4th Point

本篇介绍了一个计算几何问题的解决方法,通过给定平行四边形的两个相邻边的端点坐标,计算出平行四边形的第四个顶点坐标。使用了向量运算,并提供了完整的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4th Point
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5066 Accepted: 1765

Description

Given are the (x,y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the (x,y) coordinates of the fourth point.

Input

Each line of input contains eight floating point numbers: the (x,y) coordinates of one of the endpoints of the first side followed by the (x,y) coordinates of the other endpoint of the first side, followed by the (x,y) coordinates of one of the endpoints of the second side followed by the (x,y) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between -10000 and +10000.

Output

For each line of input, print the (x,y) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.

Sample Input

0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145

Sample Output

1.000 0.000
-2.500 -2.500
0.151 -0.398

Source



题意:给出平行四边形的两邻边的端点坐标,求第四个点的坐标。

一开始没怎么看题目,看了一下input就默认第二点和第三点为两条邻边的的连接点了,知道错了之后就把代码改得这么长了(-_-;)


很奇怪的是用g++上交就WA,c++就AC,也是很迷


#include<iostream>
#include<cstdio>
#include<cmath>
#define esp 1e-8

struct Point
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y) {}
};
typedef Point Vector;
Vector operator + (Vector A,Vector B)
{
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator - (Vector A,Vector B)
{
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (Vector A,double p)
{
    return Vector(A.x*p,A.y*p);
}
Vector operator / (Vector A,double p)
{
    return Vector(A.x/p,A.y/p);
}

int dcmp(double x)  
{
    if(fabs(x)<esp) return 0;
    else return x<0?-1:1;
}
bool operator == (const Point& a,const Point& b)
{
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y)==0;
}


int main()
{
    //freopen("in.txt","r",stdin);
    Vector a,b,c,d;
    while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y))
    {
        if(a==b)
        {
            Vector Ans=d-a-(b-c);
            printf("%.3lf %.3lf\n",Ans.x+a.x,Ans.y+a.y);
        }
        if(a==c)
        {
            Vector Ans=d-c-(a-b);
            printf("%.3lf %.3lf\n",Ans.x+c.x,Ans.y+c.y);
        }
        if(a==d)
        {
            Vector Ans=c-d-(a-b);
            printf("%.3lf %.3lf\n",Ans.x+a.x,Ans.y+a.y);
        }
        if(b==c)
        {
            Vector Ans=d-c-(b-a);
            printf("%.3lf %.3lf\n",Ans.x+c.x,Ans.y+c.y);
        }
        if(b==d)
        {
            Vector Ans=c-d-(b-a);
            printf("%.3lf %.3lf\n",Ans.x+b.x,Ans.y+b.y);
        }
        if(c==d)
        {
            Vector Ans=b-c-(d-a);
            printf("%.3lf %.3lf\n",Ans.x+c.x,Ans.y+c.y);
        }
    }
    return 0;
}


数据类型向量(vector)的模板借鉴于
计算几何基础——【点积和叉积的用处】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值