[ create a new paste ] login | about

Link: http://codepad.org/QASgM33C    [ raw code | output | fork ]

C++, pasted on Aug 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
	const double pi = 3.1415926;
	int x = -1, y = -2;								//	移動量

	for ( int i = 0; i != 4; ++i ) {
		double a = pi / 2 * i;						//	回転角(ラジアン)
		double mx = x * cos( a ) - y * sin( a );	//	回転後移動量
		double my = x * sin( a ) + y * cos( a );

		cout << setw( 3 ) << i * 90 << "度回転時移動量:"
			<< "( " << setw( 2 ) << mx << ", " << setw( 2 ) << my << " )" << endl;
	}

	return 0;
}


Output:
1
2
3
4
  0度回転時移動量:( -1, -2 )
 90度回転時移動量:(  2, -1 )
180度回転時移動量:(  1,  2 )
270度回転時移動量:( -2,  1 )


Create a new paste based on this one


Comments: