-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtriangle_interpolate_prb.cpp
140 lines (127 loc) · 3.19 KB
/
triangle_interpolate_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
# include <cmath>
# include <cstdlib>
# include <iomanip>
# include <iostream>
# include <ctime>
using namespace std;
# include "triangle_interpolate.hpp"
int main ( );
void triangle_interpolate_linear_test ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// TRIANGLE_INTERPOLATE_TEST tests the TRIANGLE_INTERPOLATE library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 20 January 2016
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "TRIANGLE_INTERPOLATE_TEST\n";
cout << " C++ version\n";
cout << " Test the TRIANGLE_INTERPOLATE library.\n";
triangle_interpolate_linear_test ( );
//
// Terminate.
//
cout << "\n";
cout << "TRIANGLE_INTERPOLATE_TEST:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void triangle_interpolate_linear_test ( )
//****************************************************************************80
//
// Purpose:
//
// TRIANGLE_INTERPOLATE_LINEAR_TEST tests TRIANGLE_INTERPOLATE_LINEAR.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 20 January 2016
//
// Author:
//
// John Burkardt
//
{
int i;
int j;
int m = 3;
int n = 10;
double *p;
double p1[2] = { 0.0, 1.0 };
double p2[2] = { 5.0, 0.0 };
double p3[2] = { 4.0, 4.0 };
int seed;
double *v;
double v1[3] = { 1.0, 0.0, 0.0 };
double v2[3] = { 0.0, 1.0, 0.0 };
double v3[3] = { 0.0, 0.0, 1.0 };
cout << "\n";
cout << "TRIANGLE_INTERPOLATE_LINEAR_TEST\n";
cout << " TRIANGLE_INTERPOLATE_LINEAR uses linear interpolation\n";
cout << " on vertex data to estimate values in the interior.\n";
//
// Get N sample points inside the triangle.
//
seed = 123456789;
p = uniform_in_triangle_map1 ( p1, p2, p3, n, seed );
//
// Request an intepolated value for R, G and B at each point.
//
v = triangle_interpolate_linear ( m, n, p1, p2, p3, p, v1, v2, v3 );
//
// Report the data.
//
cout << "\n";
cout << " X Y V(1) V(2) V(3)\n";
cout << "\n";
cout << " " << setw(14) << p1[0]
<< " " << setw(14) << p1[1]
<< " " << setw(14) << v1[0]
<< " " << setw(14) << v1[1]
<< " " << setw(14) << v1[2] << "\n";
cout << " " << setw(14) << p2[0]
<< " " << setw(14) << p2[1]
<< " " << setw(14) << v2[0]
<< " " << setw(14) << v2[1]
<< " " << setw(14) << v2[2] << "\n";
cout << " " << setw(14) << p3[0]
<< " " << setw(14) << p3[1]
<< " " << setw(14) << v3[0]
<< " " << setw(14) << v3[1]
<< " " << setw(14) << v3[2] << "\n";
cout << "\n";
for ( j = 0; j < n; j++ )
{
cout << " " << setw(14) << p[0+j*m]
<< " " << setw(14) << p[1+j*m]
<< " " << setw(14) << v[0+j*m]
<< " " << setw(14) << v[1+j*m]
<< " " << setw(14) << v[2+j*m] << "\n";
}
delete [] p;
delete [] v;
return;
}