ReferencevectorField

<vectorField/>

A vector field drawn as arrows on a lattice, from a function with two outputs

<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 x and y; use the 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.

layer

integer. Default value: 0. Z-order layer index used to stack graphical components (higher values render on top).

lineStyle

keyword. Stroke style for lines.

ValueDescription
solidContinuous, unbroken stroke.
dashedStroke composed of evenly-spaced dashes.
dottedStroke composed of evenly-spaced dots.
lineWidth

number. 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.

normalize

boolean. 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.

xoffset

number. Default value: 0. Horizontal offset of the lattice origin.

yoffset

number. Default value: 0. Vertical offset of the lattice origin.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. 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.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$v.dx

number. Horizontal spacing between arrows.

$v.dy

number. Vertical spacing between arrows.

$v.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$v.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$v.hidden

boolean. Whether this component is hidden from the rendered output.

$v.layer

integer. Z-order layer index used to stack graphical components (higher values render on top).

$v.markLength

number. Length in pixels of the longest arrow, or of every arrow when normalize is set. Arrows keep this length whatever the axis scaling.

$v.maxMarks

number. Upper bound on how many arrows are drawn. Zooming out past this coarsens the lattice rather than drawing an unbounded number of arrows.

boolean. Draw every arrow the same length, showing direction only rather than magnitude.

$v.styleDescription

text. A textual description of the vector field's style.

$v.styleDescriptionWithNoun

text. Style description including the noun "vector field".

$v.xoffset

number. Horizontal offset of the lattice origin.

$v.yoffset

number. Vertical offset of the lattice origin.

Common to all components (4)
$v.doenetML

text. The DoenetML source code that produced this component.

$v.hide

boolean. Whether to hide this component from the rendered output.

$v.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$v.styleNumber

integer. 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 x^2 + y^2 points radially outward, everywhere perpendicular to the circular level curves. Here the field is defined as a separate <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, -q) whichever axis each letter names, so swapping the two boxes — r in the first, q in the second — turns the clockwise rotation (y, -x) into (x, -y), which flows away from the vertical axis instead of circling the origin.


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 n-th lattice line.

Property Examples

Property Example: dx, dy, normalize

Each attribute of <vectorField/> is also available as a property of a named vector field.