現在地 >> メニュー >> サンプルコード::OpenGL >> 座標系の変換

問題


x-y座標系の原点(0,0)を中心に、
角度θだけ回転した座標系(r,t)を設定する。

この時、x,yの座標、回転角を入力すると、
(r,t)座標系では、どんな数値になるかを出力するプログラムを作成せよ。

答え


#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

#define PI_OVER_180 0.0174532925

int main(int argc,char*argv[])
{

double x,y;
double r,t;
int theta;

while(1){

cout<<"(x,y,θ)=? ";
cin >> x >> y >> theta;

cout << endl;

printf("(x,y,θ)=(%f,%f,%d) \n",x,y,theta );

cout <<"Radon trans !"<< endl;

r = x * cos(theta*PI_OVER_180) + y * sin(theta*PI_OVER_180);
t = -x * sin(theta*PI_OVER_180) + y * cos(theta*PI_OVER_180);

printf("(r,t)=(%f,%f) \n\n",r,t);

}


return 0;
}

メモ


(r,t)と(x,y)の関係は以下のようになる。

r = x*cosθ + y*sinθ
t = -x*sinθ+ y*cosθ

rの値はサイノグラムの投影データp(s,θ)のsと等しい...と思う。

目次

― その他 ―

Wiki内検索

計測中...(07.10.8〜)

Save The World






▲よろしければ広告のクリックもお願いします


▲ランキングに参加しました

管理人/副管理人のみ編集できます