/usr/share/doc/libplplot12/examples/tcl/x27.tcl is in plplot-tcl-dev 5.10.0+dfsg2-0.1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # $Id: x27.tcl 11859 2011-08-05 08:38:34Z andrewross $
#
# Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
#
# Copyright (C) 2007 Arjen Markus
# Copyright (C) 2008 Andrew Ross
#
# This file is part of PLplot.
#
# PLplot is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PLplot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with PLplot; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#
# --------------------------------------------------------------------------
# main
#
# Generates two kinds of plots:
# - construction of a cycloid (animated)
# - series of epitrochoids and hypotrochoids
# --------------------------------------------------------------------------
proc x27 {{w loopback}} {
# R, r, p, N
set params {
{ 21.0 7.0 7.0 3.0 }
{ 21.0 7.0 10.0 3.0 }
{ 21.0 -7.0 10.0 3.0 }
{ 20.0 3.0 7.0 20.0 }
{ 20.0 3.0 10.0 20.0 }
{ 20.0 -3.0 10.0 20.0 }
{ 20.0 13.0 7.0 20.0 }
{ 20.0 13.0 20.0 20.0 }
{ 20.0 -13.0 20.0 20.0 }}
# Illustrate the construction of a cycloid
cycloid $w
# Loop over the various curves
# First an overview, then all curves one by one
$w cmd pladv 0
$w cmd plssub 3 3
set fill 0
for { set i 0 } { $i < 9 } { incr i } {
$w cmd pladv 0
$w cmd plvpor 0.0 1.0 0.0 1.0
spiro $w [lindex $params $i] $fill
}
$w cmd pladv 0
$w cmd plssub 1 1
for { set i 0 } { $i < 9 } { incr i } {
$w cmd pladv 0
$w cmd plvpor 0.0 1.0 0.0 1.0
spiro $w [lindex $params $i] $fill
}
# Fill the curves
set fill 1
$w cmd pladv 0
$w cmd plssub 1 1 ;# One window per curve
for { set i 0 } { $i < 9 } { incr i } {
$w cmd pladv 0
$w cmd plvpor 0.0 1.0 0.0 1.0
spiro $w [lindex $params $i] $fill
}
arcs $w
}
#--------------------------------------------------------------------------
# Calculate greatest common divisor following pseudo-code for the
# Euclidian algorithm at http://en.wikipedia.org/wiki/Euclidean_algorithm
proc gcd {a b} {
set a [expr {int(abs($a))}]
set b [expr {int(abs($b))}]
while { $b != 0 } {
set t $b
set b [expr {$a % $b}]
set a $t
}
return $a
}
# ===============================================================
proc cycloid {w} {
# TODO
}
# ===============================================================
proc spiro {w params fill} {
foreach {param1 param2 param3 param4} $params {break}
set NPNT 2000
matrix xcoord f [expr {$NPNT+1}]
matrix ycoord f [expr {$NPNT+1}]
# Fill the coordinates
# Proper termination of the angle loop very near the beginning
# point, see
# http://mathforum.org/mathimages/index.php/Hypotrochoid.
set windings [expr {int(abs($param2)/[gcd $param1 $param2])}]
set steps [expr {int($NPNT/$windings)}]
set dphi [expr {2.0*$::PLPLOT::PL_PI/double($steps)}]
# puts [ format "windings, steps, dphi = %d, %d, %f" $windings $steps $dphi ]
set n [expr {int($windings*$steps)+1}]
for { set i 0 } { $i < $n } { incr i } {
set phi [expr {double($i) * $dphi}]
set phiw [expr {($param1-$param2)/$param2*$phi}]
xcoord $i = [expr {($param1-$param2)*cos($phi)+$param3*cos($phiw)}]
ycoord $i = [expr {($param1-$param2)*sin($phi)-$param3*sin($phiw)}]
if { $i == 0} {
set xmin [xcoord 0]
set xmax [xcoord 0]
set ymin [ycoord 0]
set ymax [ycoord 0]
}
if { $xmin > [xcoord $i] } { set xmin [xcoord $i] }
if { $xmax < [xcoord $i] } { set xmax [xcoord $i] }
if { $ymin > [ycoord $i] } { set ymin [ycoord $i] }
if { $ymax < [ycoord $i] } { set ymax [ycoord $i] }
}
set xrange_adjust [expr {0.15 * ($xmax - $xmin) }]
set xmin [expr {$xmin - $xrange_adjust }]
set xmax [expr {$xmax + $xrange_adjust }]
set yrange_adjust [expr {0.15 * ($ymax - $ymin) }]
set ymin [expr {$ymin - $yrange_adjust }]
set ymax [expr {$ymax + $yrange_adjust }]
$w cmd plwind $xmin $xmax $ymin $ymax
$w cmd plcol0 1
if { $fill } {
$w cmd plfill $n xcoord ycoord
} else {
$w cmd plline $n xcoord ycoord
}
}
proc arcs {w} {
set NSEG 8
set pi $::PLPLOT::PL_PI
set theta 0.0
set dtheta [expr {360.0 / $NSEG}]
$w cmd plenv -10.0 10.0 -10.0 10.0 1 0
# Plot segments of circle in different colors
for { set i 0 } { $i < $NSEG } {incr i} {
$w cmd plcol0 [expr {$i%2 + 1}]
$w cmd plarc 0.0 0.0 8.0 8.0 $theta [expr {$theta + $dtheta}] 0.0 0
set theta [expr {$theta + $dtheta}]
}
# Draw several filled ellipses inside the circle at different
# angles.
set a 3.0
set b [expr {$a * tan( ($dtheta/180.0*$pi)/2.0 )}]
set theta [expr {$dtheta/2.0}]
for {set i 0} { $i < $NSEG } { incr i } {
$w cmd plcol0 [expr {2 - $i%2}]
$w cmd plarc [expr {$a*cos($theta/180.0*$pi)}] [expr {$a*sin($theta/180.0*$pi)}] $a $b 0.0 360.0 $theta 1
set theta [expr {$theta + $dtheta}]
}
}
|