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