映像就是点p关于线段p1,p2对称的点x

求映像就要先求出p在线段上的投影点pp,然后把p投影点pp的向量放大两倍并与p点坐标相加,那么就求出了点x

题目:CGL_1_B

AC代码:

#include <iostream>
#include <algorithm>
#include<math.h>
#include<iomanip>
#include<cstdio>
using namespace std;

class Point
{
public:
    double x, y;
    Point()
    {
    }
    Point(double x, double y)
    {
        (*this).x = x;
        (*this).y = y;
    }

    double operator^(const Point &p) const //叉乘
    {
        return x * p.y - y * p.x;
    }

    double operator*(const Point &p) const //点乘
    {
        return x * p.x + y * p.y;
    }

    Point operator*(const double &d) const
    {
        return Point(x * d, y * d);
    }

    Point operator/(const double &d) const
    {
        return Point (x/d,y/d);
    }

    Point operator-(const Point &p) const
    {
        return Point(x - p.x, y - p.y);
    }

    Point operator+(const Point &p) const
    {
        return Point(x+p.x,y+p.y);
    }

    double sqr()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(sqr());
    }


    void print()
    {
        
        printf("%.10lf %.10lf\n",x,y);
    }

};

int main()
{
    

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    Point p1 = Point(x1, y1);
    Point p2 = Point(x2, y2);

    Point line = p2 - p1;

    int q;
    cin >> q;

    double x0, y0;
    Point p;
    while (q--)
    {
        cin >> x0 >> y0;
        p = Point(x0, y0);

        Point pp;
        pp = p1 + line * ((p - p1) * line) / line.sqr();
        pp=pp-p;

        Point ans = p+pp*2;
        ans.print();

    }

转载请注明来源:https://www.longjin666.top/?p=780

欢迎关注我的公众号“灯珑”,让我们一起了解更多的事物~

你也可能喜欢

发表评论