#include #include typedef struct { double x; /* x座標 */ double y; /* y座標 */ } Point; Point rotate1(double, Point, Point); void rotate2(double, Point *, Point *); int main() { double rad, deg; Point c = {1.0, 1.0}, a = {2.0, 3.0}; /* 中心と回転対象の点 */ Point b1, b2; /* 結果を入れる構造体 */ printf("回転角 [度] を入力してください\n"); scanf("%lf", °); rad = deg*M_PI/180; printf("回転角 %f [deg] (%f [rad])\n", deg, rad); /* 関数呼び出しおよび関連するコード */ b1 = rotate1(rad, c, a); b2 = a; rotate2(rad, &c, &b2); printf("Center : %f %f\n", c.x, c.y); printf("Point A : %f %f\n", a.x, a.y); printf("Point B (rotate1) : %f %f\n", b1.x, b1.y); /* rotate1関数の結果を出力 */ printf("Point B (rotate2) : %f %f\n", b2.x, b2.y); /* rotate2関数の結果を出力 */ return 0; } Point rotate1(double rad, Point center, Point p) { double dx, dy; Point pnew; dx = p.x - center.x; dy = p.y - center.y; pnew.x = dx*cos(rad) + dy*(-sin(rad)) + center.x; pnew.y = dx*sin(rad) + dy*cos(rad) + center.y; return pnew; } void rotate2(double rad, Point *center, Point *p) { double dx, dy; dx = p->x - center->x; dy = p->y - center->y; p->x = dx*cos(rad) + dy*(-sin(rad)) + center->x; p->y = dx*sin(rad) + dy*cos(rad) + center->y; }