Petya has recently started working as a programmer in the IT city company that develops computer games.
Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen.
A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c.
The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of(vx, vy) vector.
Enumerate the arrow points coordinates in counter-clockwise order starting from the tip.
The only line of the input contains eight integers px, py, vx, vy ( - 1000 ≤ px, py, vx, vy ≤ 1000, vx2 + vy2 > 0), a, b, c, d(1 ≤ a, b, c, d ≤ 1000, a > c).
Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10 - 9.
8 8 0 2 8 3 4 5
8.000000000000 11.000000000000 4.000000000000 8.000000000000 6.000000000000 8.000000000000 6.000000000000 3.000000000000 10.000000000000 3.000000000000 10.000000000000 8.000000000000 12.000000000000 8.000000000000
题意:
给出图形的朝向和每一段的长度,求图形中的个各个点的坐标
题解:
尝试用了最笨的方法去求解,调试了很久,还是过不去,后来找到了这种非常好的方法:利用向量的运算来实现点的坐标的定位
个人向量知识学的不太好,只是大约理解了这个方法....
注意分别处理点的方向和方向向量在同一个方向上和与之垂直的情况。
#include<stdio.h>
#include<math.h>
using namespace std;
double a,b,c,d;
struct point
{
double x,y;//点
}p,v,s[10];
double sinx,cosx;//控制方向
int main()
{
//freopen("shuju.txt","r",stdin);
while(~scanf("%lf%lf%lf%lf",&p.x,&p.y,&v.x,&v.y))//重要位置
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
double tp=sqrt(v.x*v.x+v.y*v.y);
cosx=v.x/tp;sinx=v.y/tp;//单位向量表述方向
a/=2.0;c/=2.0;
s[0].x=p.x+b*cosx;s[0].y=p.y+b*sinx;
s[1].x=p.x-a*sinx;s[1].y=p.y+a*cosx;
s[6].x=p.x+a*sinx;s[6].y=p.y-a*cosx;
s[2].x=p.x-c*sinx;s[2].y=p.y+c*cosx;
s[5].x=p.x+c*sinx;s[5].y=p.y-c*cosx;
s[3].x=s[2].x-d*cosx;s[3].y+=s[2].y-d*sinx;
s[4].x=s[5].x-d*cosx;s[4].y=s[5].y-d*sinx;
for(int i=0;i<7;++i)
{
printf("%.10f %.10f\n",s[i].x,s[i].y);
}
}
return 0;
}