~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/c++/x18.cc

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//--------------------------------------------------------------------------
 
2
// $Id: x18.cc 11760 2011-06-01 19:29:11Z airwin $
 
3
//--------------------------------------------------------------------------
 
4
//
 
5
//--------------------------------------------------------------------------
 
6
// Copyright (C) 2004  Andrew Ross
 
7
// Copyright (C) 2004  Alan W. Irwin
 
8
//
 
9
// This file is part of PLplot.
 
10
//
 
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.
 
14
//
 
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.
 
19
//
 
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
//--------------------------------------------------------------------------
 
24
//
 
25
//--------------------------------------------------------------------------
 
26
// Implementation of PLplot example 18 in C++.
 
27
//--------------------------------------------------------------------------
 
28
 
 
29
#include "plc++demos.h"
 
30
 
 
31
#ifdef PL_USE_NAMESPACE
 
32
using namespace std;
 
33
#endif
 
34
 
 
35
class x18 {
 
36
public:
 
37
    x18( int, const char ** );
 
38
    PLFLT THETA( int );
 
39
    PLFLT PHI( int );
 
40
    void test_poly( int );
 
41
 
 
42
private:
 
43
    // Class data
 
44
    plstream           *pls;
 
45
 
 
46
    static const int   NPTS;
 
47
    static const int   opt[4];
 
48
    static const PLFLT alt[4];
 
49
    static const PLFLT az[4];
 
50
};
 
51
 
 
52
 
 
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 };
 
57
 
 
58
 
 
59
x18::x18( int argc, const char ** argv )
 
60
{
 
61
    int   i, k;
 
62
    PLFLT r;
 
63
    char  title[80];
 
64
 
 
65
    // plplot initialization
 
66
 
 
67
    pls = new plstream();
 
68
 
 
69
    // Parse and process command line arguments.
 
70
    pls->parseopts( &argc, argv, PL_PARSE_FULL );
 
71
 
 
72
    // Initialize PLplot.
 
73
    pls->init();
 
74
 
 
75
    for ( k = 0; k < 4; k++ )
 
76
        test_poly( k );
 
77
 
 
78
    PLFLT *x = new PLFLT[NPTS];
 
79
    PLFLT *y = new PLFLT[NPTS];
 
80
    PLFLT *z = new PLFLT[NPTS];
 
81
 
 
82
    // From the mind of a sick and twisted physicist...
 
83
 
 
84
    for ( i = 0; i < NPTS; i++ )
 
85
    {
 
86
        z[i] = -1. + 2. * i / NPTS;
 
87
 
 
88
        // Pick one ...
 
89
 
 
90
        // r    = 1. - ( (PLFLT) i / (PLFLT) NPTS );
 
91
        r = z[i];
 
92
 
 
93
        x[i] = r * cos( 2. * M_PI * 6. * i / NPTS );
 
94
        y[i] = r * sin( 2. * M_PI * 6. * i / NPTS );
 
95
    }
 
96
 
 
97
    for ( k = 0; k < 4; k++ )
 
98
    {
 
99
        pls->adv( 0 );
 
100
        pls->vpor( 0.0, 1.0, 0.0, 0.9 );
 
101
        pls->wind( -1.0, 1.0, -0.9, 1.1 );
 
102
        pls->col0( 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 );
 
107
 
 
108
        pls->col0( 2 );
 
109
 
 
110
        if ( opt[k] > 0 )
 
111
            pls->line3( NPTS, x, y, z );
 
112
        else
 
113
            // U+22C5 DOT OPERATOR.
 
114
            pls->string3( NPTS, x, y, z, "â‹…" );
 
115
 
 
116
        pls->col0( 3 );
 
117
 
 
118
        sprintf( title, "#frPLplot Example 18 - Alt=%.0f, Az=%.0f",
 
119
            alt[k], az[k] );
 
120
        pls->mtex( "t", 1.0, 0.5, 0.5, title );
 
121
    }
 
122
 
 
123
    //pls->end();
 
124
 
 
125
    delete[] x;
 
126
    delete[] y;
 
127
    delete[] z;
 
128
    delete pls;
 
129
}
 
130
 
 
131
PLFLT x18::THETA( int a )
 
132
{
 
133
    return 2. * M_PI * (PLFLT) a / 20.;
 
134
}
 
135
 
 
136
PLFLT x18::PHI( int a )
 
137
{
 
138
    return M_PI * (PLFLT) a / 20.1;
 
139
}
 
140
 
 
141
void x18::test_poly( int k )
 
142
{
 
143
    int   i, j;
 
144
    bool  draw[4][4] = {
 
145
        { true,  true,  true,  true  },
 
146
        { true,  false, true,  false },
 
147
        { false, true,  false, true  },
 
148
        { true,  true,  false, false }
 
149
    };
 
150
 
 
151
    PLFLT *x = new PLFLT [5];
 
152
    PLFLT *y = new PLFLT [5];
 
153
    PLFLT *z = new PLFLT [5];
 
154
 
 
155
    pls->adv( 0 );
 
156
    pls->vpor( 0.0, 1.0, 0.0, 0.9 );
 
157
    pls->wind( -1.0, 1.0, -0.9, 1.1 );
 
158
    pls->col0( 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 );
 
163
 
 
164
    pls->col0( 2 );
 
165
 
 
166
    // x = r sin(phi) cos(theta)
 
167
    // y = r sin(phi) sin(theta)
 
168
    // z = r cos(phi)
 
169
    // r = 1 :=)
 
170
 
 
171
    for ( i = 0; i < 20; i++ )
 
172
    {
 
173
        for ( j = 0; j < 20; j++ )
 
174
        {
 
175
            x[0] = sin( PHI( j ) ) * cos( THETA( i ) );
 
176
            y[0] = sin( PHI( j ) ) * sin( THETA( i ) );
 
177
            z[0] = cos( PHI( j ) );
 
178
 
 
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 ) );
 
182
 
 
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 ) );
 
186
 
 
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 ) );
 
190
 
 
191
            x[4] = sin( PHI( j ) ) * cos( THETA( i ) );
 
192
            y[4] = sin( PHI( j ) ) * sin( THETA( i ) );
 
193
            z[4] = cos( PHI( j ) );
 
194
 
 
195
            pls->poly3( 5, x, y, z, draw[k], true );
 
196
        }
 
197
    }
 
198
 
 
199
    pls->col0( 3 );
 
200
    pls->mtex( "t", 1.0, 0.5, 0.5, "unit radius sphere" );
 
201
 
 
202
    delete[] x;
 
203
    delete[] y;
 
204
    delete[] z;
 
205
}
 
206
 
 
207
int main( int argc, const char ** argv )
 
208
{
 
209
    x18 *x = new x18( argc, argv );
 
210
 
 
211
    delete x;
 
212
}
 
213
 
 
214
 
 
215
//--------------------------------------------------------------------------
 
216
//                              End of x18.cc
 
217
//--------------------------------------------------------------------------