<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 (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $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 (14)
$v.disabledboolean. Whether this component is disabled and cannot be interacted with.
$v.dxnumber. Horizontal spacing between arrows.
$v.dynumber. Vertical spacing between arrows.
$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.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 (4)
$v.doenetMLtext. The DoenetML source code that produced this component.
$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.
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.