Vectors

 
 
 

A vector is a triple of floating point numbers (usually representing X, Y, and Z). It’s convenient to have a triple-float data type in MEL because so many operations in 3D involve manipulating X,Y,Z values.

To declare a vector, use the vector keyword:

vector $victor;

Literal representation

The literal representation of a vector is three floats separated by commas, surrounded by << and >>. For example:

vector $roger = <<3.0, 7.7, 9.1>>;
vector $more = <<4.5, 6.789, 9.12356>>;

Getting and setting vector values

You can read the individual numbers from a vector variable using the .x, .y, and .z accessors. You must surround the variable and accessor with parentheses:

vector $test = <<3.0, 7.7, 9.1>>;
print($test.x) // 3.0
print($test.y) // 7.7
print($test.z) // 9.1

You cannot use the accessors to set individual parts of a vector:

vector $test = <<3.0, 7.7, 9.1>>;
($test.y) = 5.5 // ERROR

However, you can use the following trick to set individual values:

// Assign a vector to variable $test:
vector $test = <<3.0, 7.7, 9.1>>;
$test = <<$test.x, 5.5, $test.z>>
// $test is now <<3.0, 5.5, 9.1>>
Note

Scientists often use the word vector to mean a magnitude and direction. In Maya, a vector is simply a related group of three floating point numbers.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License