回転変換
win32アプリケーション。
回転変換を行うコードを書いてみた。
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: HDC を使用する描画コードをここに追加してください...
int origin = 1000;
//背景色を設定する
SelectObject(hdc, GetStockObject(GRAY_BRUSH));
Rectangle(hdc, 0, 0, 1980, 1200);
//グリッドを引いて、見やすくする
for (int i = 0; i < origin; i++)
{
SetPixel(hdc, i, origin, 0xffff00);
SetPixel(hdc, origin, i, 0xffff00);
}
//変数の宣言
double a1, a2, b1, b2;
double degree = 60;
double rad = degree * PI / 180.0;
double x, y;
//初期値を、(600, 400)に設定
x = 600.0;
y = 400.0;
MoveToEx(hdc, x + origin, -y + origin, NULL);
LineTo(hdc, origin, origin);
//変換前の座標から、原点に向かって線を引く
//MoveToEx(hdc, x + 800, y + 800, NULL);
//LineTo(hdc, 800, 800);
//一次変換
a1 = cos(rad) * x;
a2 = sin(rad) * x;
b1 = -sin(rad) * y;
b2 = cos(rad) * y;
x = a1 + b1;
y = a2 + b2;
//変換後の座標から、原点に向かって線を引く
SetPixel(hdc, x+ origin, -y+ origin, 0xFF0000);
MoveToEx(hdc, x+ origin, -y+ origin, NULL);
LineTo(hdc, origin, origin);
EndPaint(hWnd, &ps);
}
break;