VectorField2D.pl - Adds a vector field graph to a WWPlot (from PGgraphmacros.pl) graphobject.
This is a single macro which creates a vector field and adds it to a graphobject created using init_graph
from PGgraphmacros.pl. Create a vector field by first creating a graphobject.
loadMacros('PGML.pl', 'PGgraphmacros.pl', 'VectorField2D.pl');
$gr = init_graph($xmin, $ymin, $xmax, $ymax, axes => [0, 0], pixels => [500, 500]);
Then use the VectorField2D(options)
macro to add the vector field F = Fx i + Fy j
to the graph, where Fx
and Fy
are MathObject formulas in two variables (you may need to add the variables to the Context):
Context()->variables->add(x => 'Real', y => 'Real');
VectorField2D(
graphobject => $gr,
Fx => Formula('2xy'),
Fy => Formula('y^2 - x^2'),
xvar => 'x',
yvar => 'y',
xmin => -5,
xmax => 5,
ymin => -5,
ymax => 5,
xsamples => 10,
ysamples => 10,
vectorcolor => 'blue',
vectorscale => 0.25,
vectorthickness => 2,
vectortiplength => 0.65,
vectortipwidth => 0.08,
xavoid => 0,
yavoid => 0,
);
Add the following PGML to insert the image into the problem:
[@ image(insertGraph($gr)) @]*
The options control the domain, vector density, and arrow style of the vector field.
A reference to the graphobject to add the vector field to.
The x and y coordinate functions for vector field. These can either be a MathObject Formula using two variables, or a perl subroutine, such as sub { my ($x, $y) = @_; return $x - $y; }
.
The name of the two variables used in the MathObjects Fx and Fy. Has no effect on perl functions.
The rectangular domain to plot the vector field inside of.
Defines the number of subrectangles to divide the domain into, which results in xsamples + 1
by ysamples + 1
vectors graphed at the grid intersections.
These define the color and multiple scale factors which are used to compute the length of the vector arrow and size of the vector tip.
Defines a single point to skip when creating the vector field.