###実現したいこと
height*widthの長方形の任意の座標を
「長方形の中心」を中心にして回転行列によって90°回転させた後の座標を表示させたいです。
###発生している問題
この数値を配列のインデクスとして利用するため、x, yともに0~9の値が重複なしで出てほしいです。
どのようにすれば改善できますか。
C++
1neutral_y is -0 //「0」とでてほしい 2neutral_x is 10 //「9」とでてほしい 3 4neutral_y is 0 //「1」とでてほしい 5neutral_x is 10 6 7neutral_y is 1 8neutral_x is 10 9 10neutral_y is 2 11neutral_x is 10 12 13neutral_y is 3 14neutral_x is 10 15 16neutral_y is 4 17neutral_x is 10 18 19neutral_y is 5 20neutral_x is 10 21 22neutral_y is 6 23neutral_x is 10 24 25neutral_y is 7 26neutral_x is 10 27 28neutral_y is 9 29neutral_x is 10
###該当のソースコード
C++
1void neutral_coor(int rot_num, int x, int y){ //(90°回転を何回するか, 回転したいx座標, y座標) 2 double degree = rot_num*90*(M_PI / 180); //弧度からラジアンへ 3 double O_x = width*0.5; //xの回転中心 4 double O_y = height*0.5; //yの回転中心 5 double neutral_x = x*cos(degree) - y*sin(degree) + O_x*(1-cos(degree)) + O_y*sin(degree); //回転後のx 6 double neutral_y = x*sin(degree) + y*cos(degree) - O_x*sin(degree) + O_y*(1-cos(degree)); //回転後のy 7 cout << "neutral_y is " << int(neutral_y) << endl; 8 cout << "neutral_x is " << int(neutral_x) << endl; 9 cout << endl; 10} 11 12int main(void){ 13 for (int x = 0; x < width; x++){ 14 neutral_coor(1, x, 0); 15 } 16}
###補足
任意点における回転行列は以下のサイトを参考にしました
http://imagingsolution.blog107.fc2.com/blog-entry-111.html
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。