Obtain Polar Coordinate from specific origin

  c++, coordinates, polar-coordinates

Let’s say I have a list of points represented in cartesian coordinates (Ex. (x,y)). I’m trying to grab one of those points, and make it the origin of a polar plane, and get the polar coordinates of all of the other points.

Right now I have this:

This is my point struct

struct point
{

    float x;
    float y;
    string type;
    float toDegrees = (180/3.1416);

    point(float x, float y)
    {
        this->x = x;
        this->y = y;
    }

    void makePolar()
    {
        float oldX = this->x;
        float oldY = this->y;
        this->x = sqrt(pow(oldX, 2) + pow(oldY, 2));
        this->y = atan(oldY/oldX) * toDegrees;
        if (this->y < 0)
        {
            this->y = 360 + this->y;
        }
    }
};

And here is where I’m trying to do what I just explained

    for (int i = 0; i < points.size(); i++)
    {
        for (int j = 0; j < points.size(); j++)
        {
            point temp = points[j];
            if (points[i].x != points[j].x && points[i].y != points[j].y)
            {
                temp.x += points[i].x;
                temp.y += points[i].y;
                temp.makePolar();
            }
        }
    }

In this snippet, "points" is a vector<point>.

Source: Windows Questions C++

LEAVE A COMMENT