已知矩形的任意三个点,求第四个点

      做car的旅行路线遇到的,先用向量法找出直角边,再利用对角线上的点横坐标之和等于中点横坐标的二倍求出。

 

 

#include

struct zuobiao
{
    int x,y;
};

zuobiao qiudian(int x1,int y1,int x2,int y2,int x3,int y3)
{
    zuobiao g;
    g.x=x1+x3-x2;g.y=y1+y3-y2;
    return g;
}

int main()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int x1,y1,x2,y2,x3,y3;
    zuobiao g;
    scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
    if((x1-x2)*(x2-x3)+(y1-y2)*(y2-y3)==0)
    {
        g=qiudian(x1,y1,x2,y2,x3,y3);
    }
    if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)==0)
    {
        g=qiudian(x1,y1,x3,y3,x2,y2);
    }
    if((x1-x3)*(x2-x1)+(y1-y3)*(y2-y1)==0)
    {
        g=qiudian(x3,y3,x1,y1,x2,y2);
    }
    printf("%d %d",g.x,g.y);
    return 0;
}


 

你可能感兴趣的:(已知矩形的任意三个点,求第四个点)