<vectorField/>
<vectorField/> is a Graphical component
that draws a two-dimensional vector field as arrows on a lattice covering the visible region of an
enclosing <graph>.
The field comes from a function with two outputs, given inside the component either as a bare
expression — <vectorField>(y, -x)</vectorField> — or as a <function> child. A bare
expression is read as a function of variables attribute to name
them differently. A <function> child is used exactly as written, since it names its own
variables. Like <slopeField/>, the field re-tiles as the user pans or zooms, and
its arrows keep a constant on-screen length whatever the axis scaling.
Each arrow’s tail sits on the lattice point it was sampled at, so it shows the vector at that
point. This differs from <slopeField/>, whose marks are centered on their lattice points
because a tangent direction has no head or tail to distinguish.
Attributes and Properties
Attributes for <vectorField>
Other (11)
number. Default value: 1. Horizontal spacing between arrows.
number. Default value: 1. Vertical spacing between arrows.
layerinteger. Default value: 0. Z-order layer index used to stack graphical components (higher values render on top).
lineStylekeyword. Stroke style for lines.
| Value | Description |
|---|---|
solid | Continuous, unbroken stroke. |
dashed | Stroke composed of evenly-spaced dashes. |
dotted | Stroke composed of evenly-spaced dots. |
lineWidthnumber. Stroke width for lines, in pixels.
number. Default value: 24. Length in pixels of the longest arrow, or of every arrow when normalize is set. Arrows keep this length whatever the axis scaling.
number. Default value: 2500. Upper bound on how many arrows are drawn. Zooming out past this coarsens the lattice rather than drawing an unbounded number of arrows.
normalizeboolean. Default value: false. Draw every arrow the same length, showing direction only rather than magnitude.
_variableNameList. Names of the variables a bare expression is read as a function of. Defaults to "x y". Ignored when the function is given as a <function> child, which names its own variables.
xoffsetnumber. Default value: 0. Horizontal offset of the lattice origin.
yoffsetnumber. Default value: 0. Vertical offset of the lattice origin.
Common to all components (10)
copyreference. Create an independent copy of another component by reference, as if its DoenetML were written here: it starts fresh, without the reader's changes, and makes its own random choices. Enter a reference as $name.
copyWithStateIn developmentreference. Create an independent copy of another component by reference that starts with that component's current state, including the reader's changes and its random choices. Enter a reference as $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <vectorField name="v">
Other (10)
$v.dxnumber. Horizontal spacing between arrows.
$v.dynumber. Vertical spacing between arrows.
$v.layerinteger. Z-order layer index used to stack graphical components (higher values render on top).
$v.markLengthnumber. Length in pixels of the longest arrow, or of every arrow when normalize is set. Arrows keep this length whatever the axis scaling.
$v.maxMarksnumber. Upper bound on how many arrows are drawn. Zooming out past this coarsens the lattice rather than drawing an unbounded number of arrows.
$v.normalizeboolean. Draw every arrow the same length, showing direction only rather than magnitude.
$v.styleDescriptiontext. A textual description of the vector field's style.
$v.styleDescriptionWithNountext. Style description including the noun "vector field".
$v.xoffsetnumber. Horizontal offset of the lattice origin.
$v.yoffsetnumber. Vertical offset of the lattice origin.
Common to all components (8)
$v.disabledboolean. Whether this component is disabled and cannot be interacted with.
$v.doenetMLtext. The DoenetML source code that produced this component.
$v.fixedboolean. Whether this component's value is fixed and cannot be modified.
$v.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$v.hideboolean. Whether to hide this component from the rendered output.
$v.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$v.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: A rotational field
By default arrow length is proportional to the magnitude of the vector, so the arrows grow with
distance from the origin. The longest arrow currently on screen is drawn at markLength, and the
rest in proportion to it, so panning or zooming to a region of larger vectors rescales them all
rather than letting them run off the graph.
Example: Direction only
With normalize, every arrow is drawn the same length. This is the better choice when the shape of
the flow matters more than its speed, or when magnitudes vary so widely that the small arrows
vanish.
Example: A gradient field
The gradient of <function> and referenced inside the
component, which is the alternative to writing the expression out.
Example: Drawn with PreFigure
In a graph with renderer="prefigure", the field is drawn as PreFigure’s own vector field, so an
<annotation> can describe it as a single object. PreFigure draws the field once,
at the graph’s axis limits, on the same lattice: dx, dy, xoffset, yoffset and maxMarks
mean what they mean above, and a lattice point outside the function’s domain gets no arrow. The
longest arrow is markLength pixels long, and with normalize every arrow is.
A few things are drawn differently:
- With
normalize, every arrow has the same length only when the axes are equally scaled. On unequally scaled axes the arrows’ lengths vary with their direction, and a warning says so. - Every arrowhead is the same size, about that of the head on an arrow
markLengthlong, but never narrower than twice the line width. Withoutnormalize, shorter arrows therefore have larger heads than in the interactive graph, and an arrow shorter than 2 pixels is left out. On a thick line a head can fill most of an arrow; a longermarkLengthleaves room for the shaft. - The line width is rounded to a whole pixel, at least 1, and a field with a line width of 0 draws nothing.
- Arrows are solid and fully opaque. A dashed or dotted
lineStyleis ignored, with a warning. The style’s line opacity is ignored too, without one. - The function must be given by a formula. A function defined in some other way draws nothing, with a warning. So does a formula using something PreFigure cannot evaluate, as a curve’s does.
- PreFigure may draw no field at all when a function such as
sqrtorlogis undefined at a lattice point, whenexpoverflows, or when the field divides a constant by a function such assin(x)where it is zero:(1, 1/sin(x))or(1, csc(x))atx = 0 , for example. (Dividing byxitself, or dividingxbysin(y), where the divisor is 0 loses only that arrow.) Give the<function>adomainthat avoids those points, and they are left out. A warning names the first such lattice point.
Attribute Examples
Attribute Example: variables
variables names the inputs of a bare expression, in order: the horizontal axis first, then the
vertical. It defaults to x y, so an equation written in those letters needs nothing. It has no
effect on a <function> child, which names its own variables — writing both warns, since
one of them cannot be doing anything.
The names may themselves be references, exactly as on a <function>, so a student can choose
them:
The field is r in the
first, q in the second — turns the clockwise rotation
Attribute Example: dx, dy
dx and dy set the lattice spacing, one unit each by default. A finer lattice usually wants a
shorter markLength, and a thinner lineWidth: a field is drawn in the component’s selected style,
and the default style’s line is 4 pixels wide, which is more than an arrow this short needs even
before the lattice is crowded. styleNumber="2" gives a thinner line as well, and recolors it.
Attribute Example: markLength
markLength is measured in pixels, and defaults to 24. When arrows scale with magnitude it sets the
length of the longest arrow on screen; with normalize it sets the length of every arrow.
Attribute Example: maxMarks
maxMarks bounds how many arrows are drawn, and defaults to 2500. Rather than refusing to draw when
the lattice would exceed it, the field keeps every
Property Examples
Property Example: dx, dy, normalize
Each attribute of <vectorField/> is also available as a property of a named vector field.