4th Point
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4943 | Accepted: 1735 |
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
问题描述:已知平行四边形的两条邻边,求第四个点的坐标
解题思路:先确定这两条边的交点,让后使用矢量和,具体看程序
AC的C++程序:
#include<iostream>
#include<cmath>
using namespace std;
const double EPS=1e-10;
struct Point{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
};
//矢量加
Point operator +(Point p,Point q)
{
return Point(p.x+q.x,p.y+q.y);
}
//矢量减
Point operator -(Point p,Point q)
{
return Point(p.x-q.x,p.y-q.y);
}
//判断p和q是否为同一点
bool IsOne(Point p,Point q)
{
return (fabs(p.x-q.x)<EPS&&fabs(p.y-q.y)<EPS);
}
int main()
{
Point 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))
{
Point ans;
if(IsOne(a,c))
{
ans=(b-a)+(d-a)+a;
}
else if(IsOne(a,d))
{
ans=(b-a)+(c-a)+a;
}
else if(IsOne(b,c))
{
ans=(a-b)+(d-b)+b;
}
else if(IsOne(b,d))
{
ans=(a-b)+(c-d)+b;
}
printf("%.3lf %.3lf\n",ans.x,ans.y);
}
return 0;
}