Math-PlanePath
view release on metacpan or search on metacpan
devel/dragon.pl view on Meta::CPAN
}
# shift @values; shift @values; shift @values; shift @values;
require Math::OEIS::Grep;
Math::OEIS::Grep->search(array=>\@values);
}
exit 0;
}
{
# convex hull iterations
#
require Math::Geometry::Planar;
my $points = [ [0,0], [1,0], [1,1] ];
my $nx = 1;
my $ny = 1;
foreach my $k (1 .. 20) {
($nx,$ny) = ($nx-$ny, $ny+$nx); # add rotate +90
my $num_points = scalar(@$points);
print "k=$k nxy=$nx,$ny count=$num_points\n";
devel/lib/Math/PlanePath/WythoffLines.pm view on Meta::CPAN
1 | 1
Y=0 |
+-----------------------------------------------------
X=0 1 2 3 4 5 6 7 8 9 10 11 12
A coordinate pair Y and X are the start of a Fibonacci style recurrence,
F[1]=Y, F[2]=X F[i+i] = F[i] + F[i-1]
Any such sequence eventually becomes a row of the Wythoff array
(L<Math::PlanePath::WythoffArray>) after some number of initial iterations.
The N value at X,Y is the row number of the Wythoff array containing
sequence beginning Y and X. Rows are numbered starting from 1. Eg.
Y=4,X=1 sequence: 4, 1, 5, 6, 11, 17, 28, 45, ...
row 7 of WythoffArray: 17, 28, 45, ...
so N=7 at Y=4,X=1
Conversely a given N is positioned in the triangle according to where row
number N of the Wythoff array "precurses" by running the recurrence in
reverse,
examples/c-curve-wx.pl view on Meta::CPAN
my ($prev_x,$prev_y) = $to01->transform($x_lo,$y_lo);
### origin: "$prev_x, $prev_y"
undef $dc;
my $bitmap = Wx::Bitmap->new ($width, $height);
my $scale = 0.5;
# $scale = sqrt(3)/2;
my $iterations = 100;
my $n = $n_lo+1;
$idle_drawing = sub {
my ($event) = @_;
### idle_drawing: $event
my $time = Time::HiRes::time();
# my $client_dc = Wx::ClientDC->new($draw);
# my $dc = Wx::BufferedDC->new($client_dc, $bitmap);
my $dc = Wx::ClientDC->new($draw);
my $remaining = $iterations;
for ( ; $n <= $n_hi; $n++) {
if ($remaining-- < 0) {
# each took time/iterations, want to take .25 sec so
# new_iterations = .25/(time/iterations)
# new_iterations = iterations * .25/time
my $time = Time::HiRes::time() - $time;
$iterations = int(($iterations+1) * .25/$time);
# print "$iterations cf time $time\n";
if ($event) { $event->RequestMore(1); }
return;
}
my ($x,$y) = $path->n_to_xy($n);
($x,$y) = $to01->transform($x,$y);
### point: "$x, $y"
my $c = 0;
lib/Math/PlanePath/ArchimedeanChords.pm view on Meta::CPAN
# f(x) / sub = f'(x)
# sub = f(x) / f'(x)
#
#
# _chord_angle_inc() takes $t is a polar angle around the Archimedean spiral.
# Returns an increment polar angle $u which may be added to $t to move around
# the spiral by a chord length 1 unit.
#
# The loop is Newton's method, $f=f(u), $slope=f'(u) so $u-$f/$slope is a
# better $u, ie. f($u) closer to 0. Stop when the subtract becomes small,
# usually only about 3 iterations.
#
sub _chord_angle_inc {
my ($t) = @_;
# ### _chord_angle_inc(): $t
my $u = 2*_PI/$t; # estimate
foreach (0 .. 10) {
my $shu = sin($u/2); $shu *= $shu; # sin^2(u/2)
my $tu = ($t+$u);
lib/Math/PlanePath/WythoffPreliminaryTriangle.pm view on Meta::CPAN
1 = 6 - 5
4 = 5 - 1
stop on reaching 4,1 which is Y=4,X=1 with Y>=1 and 0<=X<Y
Conversely a coordinate pair X,Y is reckoned as the start of a Fibonacci
style recurrence,
F[i+i] = F[i] + F[i-1] starting F[1]=Y, F[2]=X
Iterating these values gives a row of the Wythoff array
(L<Math::PlanePath::WythoffArray>) after some initial iterations. The N
value at X,Y is the row number of the Wythoff array which is reached. Rows
are numbered starting from 1. For example,
Y=4,X=1 sequence: 4, 1, 5, 6, 11, 17, 28, 45, ...
row 7 of WythoffArray: 17, 28, 45, ...
so N=7 at Y=4,X=1
=cut
# =head2 Phi Slope Blocks
t/MyTestHelpers.pm view on Meta::CPAN
# Don't want to load Exporter here since that could hide a problem of a
# module missing a "use Exporter". Though Test.pm and Test::More (via
# Test::Builder::Module) both use it anyway.
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
sub DEBUG { 0 }
#-----------------------------------------------------------------------------
t/MyTestHelpers.pm view on Meta::CPAN
MyTestHelpers::diag ("search ", $proberef);
MyTestHelpers::findrefs($proberef);
}
}
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
# {
# local $SIG{'__WARN__'} = \&MyTestHelpers::warn_suppress_gtk_icon;
# $something = SomeThing->new;
# }
#
t/MyTestHelpers.pm view on Meta::CPAN
# in Gtk 2.0 gdk_flush() is a sync actually
Gtk2::Gdk->flush;
}
my $count = 0;
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
#-----------------------------------------------------------------------------
# X11::Protocol helpers
sub X11_chosen_screen_number {
( run in 0.791 second using v1.01-cache-2.11-cpan-71847e10f99 )