#include <iostream>
#include <math.h> 

using std::cout;
using std::endl;

struct Vector2D
{
    float x, y;
    Vector2D() : x(0), y(0) {}
    Vector2D(float x, float y) : x(x), y(y) {}
    Vector2D operator -(const Vector2D& v) const
    {
        return (Vector2D(x - v.x, y - v.y));
    }
    Vector2D operator -(void) const
    {
        return (Vector2D(-x, -y));
    }
    Vector2D operator /(float f) const
    {
    	return (Vector2D(x / f, y / f));
    }
};

// constants
const float chunkSize = 512;
const Vector2D minimapCenter(627, 135);

float distance(const Vector2D& a, const Vector2D& b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

void rotate(Vector2D& p, float theta)
{
    p.x = cos(theta) * p.x - sin(theta) * p.y;
    p.y = sin(theta) * p.x + cos(theta) * p.y;
}

float getTheta(const Vector2D& v)
{
    return atan2(v.y,v.x) - atan2(-1 , 0); // b(0, -1)
}

Vector2D getRelativePosition(const Vector2D& vert0, const Vector2D& vert1)
{
    Vector2D p = vert0 - minimapCenter;
    rotate(p, getTheta(vert0 - vert1));
    return -p / (distance(vert0, vert1) / chunkSize);
}

int main()
{
    // input
    Vector2D vert0(309.88147, -144.74777); // top left
    Vector2D vert1(305.99057, 389.2381); // bottom left
    
    Vector2D p = getRelativePosition(vert0, vert1);
    cout << "Relative position = (" << p.x << ", " << p.y << ")" << endl;
    return 0;
}
