【数学几何】 已知正方形相邻两点的坐标,求另外两点的坐标

UPC Contest2219 L题 Ruined Square

在比赛的时候想了许久,终究还是没弄出来,刚看到一个博客里展示了一个图,顿时就想着可以试试把他推出来了,结果,这不,出来了,哈哈哈哈
给我机会推出来的那张图

题目描述:

There is a square in the xy-plane. The coordinates of its four vertices are (x1,y1),(x2,y2),(x3,y3) and (x4,y4) 
in counter-	clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)
Takahashi remembers (x1,y1) and (x2,y2), but he has forgot (x3,y3) and (x4,y4).
Given x1,x2,y1,y2, restore x3,y3,x4,y4. It can be shown that x3,y3,x4 and y4 uniquely exist and have integer values.
Constraints
·|x1|,|y1|,|x2|,|y2|≤100
·(x1,y1) ≠ (x2,y2)
·All values in input are integers.

输入:

Input is given from Standard Input in the following format:
x1 y1 x2 y2

输出 :

Print x3,y3,x4 and y4 as integers, in this order.

样例输入:

0 0 0 1

样例输出:

-1 1 -1 0

题解:啥也不说了,全在图里,看大图

【数学几何】 已知正方形相邻两点的坐标,求另外两点的坐标_第1张图片

AC代码:

#include
using namespace std;
int main()
{
	int x1,y1,x2,y2,x3,y3,x4,y4;
	cin>>x1>>y1>>x2>>y2; 
	x3=x2-(y2-y1);
	y3=y2-(x1-x2);
	x4=x1-(y2-y1);
	y4=y1-(x1-x2);
	printf("%d %d %d %d",x3,y3,x4,y4);
	return 0;
}

推出来后,哇!代码这么短小精悍啊!!!

你可能感兴趣的:(【数学几何】 已知正方形相邻两点的坐标,求另外两点的坐标)