1
## $Id: x27c.m 11857 2011-08-04 23:34:19Z andrewross $
3
## Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
5
## Copyright (C) 2007 Arjen Markus
6
## Copyright (C) 2008 Andrew Ross
8
## This file is part of PLplot.
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.
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
31
##--------------------------------------------------------------------------*\
32
## Generates two kinds of plots:
33
## - construction of a cycloid (animated)
34
## - series of epitrochoids and hypotrochoids
35
##--------------------------------------------------------------------------*/
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).
43
21.0, 7.0, 7.0, 3.0; ## Deltoid
45
21.0, -7.0, 10.0, 3.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];
53
## Parse and process command line arguments
55
## (void) plparseopts(&argc, argv, PL_PARSE_FULL);
60
## Illustrate the construction of a cycloid
64
## Loop over the various curves
65
## First an overview, then all curves one by one
67
plssub(3, 3); ## Three by three window
72
plvpor( 0.0, 1.0, 0.0, 1.0 );
73
spiro( params(i,:), fill );
77
plssub(1, 1); ## One window per curve
81
plvpor( 0.0, 1.0, 0.0, 1.0 );
82
spiro( params(i,:), fill );
88
plssub( 1, 1 ); ## One window per curve
91
plvpor( 0.0, 1.0, 0.0, 1.0 );
92
spiro( params(i,:), fill );
95
## Finally, an example to test out plarc capabilities
99
## Don't forget to call plend() to finish off!
104
##------------------------------------------------------------------------
105
## Calculate greatest common divisor following pseudo-code for the
106
## Euclidian algorithm at http://en.wikipedia.org/wiki/Euclidean_algorithm
108
function [value] = gcd (a, b)
119
## ===============================================================
125
## ===============================================================
127
function spiro(params, fill)
131
## Fill the coordinates
133
## Proper termination of the angle loop very near the beginning
135
## http://mathforum.org/mathimages/index.php/Hypotrochoid.
136
windings = floor(abs(params(2))/gcd(params(1), params(2)));
137
steps = floor(NPNT/windings);
140
i = (0:windings*steps)';
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);
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;
158
plwind( xmin, xmax, ymin, ymax );
162
plfill( xcoord, ycoord );
164
plline( xcoord, ycoord );
173
dtheta = 360.0 / NSEG;
174
plenv( -10.0, 10.0, -10.0, 10.0, 1, 0 );
176
## Plot segments of circle in different colors
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;
183
## Draw several filled ellipses inside the circle at different
186
b = a * tan( (dtheta/180.0*pi)/2.0 );
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;