Last active
December 20, 2015 11:59
-
-
Save anaechavarria/6127727 to your computer and use it in GitHub Desktop.
Solution to problem overlapping maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <sstream> | |
#include <fstream> | |
#include <cassert> | |
#include <cstdlib> | |
#include <cstring> | |
#include <string> | |
#include <cstdio> | |
#include <vector> | |
#include <cmath> | |
#include <queue> | |
#include <stack> | |
#include <map> | |
#include <set> | |
#define D(x) cout << #x " = " << (x) << endl | |
const double EPS = 1e-8; | |
int cmp(double x, double y = 0, double tol = EPS){ | |
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; | |
} | |
const double pi = 2 * acos(0); | |
int main(){ | |
double w, h, x0, y0, s, r; | |
while (cin >> w >> h >> x0 >> y0 >> s >> r){ | |
if (w == 0) break; | |
r = r * pi / 180.0; | |
s = s / 100.0; | |
// Los puntos del mapa pequeño se pueden expresar así | |
// rotar (r), escalar (s) y trarladar (x0, y0) el punto original | |
// [nx] = [s * cos r -s * sin r] [x] + [x0] | |
// [ny] = [s * sin r s * cos r] [y] + [y0] | |
// Un punto igual en los dos mapas cumple que nx = x and ny = y | |
// [x] = [s * cos r -s * sin r] [x] + [x0] | |
// [y] = [s * sin r s * cos r] [y] + [y0] | |
// Despejando | |
// [x] - [s * cos r -s * sin r] [x] = [x0] | |
// [y] - [s * sin r s * cos r] [y] = [y0] | |
// Reescribiendo | |
// [1 0] [x] - [s * cos r -s * sin r] [x] = [x0] | |
// [0 1] [y] - [s * sin r s * cos r] [y] = [y0] | |
// Factor común | |
// { [1 0] - [s * cos r -s * sin r] } [x] = [x0] | |
// { [0 1] - [s * sin r s * cos r] } [y] = [y0] | |
// Sumando | |
// [ 1 - s * cos r s * sin r ] [x] = [x0] | |
// [ -s * sin r 1 - s * cos r] [y] = [y0] | |
// Se tiene un sistema de la forma Ax = b | |
// Hallar la inversa de A | |
// A = [a b] Inv(A) = __1__ [d -b] | |
// [c d] det(A) [-c a] | |
double a = 1 - s * cos(r); | |
double b = s * sin(r); | |
double c = -s * sin(r); | |
double d = 1 - s * cos(r); | |
double det = a * d - c * b; | |
assert(cmp(det) != 0); | |
// x = Inv(A) * b | |
// [x] = (d * x0 - b * y0) / det(A) | |
// [y] = (-c * x0 + a * y0) / det(A) | |
double x = (d * x0 - b * y0) / det; | |
double y = (-c * x0 + a * y0) / det; | |
printf("%.2lf %.2lf\n", x, y); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment