最終更新: mikk_ni3_92 2007年11月08日(木) 15:16:46履歴
現在地 >> メニュー >> サンプルコード::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;
}
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;
}