回答編集履歴
1
ついでに
test
CHANGED
@@ -13,3 +13,147 @@
|
|
13
13
|
}
|
14
14
|
|
15
15
|
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
ついでに
|
20
|
+
|
21
|
+
-----
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
以下のように座標値変換(回転後の座標値を求める方法)でもできます。
|
26
|
+
|
27
|
+
```C++
|
28
|
+
|
29
|
+
#include <stdio.h>
|
30
|
+
|
31
|
+
#include <string.h>
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
#define SIZE 3
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
// 座標値を時計回りに90度回転
|
40
|
+
|
41
|
+
void rot90( int *px, int *py)
|
42
|
+
|
43
|
+
{
|
44
|
+
|
45
|
+
int x(*px), y(*py);
|
46
|
+
|
47
|
+
*px = SIZE - y - 1;
|
48
|
+
|
49
|
+
*py = x;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// 座標値を回転
|
56
|
+
|
57
|
+
// direc : 0=反時計, 1=時計回り
|
58
|
+
|
59
|
+
// angle : x90度
|
60
|
+
|
61
|
+
void rot( int *px, int *py, int direc, int angle)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
int lop = direc == 1 ? (angle % 4) : (4 - (angle % 4));
|
66
|
+
|
67
|
+
for( int i = 0; i < lop; i++){
|
68
|
+
|
69
|
+
rot90( px, py);
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
// 図形を回転
|
78
|
+
|
79
|
+
void rotate( char src[][SIZE+1], char dst[][SIZE+1], int direc, int angle)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
for( int y = 0; y < SIZE; y++){
|
84
|
+
|
85
|
+
for( int x = 0; x < SIZE; x++){
|
86
|
+
|
87
|
+
char c = src[y][x];
|
88
|
+
|
89
|
+
int dx(x), dy(y);
|
90
|
+
|
91
|
+
rot( &dx, &dy, direc, angle);
|
92
|
+
|
93
|
+
dst[dy][dx] = c;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// 図形をprint
|
104
|
+
|
105
|
+
void print( char s[][SIZE+1])
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
for( int y = 0; y < SIZE; y++){
|
110
|
+
|
111
|
+
printf("%s\n", s[y]);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
int main(void)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
char src[SIZE][SIZE+1] = { "-+-",
|
124
|
+
|
125
|
+
"+++",
|
126
|
+
|
127
|
+
"---"};
|
128
|
+
|
129
|
+
char dst[SIZE][SIZE+1];
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
for( int direc = 0; direc < 2; direc++){
|
134
|
+
|
135
|
+
for( int angle = 0; angle < 4; angle++){
|
136
|
+
|
137
|
+
memset( dst, 0, sizeof(dst));
|
138
|
+
|
139
|
+
printf("direc=%d, angle=%d\n", direc, angle);
|
140
|
+
|
141
|
+
printf("src=====\n");
|
142
|
+
|
143
|
+
print( src);
|
144
|
+
|
145
|
+
rotate( src, dst, direc, angle);
|
146
|
+
|
147
|
+
printf("dst=====\n");
|
148
|
+
|
149
|
+
print( dst);
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
return 0;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|