DGS Studio

Vector Fields

2D Vector Field

Draw vector_field(-y, x) as arrows on the plane. Length and color follow the magnitude. A zero vector is a marker, and an undefined sample is skipped.

Generate Graph draws vector_field(-y, x) as a rotation about the origin. At (1, 0) the vector is (0, 1). At (0, 1) it is (-1, 0). At the origin the vector is (0, 0), a zero vector with no direction. The direction is perpendicular to the position vector, so the arrows circle counterclockwise. The magnitude is sqrt(x^2+y^2).

The same card also draws the radial field vector_field(x, y), the constant field vector_field(1, 0), and the zero field vector_field(0, 0). The density slider changes how many arrows are sampled. Arrow scale changes their length together. Normalize arrows keeps the direction and uses one length. Color by magnitude uses teal for smaller vectors and amber for larger ones. Zoom and pan resample the visible window. A component such as 1/x is skipped where it is undefined.

Equation

vector_field(-y,x)

Graph preview

Graph preview of vector_field(-y,x)
A static sample of this expression. The studio draws the full interactive result.

How a vector field is sampled

A vector field assigns a vector to each point. In the plane, F(x, y) = (P, Q). In space, F(x, y, z) = (P, Q, R). The arrow at a sample point starts at that point and points in the direction of the vector. Its length follows the magnitude, scaled so neighboring arrows do not cover one another. Color uses the same magnitude, from teal for a small vector to amber for the largest vector in the current window.

A zero vector has no direction, so it is drawn as a marker rather than an arrow with an invented direction. A sample that is undefined, infinite, or too large to plot is omitted. Changing the density changes how many points are sampled. Normalizing keeps the direction and uses one length, which makes a direction pattern easier to see when magnitudes differ. These pictures sample the field. They do not replace gradient, divergence, or curl, which stay on their own commands.

Reading the input

Other versions of this example

These stay on this page so each version keeps the same explanation. Choose Try example to run a version in its Studio workflow, or copy it into the editable field below.

Rotation

At (1, 0) the vector is (0, 1). At (0, 1) it is (-1, 0). The arrows circle the origin counterclockwise, and the origin is a zero vector.

vector_field(-y,x)

Radial

Arrows point away from the origin. The magnitude is sqrt(x^2+y^2).

vector_field(x,y)

Constant

Every arrow is (1, 0), so the direction and the length stay the same across the window.

vector_field(1,0)

Zero

The field is the zero vector at every point, so the board shows markers and no direction.

vector_field(0,0)

Try a change

Generate Graph draws vector_field(P, Q) on the 2D board, or vector_field(P, Q, R) in the existing 3D viewer. Arrow length and color follow the magnitude unless Normalize arrows is on. Zoom, pan, and orbit stay with those engines. An undefined sample is skipped. A zero vector is a marker with no direction. Export stays available.

Edit and generate

Generate Graph opens the studio homepage and runs this field. Open in DGS Studio loads the same text and waits for you to generate it. The equation is sent once, as a query parameter.

Related examples