~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/octave/x27c.m

  • 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
##  $Id: x27c.m 11857 2011-08-04 23:34:19Z andrewross $
 
2
##
 
3
##  Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
 
4
##
 
5
##  Copyright (C) 2007 Arjen Markus
 
6
##  Copyright (C) 2008 Andrew Ross
 
7
##
 
8
##  This file is part of PLplot.
 
9
##   
 
10
##  PLplot is free software; you can redistribute it and/or modify
 
11
##  it under the terms of the GNU Library General Public License as published
 
12
##  by the Free Software Foundation; either version 2 of the License, or
 
13
##  (at your option) any later version.
 
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
 
 
27
1;
 
28
 
 
29
function ix27c
 
30
 
 
31
##--------------------------------------------------------------------------*\
 
32
## Generates two kinds of plots:
 
33
##   - construction of a cycloid (animated)
 
34
##   - series of epitrochoids and hypotrochoids
 
35
##--------------------------------------------------------------------------*/
 
36
 
 
37
  ## R, r, p, N
 
38
  ## R and r should be integers to give correct termination of the
 
39
  ## angle loop using gcd.
 
40
  ## N.B. N is just a place holder since it is no longer used
 
41
  ## (because we now have proper termination of the angle loop).
 
42
  params = [
 
43
            21.0,  7.0,  7.0,  3.0;  ## Deltoid
 
44
            21.0,  7.0, 10.0,  3.0;
 
45
            21.0, -7.0, 10.0,  3.0;
 
46
            20.0,  3.0,  7.0, 20.0;
 
47
            20.0,  3.0, 10.0, 20.0;
 
48
            20.0, -3.0, 10.0, 20.0;
 
49
            20.0, 13.0,  7.0, 20.0;
 
50
            20.0, 13.0, 20.0, 20.0;
 
51
            20.0,-13.0, 20.0, 20.0];
 
52
  
 
53
  ## Parse and process command line arguments
 
54
 
 
55
  ## (void) plparseopts(&argc, argv, PL_PARSE_FULL);
 
56
 
 
57
  ## Initialize plplot
 
58
  plinit();
 
59
 
 
60
  ## Illustrate the construction of a cycloid
 
61
 
 
62
  cycloid();
 
63
 
 
64
  ## Loop over the various curves
 
65
  ## First an overview, then all curves one by one
 
66
 
 
67
  plssub(3, 3); ## Three by three window
 
68
 
 
69
  fill = 0;
 
70
  for i = 1:9
 
71
    pladv(0);
 
72
    plvpor( 0.0, 1.0, 0.0, 1.0 );
 
73
    spiro( params(i,:), fill );
 
74
  endfor
 
75
 
 
76
  pladv(0);
 
77
  plssub(1, 1); ## One window per curve
 
78
  
 
79
  for i=1:9
 
80
    pladv(0);
 
81
    plvpor( 0.0, 1.0, 0.0, 1.0 );
 
82
    spiro( params(i,:), fill );
 
83
  endfor
 
84
 
 
85
  ## Fill the curves.
 
86
  fill = 1;
 
87
  pladv( 0 );
 
88
  plssub( 1, 1 ); ## One window per curve
 
89
  for i=1:9
 
90
    pladv(0);
 
91
    plvpor( 0.0, 1.0, 0.0, 1.0 );
 
92
    spiro( params(i,:), fill );
 
93
  endfor
 
94
 
 
95
  ## Finally, an example to test out plarc capabilities
 
96
  arcs();
 
97
 
 
98
 
 
99
  ## Don't forget to call plend() to finish off!
 
100
 
 
101
  plend1();
 
102
end
 
103
 
 
104
##------------------------------------------------------------------------
 
105
## Calculate greatest common divisor following pseudo-code for the
 
106
## Euclidian algorithm at http://en.wikipedia.org/wiki/Euclidean_algorithm
 
107
 
 
108
function [value] = gcd (a,  b)
 
109
    a = floor(abs(a));
 
110
    b = floor(abs(b));
 
111
    while(b!=0)
 
112
        t = b;
 
113
        b = mod(a,b);
 
114
        a = t;
 
115
    endwhile
 
116
    value = a;
 
117
end
 
118
 
 
119
## ===============================================================
 
120
 
 
121
function cycloid()
 
122
    ## TODO
 
123
endfunction
 
124
 
 
125
## ===============================================================
 
126
 
 
127
function spiro(params, fill)
 
128
  
 
129
  NPNT=2000;
 
130
 
 
131
  ## Fill the coordinates
 
132
 
 
133
  ## Proper termination of the angle loop very near the beginning
 
134
  ## point, see
 
135
  ## http://mathforum.org/mathimages/index.php/Hypotrochoid.
 
136
  windings = floor(abs(params(2))/gcd(params(1), params(2)));
 
137
  steps    = floor(NPNT/windings);
 
138
  dphi     = 2.0*pi/steps;
 
139
 
 
140
  i = (0:windings*steps)';
 
141
  phi = i*dphi;
 
142
  phiw = (params(1)-params(2))/params(2)*phi;
 
143
  xcoord = (params(1)-params(2))*cos(phi) + params(3)*cos(phiw);
 
144
  ycoord = (params(1)-params(2))*sin(phi) - params(3)*sin(phiw);
 
145
 
 
146
  xmin = min(xcoord);
 
147
  xmax = max(xcoord);
 
148
  ymin = min(ycoord);
 
149
  ymax = max(ycoord);
 
150
 
 
151
  xrange_adjust = 0.15 * (xmax - xmin);
 
152
  xmin -= xrange_adjust;
 
153
  xmax += xrange_adjust;
 
154
  yrange_adjust = 0.15 * (ymax - ymin);
 
155
  ymin -= yrange_adjust;
 
156
  ymax += yrange_adjust;
 
157
 
 
158
  plwind( xmin, xmax, ymin, ymax );
 
159
  
 
160
  plcol0(1);
 
161
  if ( fill )
 
162
    plfill( xcoord, ycoord );
 
163
  else
 
164
    plline( xcoord, ycoord );
 
165
  endif
 
166
 
 
167
endfunction
 
168
 
 
169
function arcs
 
170
  NSEG = 8;
 
171
 
 
172
  theta = 0.0;
 
173
  dtheta = 360.0 / NSEG;
 
174
  plenv( -10.0, 10.0, -10.0, 10.0, 1, 0 );
 
175
 
 
176
  ## Plot segments of circle in different colors
 
177
  for i = 0:NSEG-1
 
178
    plcol0( mod(i,2) + 1 );
 
179
    plarc(0.0, 0.0, 8.0, 8.0, theta, theta + dtheta, 0.0, 0);
 
180
    theta = theta + dtheta;
 
181
  endfor
 
182
 
 
183
  ## Draw several filled ellipses inside the circle at different
 
184
  ## angles.
 
185
  a = 3.0;
 
186
  b = a * tan( (dtheta/180.0*pi)/2.0 );
 
187
  theta = dtheta/2.0;
 
188
  for i = 0:NSEG-1
 
189
    plcol0( 2 - mod(i,2) );
 
190
    plarc( a*cos(theta/180.0*pi), a*sin(theta/180.0*pi), a, b, 0.0, 360.0, theta, 1);
 
191
    theta = theta + dtheta;
 
192
  endfor
 
193
 
 
194
endfunction
 
195
 
 
196
ix27c