Maya Node Math: Vectors and How to Get Them

This tutorial introduces vectors and demonstrates some common ways of accessing them in Maya node networks.

What’s a Vector?

A vector describes direction and magnitude, with magnitude sometimes also referred to as distance or length. A vector comprises three values: X, Y and Z. These can be conceptualised as the difference (delta) between a pair of start and end coordinates. However, a vector has no inherent position.

What Can You Use Vectors For?

Vectors are an essential part of computer graphics. You can use them to:

  • Measure alignments, for example between bones in a skeleton
  • Do more with the worldUpVector input of nodes such as aimConstraint and motionPath
  • Create orientation relationships without relying on rotation values
  • Develop fully customised orientation and / or scaling setups beyond what’s possible using Maya’s standard constraints
  • And much, much more

OK, I Want One

You can sample vectors in a variety of ways.

Get the Vector Between Two Objects
To get the world-space vector between object A and object B, do the following:

  1. Create outputs for the world positions of the two objects (see Getting the World Position of an Object).
  2. Create a plusMinusAverage node, set its operation to Subtract and subtract the world position of A from that of B.
  3. Grab the vector from the plusMinusAverage node’s output3D output.

Your network should look something like this:


The above is commonly used to find the vector represented by two joints that make up a bone in a skeleton.

Get an Object Orientation Axis as a Vector
To achieve this, do the following:

  1. Create a vectorProduct node, and set its operation to Vector Matrix Product.
  2. Connect the object’s worldMatrix output into the vectorProduct node’s matrix input.
  3. Manually fill out the input1 fields of the vectorProduct node to correspond to the axis you wish to extract. For example, if you want to get a vector for the X axis, set the fields to 1, 0, 0.
  4. Grab the vector from the vectorProduct node’s output plug.

Your network should look something like this:


The above technique is similar to what happens when you configure an aimConstraint to use the Object Rotation Up mode for its up vector. The axis you define in the the worldUpVector field is is extracted from the worldMatrix of the object defined in worldUpObject.

Sample a Vector from a NURBS Surface
Maya’s pointOnSurfaceInfo node makes it easy to extract tangent and normal vectors from NURBS surfaces. You can use these, for example, to create complex spine rigs that twist to follow a “ribbon” surface, or even to attach objects in “stretchy” ways. Here’s a visual example of a U tangent, V tangent and normal on a NURBS surface point:


To extract these vectors, do the following:

  1. Load up your surface’s shape node in the Node Editor.
  2. Create a pointOnSurfaceInfo node.
  3. Connect the surface’s worldSpace[0] output into the inputSurface input of the pointOnSurfaceInfo.
  4. Set the parameterU and parameterV attributes on the pointOnSurfaceInfo accordingly. (A quick way to check what these should be is to select a point on the surface and make a note of what appears in the Maya menu bar.)
  5. Grab any of the tangentU, tangentV or normal outputs.

Your setup should look something like this:


You can also draw tangent and normal vectors from a NURBS curve in a similar way using the pointOnCurveInfo node.