-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdisk_grid_prb.cpp
301 lines (267 loc) · 7.39 KB
/
disk_grid_prb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <cmath>
using namespace std;
# include "disk_grid.hpp"
int main ( );
void disk_grid_test01 ( );
void disk_grid_test02 ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for DISK_GRID_PRB.
//
// Discussion:
//
// DISK_GRID_PRB tests the DISK_GRID library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 20 October 2013
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "DISK_GRID_PRB:\n";
cout << " C++ version\n";
cout << " Test the DISK_GRID library.\n";
disk_grid_test01 ( );
disk_grid_test02 ( );
//
// Terminate.
//
cout << "\n";
cout << "DISK_GRID_PRB:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void disk_grid_test01 ( )
//****************************************************************************80
//
// Purpose:
//
// DISK_GRID_TEST01 tests DISK_GRID.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 20 October 2013
//
// Author:
//
// John Burkardt
//
{
string boundary_filename = "disk_grid_test01_boundary.txt";
ofstream boundary_unit;
double c[2];
double *cg;
string command_filename = "disk_grid_test01_commands.txt";
ofstream command_unit;
string data_filename = "disk_grid_test01_data.txt";
ofstream data_unit;
string filename = "disk_grid_test01.xy";
int i;
int n;
int ng;
const double pi = 3.141592653589793;
double r;
double t;
cout << "\n";
cout << "TEST01:\n";
cout << " DISK_GRID can define a grid of points\n";
cout << " with N+1 points on a horizontal or vertical radius,\n";
cout << " based on any disk.\n";
n = 20;
r = 2.0;
c[0] = 1.0;
c[1] = 5.0;
cout << "\n";
cout << " We use N = " << n << "\n";
cout << " Radius R = " << r << "\n";;
cout << " Center C = (" << c[0] << "," << c[1] << ")\n";
ng = disk_grid_count ( n, r, c );
cout << "\n";
cout << " Number of grid points will be " << ng << "\n";
cg = disk_grid ( n, r, c, ng );
r82vec_print_part ( ng, cg, 20, " Part of the grid point array:" );
//
// Write the coordinate data to a file.
//
r8mat_write ( filename, 2, ng, cg );
cout << "\n";
cout << " Data written to the file \"" << filename << "\"\n";
//
// Create graphics data files.
//
boundary_unit.open ( boundary_filename.c_str ( ) );
for ( i = 0; i <= 50; i++ )
{
t = 2.0 * pi * ( double ) ( i ) / 50.0;
boundary_unit << " " << c[0] + r * cos ( t )
<< " " << c[1] + r * sin ( t ) << "\n";
}
boundary_unit.close ( );
cout << "\n";
cout << " Created boundary file \"" << boundary_filename << "\".\n";
data_unit.open ( data_filename.c_str ( ) );
for ( i = 0; i < ng; i++ )
{
data_unit << " " << cg[0+i*2]
<< " " << cg[1+i*2] << "\n";
}
data_unit.close ( );
cout << "\n";
cout << " Created data file \"" << data_filename << "\"\n";
//
// Create graphics command file.
//
command_unit.open ( command_filename.c_str ( ) );
command_unit << "# " << command_filename << "\n";
command_unit << "#\n";
command_unit << "# Usage:\n";
command_unit << "# gnuplot < " << command_filename << "\n";
command_unit << "#\n";
command_unit << "set term png\n";
command_unit << "set output 'disk_grid_test01.png'\n";
command_unit << "set xlabel '<--- X --->'\n";
command_unit << "set ylabel '<--- Y --->'\n";
command_unit << "set title 'Disk Grid'\n";
command_unit << "set grid\n";
command_unit << "set key off\n";
command_unit << "set size ratio -1\n";
command_unit << "set style data lines\n";
command_unit << "plot '" << data_filename
<< "' using 1:2 with points lt 3 pt 3,\\\n";
command_unit << " '" << boundary_filename
<< "' using 1:2 lw 3 linecolor rgb 'black'\n";
command_unit << "quit\n";
command_unit.close ( );
cout << " Created command file \"" << command_filename << "\"\n";
delete [] cg;
return;
}
//****************************************************************************80
void disk_grid_test02 ( )
//****************************************************************************80
//
// Purpose:
//
// DISK_GRID_TEST02 tests DISK_GRID_FIBONACCI.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 20 October 2013
//
// Author:
//
// John Burkardt
//
{
string boundary_filename = "disk_grid_test02_boundary.txt";
ofstream boundary_unit;
double c[2];
string command_filename = "disk_grid_test02_commands.txt";
ofstream command_unit;
string data_filename = "disk_grid_test02_data.txt";
ofstream data_unit;
string filename = "disk_grid_test02.xy";
double *g;
int i;
int n;
const double pi = 3.141592653589793;
double r;
double t;
cout << "\n";
cout << "TEST02:\n";
cout << " DISK_GRID_FIBONACCI can define a grid of N points\n";
cout << " based on a Fibonacci spiral inside a disk.\n";
n = 1000;
r = 2.0;
c[0] = 1.0;
c[1] = 5.0;
cout << "\n";
cout << " We use N = " << n << "\n";
cout << " Radius R = " << r << "\n";;
cout << " Center C = (" << c[0] << "," << c[1] << ")\n";
g = disk_grid_fibonacci ( n, r, c );
r82vec_print_part ( n, g, 20, " Part of the grid point array:" );
//
// Write the coordinate data to a file.
//
r8mat_write ( filename, 2, n, g );
cout << "\n";
cout << " Data written to the file \"" << filename << "\"\n";
//
// Create graphics data files.
//
boundary_unit.open ( boundary_filename.c_str ( ) );
for ( i = 0; i <= 50; i++ )
{
t = 2.0 * pi * ( double ) ( i ) / 50.0;
boundary_unit << " " << c[0] + r * cos ( t )
<< " " << c[1] + r * sin ( t ) << "\n";
}
boundary_unit.close ( );
cout << "\n";
cout << " Created boundary file \"" << boundary_filename << "\".\n";
data_unit.open ( data_filename.c_str ( ) );
for ( i = 0; i < n; i++ )
{
data_unit << " " << g[0+i*2]
<< " " << g[1+i*2] << "\n";
}
data_unit.close ( );
cout << "\n";
cout << " Created data file \"" << data_filename << "\"\n";
//
// Create graphics command file.
//
command_unit.open ( command_filename.c_str ( ) );
command_unit << "# " << command_filename << "\n";
command_unit << "#\n";
command_unit << "# Usage:\n";
command_unit << "# gnuplot < " << command_filename << "\n";
command_unit << "#\n";
command_unit << "set term png\n";
command_unit << "set output 'disk_grid_test02.png'\n";
command_unit << "set xlabel '<--- X --->'\n";
command_unit << "set ylabel '<--- Y --->'\n";
command_unit << "set title 'Fibonacci Disk Grid'\n";
command_unit << "set grid\n";
command_unit << "set key off\n";
command_unit << "set size ratio -1\n";
command_unit << "set style data lines\n";
command_unit << "plot '" << data_filename
<< "' using 1:2 with points lt 3 pt 3,\\\n";
command_unit << " '" << boundary_filename
<< "' using 1:2 lw 3 linecolor rgb 'black'\n";
command_unit << "quit\n";
command_unit.close ( );
cout << " Created command file \"" << command_filename << "\"\n";
delete [] g;
return;
}