1
//--------------------------------------------------------------------------
2
// $Id: x18.cc 11760 2011-06-01 19:29:11Z airwin $
3
//--------------------------------------------------------------------------
5
//--------------------------------------------------------------------------
6
// Copyright (C) 2004 Andrew Ross
7
// Copyright (C) 2004 Alan W. Irwin
9
// This file is part of PLplot.
11
// PLplot is free software; you can redistribute it and/or modify
12
// it under the terms of the GNU Library General Public License as published by
13
// the Free Software Foundation; version 2 of the License.
15
// PLplot is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Library General Public License for more details.
20
// You should have received a copy of the GNU Library General Public License
21
// along with PLplot; if not, write to the Free Software
22
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
//--------------------------------------------------------------------------
25
//--------------------------------------------------------------------------
26
// Implementation of PLplot example 18 in C++.
27
//--------------------------------------------------------------------------
29
#include "plc++demos.h"
31
#ifdef PL_USE_NAMESPACE
37
x18( int, const char ** );
40
void test_poly( int );
46
static const int NPTS;
47
static const int opt[4];
48
static const PLFLT alt[4];
49
static const PLFLT az[4];
53
const int x18:: NPTS = 1000;
54
const int x18:: opt[] = { 1, 0, 1, 0 };
55
const PLFLT x18::alt[4] = { 20.0, 35.0, 50.0, 65.0 };
56
const PLFLT x18::az[4] = { 30.0, 40.0, 50.0, 60.0 };
59
x18::x18( int argc, const char ** argv )
65
// plplot initialization
69
// Parse and process command line arguments.
70
pls->parseopts( &argc, argv, PL_PARSE_FULL );
75
for ( k = 0; k < 4; k++ )
78
PLFLT *x = new PLFLT[NPTS];
79
PLFLT *y = new PLFLT[NPTS];
80
PLFLT *z = new PLFLT[NPTS];
82
// From the mind of a sick and twisted physicist...
84
for ( i = 0; i < NPTS; i++ )
86
z[i] = -1. + 2. * i / NPTS;
90
// r = 1. - ( (PLFLT) i / (PLFLT) NPTS );
93
x[i] = r * cos( 2. * M_PI * 6. * i / NPTS );
94
y[i] = r * sin( 2. * M_PI * 6. * i / NPTS );
97
for ( k = 0; k < 4; k++ )
100
pls->vpor( 0.0, 1.0, 0.0, 0.9 );
101
pls->wind( -1.0, 1.0, -0.9, 1.1 );
103
pls->w3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k] );
104
pls->box3( "bnstu", "x axis", 0.0, 0,
105
"bnstu", "y axis", 0.0, 0,
106
"bcdmnstuv", "z axis", 0.0, 0 );
111
pls->line3( NPTS, x, y, z );
113
// U+22C5 DOT OPERATOR.
114
pls->string3( NPTS, x, y, z, "â‹…" );
118
sprintf( title, "#frPLplot Example 18 - Alt=%.0f, Az=%.0f",
120
pls->mtex( "t", 1.0, 0.5, 0.5, title );
131
PLFLT x18::THETA( int a )
133
return 2. * M_PI * (PLFLT) a / 20.;
136
PLFLT x18::PHI( int a )
138
return M_PI * (PLFLT) a / 20.1;
141
void x18::test_poly( int k )
145
{ true, true, true, true },
146
{ true, false, true, false },
147
{ false, true, false, true },
148
{ true, true, false, false }
151
PLFLT *x = new PLFLT [5];
152
PLFLT *y = new PLFLT [5];
153
PLFLT *z = new PLFLT [5];
156
pls->vpor( 0.0, 1.0, 0.0, 0.9 );
157
pls->wind( -1.0, 1.0, -0.9, 1.1 );
159
pls->w3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k] );
160
pls->box3( "bnstu", "x axis", 0.0, 0,
161
"bnstu", "y axis", 0.0, 0,
162
"bcdmnstuv", "z axis", 0.0, 0 );
166
// x = r sin(phi) cos(theta)
167
// y = r sin(phi) sin(theta)
171
for ( i = 0; i < 20; i++ )
173
for ( j = 0; j < 20; j++ )
175
x[0] = sin( PHI( j ) ) * cos( THETA( i ) );
176
y[0] = sin( PHI( j ) ) * sin( THETA( i ) );
177
z[0] = cos( PHI( j ) );
179
x[1] = sin( PHI( j + 1 ) ) * cos( THETA( i ) );
180
y[1] = sin( PHI( j + 1 ) ) * sin( THETA( i ) );
181
z[1] = cos( PHI( j + 1 ) );
183
x[2] = sin( PHI( j + 1 ) ) * cos( THETA( i + 1 ) );
184
y[2] = sin( PHI( j + 1 ) ) * sin( THETA( i + 1 ) );
185
z[2] = cos( PHI( j + 1 ) );
187
x[3] = sin( PHI( j ) ) * cos( THETA( i + 1 ) );
188
y[3] = sin( PHI( j ) ) * sin( THETA( i + 1 ) );
189
z[3] = cos( PHI( j ) );
191
x[4] = sin( PHI( j ) ) * cos( THETA( i ) );
192
y[4] = sin( PHI( j ) ) * sin( THETA( i ) );
193
z[4] = cos( PHI( j ) );
195
pls->poly3( 5, x, y, z, draw[k], true );
200
pls->mtex( "t", 1.0, 0.5, 0.5, "unit radius sphere" );
207
int main( int argc, const char ** argv )
209
x18 *x = new x18( argc, argv );
215
//--------------------------------------------------------------------------
217
//--------------------------------------------------------------------------