Autodesk Creative Platform Core Version 1.19.0
A broad and deep collection of 2D and 3D capabilities.

Vector2D Overview

Implements Interfaces: IDebuggable

A vector in 2D Space.

Introduced in Version: 1.1.0

Class Member Summary

Class Member Details

• Vector2D (x, y) | Constructor

The following parameters can be specified in the constructor:
  • x: Number - The X magnitude of the vector.
  • y: Number - The Y magnitude of the vector.

Number angle (other)

Calculates the counter-clockwise angle from this vector to a specified vector. The returned value is in the range [ 0 , π ] and ( -π , 0 ).

1 Example:

// Calculate the angle counter-clockwise to the specified vector
var vec1 = new Vector2D(1, 1);
var vec2 = new Vector2D(-1, 0);
var vec3 = new Vector2D(0, -1);
vec1.angle(vec2); //returns 3 * PI / 4;
vec1.angle(vec3); //returns - 3 * PI / 4;

Vector2D clone()

Creates a copy of this object and returns it.

Number cross (other)

Calculates the cross product of this vector with another vector. Returns a new vector representing the cross product.

• debug()

Instructs the object to present useful debugging information via a series of calls to Debug.point, Debug.line and Debug.triangles.

Number dot (other)

Calculates the dot product of this vector with another vector.

Boolean equals (other)

Returns true if the objects are equal, otherwise false.

Number length()

The length of the vector.

Vector2D normalize() | Chainable

Reduces the length of this vector to be 1.0 but maintains the X/Y ratio.

Vector2D rotate (angle) | Chainable

Rotates this vector by the angle specified. Right-handed system is used implying the positive angles result in counter-clockwise orientations.
  • angle: Number - The angle of rotation in radians by clockwise

Vector2D scale (scale, [y]) | Chainable

Scales the vector magnitude.
  • scale: Vector2D or Array [ Number ] or Number - A scale defined by a Vector2D, an Array with 2 values (X and Y), or a number representing the X scale (and Y scale if no additional parameter is specified.)
  • y: Number - An option Y scale to use if an X scale was specified as the first argument. If this argument is not specified then uniform scaling is assumed. | Optional

4 Examples:

// Scale the vector by given one scale number uniformly
// Scale the vector by given X and Y scale numbers
vector.scale(0.5, 0.75);
// Scale the vector by given a Vector2D object
var vec = new Vector2D(0.5, 0.75);
// Scale the vector by given a 2-element array with X and Y scale numbers
vector.scale([0.5, 0.75]);

Vector2D transform (matrix) | Chainable

Transforms this vector by a transformation matrix. Only the rotation and scaling from the matrix are applied.

2 Examples:

// Transform the vector by given a 9-element array 
tm = [a, b, 0, c, d, 0, e, f, 1] representing following matrix, only rotation and scaling part applied
[a b 0] 
[c d 0]
[0 0 1]  
new vector would be (a*x + c*y, b*x + d*y)

// Transform the vector by given a Matrix2D object

Number x

The X magnitude of the vector.

Number y

The Y magnitude of the vector.