App-Physics-ParticleMotion

 view release on metacpan or  search on metacpan

lib/App/Physics/ParticleMotion.pm  view on Meta::CPAN

    my $x_max_half = $cloth->cget('-width') / 2;
    my @res;
    while (@_) {
        push @res, $x_max_half + shift(@_) * $displayscale,
          $y_max_half - shift(@_) * $displayscale;
    }
    return @res;
}

# draw_axis draws the n axis' as Tk::Cloth::Line objects.
sub _draw_axis {
	my $app = shift;
	my $axis = $app->{axis};
	my $proj = $app->{proj};
	my $dimensions = $app->{dimensions};
	my $axiscolor = $app->{axiscolor};
	my $cloth = $app->{cloth};
	my $displayscale = $app->{displayscale};
    my $max = 20000;
    $_->delete() foreach @$axis;
    foreach my $dim ( 0 .. $dimensions - 1 ) {
        my ( $x1, $y1 ) =
        	$proj->project( map { $_ == $dim ? -$max / $displayscale : 0 }
             0 .. 2 );
        my ( $x2, $y2 ) =
        	$proj->project( map { $_ == $dim ? $max / $displayscale : 0 }
             0 .. 2 );
		push @$axis,
	        $cloth->Line(
              -coords => [ _transform( $app, $x1, $y1, $x2, $y2 ) ],
              -fill   => $axiscolor,
        	);
    }
}


1;
__END__

=head1 NAME

App::Physics::ParticleMotion - Simulations from Differential Equations

=head1 SYNOPSIS

  # You can use the tk-motion.pl script instead.
  
  use App::Physics::ParticleMotion;
  my $app = App::Physics::ParticleMotion->new();
  $app->config('filename'); # Or pass a Config::Tiny object instead
  $app->run();

  # Using the script:
  # tk-motion.pl filename

=head1 DESCRIPTION

tk-motion (and its implementation App::Physics::ParticleMotion)
is a tool to create particle simulations from any number of
correlated second order differential equations. From a more mathematical
point of view, one could also say it helps visualize the numeric solution
of such differential equations.

The program uses a 4th-order Runge-Kutta integrator to find the numeric
solution of the specified differential equations. We will walk through
an example configuration file step by step to show how the process works.
The format of the configuration files is the ordinary ini file format
as understood by Config::Tiny. (Should be self explanatory.)

=head1 EXAMPLES

=head2 Long Example

The following B<extensive> example comes with the distribution as "ex1.ini".
See below for a minimal working example.

    # This will be a one-dimensional harmonic oszillator (in 2D-space)
    
    # Number of dimensions in simulation (up to three dimensions allowed)
    dimensions = 2
    
    # Given a sufficiently fast cpu, you can have the simulation run very fast
    # by setting this to a high value. Setting it to one makes the simualtion
    # pause after integration steps so that the total speed is no greater
    # than realtime.
    timewarp = 1
    
    # The sensitivity of the integrator.
    # Smaller is more accurate but more cpu intensive.
    epsilon = 0.0000001
    
    # Set to a true value to have the particle traces stay on screen.
    # Note, however, that this tends to increase memory usage with time - slowly.
    # This option may be omitted and defaults to false.
    trace = 0
    
    # Set this to any HTML color to change the axis' color.
    # This option may be omitted and defaults to black.
    axiscolor = #222277
    
    # This sets the zoom. It may be omitted and defaults to 20 for
    # backwards compatibility.
    zoom = 60
    
    # The following options specify the base point and the plane vectors
    # for the viewing plane. (That's the plane you project the 3D coordinates on.)
    # Make sure your vectors are normalized because otherwise your display will
    # be stretched.
    # The values in this example are at the same time the default values.
    plane_base_x = 0
    plane_base_y = 0
    plane_base_z = 0
    
    plane_vec1_x = 0.371391
    plane_vec1_y = 0.928477
    plane_vec1_z = 0
    
    plane_vec2_x = 0.371391
    plane_vec2_y = 0
    plane_vec2_z = 0.928477
    



( run in 1.934 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )