最終更新: mikk_ni3_92 2007年11月13日(火) 15:02:27履歴
現在地 >> メニュー >> サンプルコード::OpenGL >> 座標の回転
#include <cstdio>
#include <cmath>
#include <iostream>
struct _POINT2D
{
double x;
double y;
};
typedef struct _POINT2D POINT_2D;
using namespace std;
#define PI_OVER_180 0.0174532925
int main(int argc,char*argv[])
{
POINT_2D p;
POINT_2D q;
double theta;
while(1){
cout<<"(x,y,θ)=? ";
cin >> p.x >> p.y >> theta;
cout << endl;
printf("(x,y,θ)=(%f,%f,%f) \n",p.x,p.y,theta );
cout <<"Rotate !"<< endl;
q.x = p.x * cos(theta*PI_OVER_180) - p.y * sin(theta*PI_OVER_180);
q.y = p.x * sin(theta*PI_OVER_180) + p.y * cos(theta*PI_OVER_180);
printf("(s,t)=(%f,%f) \n\n",q.x,q.y);
}
return 0;
}
#include <cstdio>
#include <cmath>
#include <iostream>
struct _POINT2D
{
double x;
double y;
};
typedef struct _POINT2D POINT_2D;
using namespace std;
#define PI_OVER_180 0.0174532925
int main(int argc,char*argv[])
{
POINT_2D p;
POINT_2D q;
double theta;
while(1){
cout<<"(x,y,θ)=? ";
cin >> p.x >> p.y >> theta;
cout << endl;
printf("(x,y,θ)=(%f,%f,%f) \n",p.x,p.y,theta );
cout <<"Rotate !"<< endl;
q.x = p.x * cos(theta*PI_OVER_180) - p.y * sin(theta*PI_OVER_180);
q.y = p.x * sin(theta*PI_OVER_180) + p.y * cos(theta*PI_OVER_180);
printf("(s,t)=(%f,%f) \n\n",q.x,q.y);
}
return 0;
}