Vector3d
A direction and magnitude in 3D space.
Vectors describe displacements, normals, and directions. Unlike
Point3d (which is a position), a vector has no fixed
location — it represents “how far and which way.” Vectors are
immutable: operations like add(), cross(), and normalize
return new instances.
Common uses include rotation axes, face normals, translation offsets, and computing angles between directions.
Example
Section titled “Example”let { Vector3d } = SketchUpApi;
let up = new Vector3d(0, 0, 1);let diagonal = new Vector3d(1, 1, 0);
// Angle between two vectors (radians)let angle = up.angleBetween(diagonal);console.log((angle * 180 / Math.PI).toFixed(1));// => 90.0
// Cross product gives a perpendicular vectorlet perp = up.cross(diagonal);console.log(perp.normalize.toArray());// => [-0.707, 0.707, 0] (approx)
// Length and normalizationconsole.log(diagonal.length.toFixed(3));// => 1.414console.log(diagonal.normalize.toArray());// => [0.707, 0.707, 0] (approx)Constructor
Section titled “Constructor”Constructor
Section titled “Constructor”new Vector3d(
x?,y?,z?):Vector3d
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”Vector3d
Properties
Section titled “Properties”
readonlyx:number=0
readonlyy:number=0
readonlyz:number=0
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get axes(): [
Vector3d,Vector3d,Vector3d]
Creates an arbitrary axes triple that satisfy this direction as the z-axis direction.
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(0, 0, 1);console.log(vector.axes);Returns
Section titled “Returns”[Vector3d, Vector3d, Vector3d]
an Array of three vectors [xaxis, yaxis, zaxis]
length
Section titled “length”Get Signature
Section titled “Get Signature”get length():
number
The magnitude (length) of this vector.
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(1, 2, 3);// 1console.log(vector.normalize.length);// √14console.log(vector.length);Returns
Section titled “Returns”number
normalize
Section titled “normalize”Get Signature
Section titled “Get Signature”get normalize():
Vector3d
A unit vector (length 1) pointing in the same direction.
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(1, 2, 3);// ~Vector3d(0.267,0.535,0.802)console.log(vector.normalize.toString());Returns
Section titled “Returns”Vector3d
reverse
Section titled “reverse”Get Signature
Section titled “Get Signature”get reverse():
Vector3d
A new vector pointing in the opposite direction (negated components), with the same length.
Returns
Section titled “Returns”Vector3d
Methods
Section titled “Methods”add(
vector2):Vector3d
Returns a new vector that is the sum of this vector and another.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);let b = new Vector3d(10, 20, 30);
// Vector3d(11,22,33);console.log(a.add(b).toString());angleBetween()
Section titled “angleBetween()”angleBetween(
vector2):number
The angle between this vector and another, in radians (always 0 to PI).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”number
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);let b = new Vector3d(1, -2, 3);
// PI / 2console.log(a.angleBetween(b));cross()
Section titled “cross()”cross(
vector):Vector3d
The cross product of this vector and another — a new vector perpendicular to both, whose length equals the area of the parallelogram they span.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(0, 0, 1);// Vector3d(0,1,0)console.log(vector.cross([1, 0, 0]).toString());dot(
vector):number
The dot product of this vector and another. Positive when they point in similar directions, zero when perpendicular, negative when opposing.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”number
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(0, 0, 1);// 0console.log(vector.dot([1, 0, 0]));// √2console.log(vector.dot([1, 1, 0]));equalTo()
Section titled “equalTo()”equalTo(
vector2):boolean
Compares two vectors component-wise within a 0.001 tolerance.
let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);
// trueconsole.log(a.equalTo(a.add([0.0009,0,0])));// falseconsole.log(a.equalTo(a.add([0.001,0,0])));Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”boolean
isParallel()
Section titled “isParallel()”isParallel(
vector2):boolean
True if this vector is parallel (or anti-parallel) to another, within tolerance.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”boolean
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);let b = new Vector3d(11, 22, 33);let c = new Vector3d(1, -2, 3);let d = new Vector3d(-1, -2, -3);// trueconsole.log(a.isParallel(b));// falseconsole.log(a.isParallel(c));// trueconsole.log(a.isParallel(d));isPerpendicular()
Section titled “isPerpendicular()”isPerpendicular(
vector2):boolean
True if this vector is perpendicular to another (dot product is within tolerance of zero).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”boolean
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector(1, 2, 3);let b = new Vector(11, 22, 33);let c = new Vector(1, -2, 3);// falseconsole.log(a.perpendicular(b));// trueconsole.log(a.perpendicular(c));SDK 2.37.0
isSameDirectionAs()
Section titled “isSameDirectionAs()”isSameDirectionAs(
vector2):boolean
True if this vector points in the same direction as another (within tolerance).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”boolean
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);let b = new Vector3d(11, 22, 33);let c = new Vector3d(1, -2, 3);let d = new Vector3d(-1, -2, -3);// trueconsole.log(a.isSameDirectionAs(b));// falseconsole.log(a.isSameDirectionAs(c));// falseconsole.log(a.isSameDirectionAs(d));SDK 2.37.0
isUnitVector()
Section titled “isUnitVector()”isUnitVector():
boolean
Returns true if the Vector3d.length is close enough to 1
Returns
Section titled “Returns”boolean
Boolean true if this represents a unit vector
SDK 2.37.0
minus()
Section titled “minus()”minus(
vector2):Vector3d
Returns a new vector with the other vector subtracted from this one.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1, 2, 3);let b = new Vector3d(10, 20, 30);
// Vector3d(-9,-18,-27);console.log(a.minus(b).toString());scale()
Section titled “scale()”scale(
by):Vector3d
Returns a new vector scaled by the given factor.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = new Vector(1, 2, 3);// Vector3d(2,4,6)console.log(vector.scale(2).toString());toArray()
Section titled “toArray()”toArray(): [
number,number,number]
Returns this vector as an [x, y, z] tuple.
Returns
Section titled “Returns”[number, number, number]
SDK 2.35.0
toString()
Section titled “toString()”toString():
string
Returns
Section titled “Returns”string
with()
Section titled “with()”with(
partialVector):Vector3d
Returns a new vector with the defined values from the partialPoint replacing this vector.
Null and undefined values are ignored.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let a = new Vector3d(1,2,3);let b = a.with({z: 0});// Vector3d(1,2,0)console.log(b.toString());SDK 2.37.0
create()
Section titled “create()”
staticcreate(input):Vector3d
Utility that creates a Vector3d from an input that is shaped like a Vector3d.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
input that is shaped like a Vector3d |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;Vector3d.create({x: 100, y: 200});Vector3d.create([100, 200]);Vector3d.create({x: 100, y: 200, z: 300});Vector3d.create([100, 200, 300]);Throws
Section titled “Throws”Error an invalid input
SDK 2.37.0
direction()
Section titled “direction()”
staticdirection(eye,target):Vector3d
Creates a vector pointing from one point to another (not normalized — its length is the distance between them).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
starting point |
|
|
|
ending point |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;let vector = Vector3d.direction([1,2,3],[10,20,30]);// Vector3d(9,18,27)console.log(vector.toString());fromLinearCombination()
Section titled “fromLinearCombination()”
staticfromLinearCombination(w1,v1,w2,v2):Vector3d
Combines two points using weighted coefficients:
w1 * p1 + w2 * p2. Commonly used to interpolate between
two points — for example, the midpoint is
fromLinearCombination(0.5, p1, 0.5, p2) — though the
weights don’t need to sum to 1.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
weight applied to |
|
|
|
the first point |
|
|
|
weight applied to |
|
|
|
the second point |
Returns
Section titled “Returns”Vector3d
Example
Section titled “Example”let { Vector3d } = SketchUpApi;
// Midpoint between a and blet mid = Vector3d.fromLinearCombination( 0.5, [0, 0, 0], 0.5, [10, 20, 0]);console.log(mid.toArray());// => [5, 10, 0]NOTE this function will not create a unit vector, call Vector3d.normalize in order to achieve that.
SDK 2.37.0
fromOrigin()
Section titled “fromOrigin()”
staticfromOrigin(point):Vector3d
Creates a vector from the origin to a point — its components match the point’s coordinates. Useful when you have a position and need to treat it as a direction, like passing a point’s location into a method that expects a vector.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the point defining the vector’s components |
Returns
Section titled “Returns”Vector3d
Deprecated
Section titled “Deprecated”Get Signature
Section titled “Get Signature”get to_a(): [
number,number,number]
Returns
Section titled “Returns”[number, number, number]
angle_between()
Section titled “angle_between()”angle_between(
vector2):number
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”number
parallel()
Section titled “parallel()”parallel(
vector2):boolean
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”boolean