Find the Point

Consider two points,  and . We consider the inversion or point reflection, , of point  across point  to be a  rotation of point  around .

Given  sets of points  and , find  for each pair of points and print two space-separated integers denoting the respective values of  and  on a new line.

Example:

Input:  px = 0, py = 0, qx = 1, qy = 1
Output: 2 2

Approach

C++

#include <bits/stdc++.h>
using namespace std;

vector<intfindPoint(int pxint pyint qxint qy)
{

    vector<intres;
    int rx = 2 * qx - px;
    int ry = 2 * qy - py;

    res.push_back(rx);
    res.push_back(ry);
    return res;
}

int main()
{

    int px = 0py = 0;
    int qx = 1qy = 1;

    vector<intresult = findPoint(pxpyqxqy);
    for (size_t i = 0i < result.size(); i++)
    {
        cout << result[i];

        if (i != result.size() - 1)
        {
            cout << " ";
        }
    }
    cout << "\n";

    return 0;
}


No comments:

Post a Comment