Class

DuVector

DuVector(components)

A class to manipulate vectors
Constructor

# new DuVector(components)

Constructs a new Vector
Parameters:
Name Type Description
components Array.<Number> The components of the vector, one number per dimension

View Source Duik_api_fordoc.jsxinc, line 7366

Methods

# static fromPoints(pointA, pointB) → {DuVector}

Creates a vector from two points
Parameters:
Name Type Description
pointA Array.<Number> The origin of the vector
pointB Array.<Number> The end of the vector

View Source Duik_api_fordoc.jsxinc, line 7382

DuVector

# static unit(axis, dimensions) → {DuVector}

Creates a unit vector
Parameters:
Name Type Description
axis Number The unit axis
dimensions Number The number of dimensions

View Source Duik_api_fordoc.jsxinc, line 7400

DuVector

# add(other) → {DuVector}

Addition
Parameters:
Name Type Description
other DuVector The vector to add

View Source Duik_api_fordoc.jsxinc, line 7412

The result
DuVector

# angle(other) → {Number}

Gets the angle between the two vectors
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7549

The angle in degrees
Number

# cross(other) → {DuVector}

Cross Product
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7530

DuVector

# dot(other) → {Number}

Dot Product
Parameters:
Name Type Description
other DuVector The other vector

View Source Duik_api_fordoc.jsxinc, line 7472

Number

# hasOppositeDirection(other) → {Boolean}

Checks if the two vectors have an opposite direction
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7508

Boolean

# hasSameDirection(other) → {Boolean}

Checks if the two vectors have the same direction
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7497

Boolean

# isPerpendicular(other) → {Boolean}

Checks if the two vectors are perpendicular
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7519

Boolean

# length() → {Number}

+ The length of the vector

View Source Duik_api_fordoc.jsxinc, line 7463

The length
Number

# negate() → {DuVector}

Creates the same vector in the opposite direction (scale -1)

View Source Duik_api_fordoc.jsxinc, line 7561

DuVector

# normalize() → {DuVector}

Create a normalized vector (with length equal to 1)

View Source Duik_api_fordoc.jsxinc, line 7488

The normalized vector
DuVector

# orientation2D(other) → {Number}

Checks the orientation of the angle between 2D vectors
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7598

1: counter-clockwiser, -1: clockwise, 0: aligned
Number

# orientedAngle(other) → {Number}

Gets the angle between the two 2D vectors
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7610

Number

# projectOn(other) → {DuVector}

Projects the vector on another vector
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7570

DuVector

# scale(factor) → {DuVector}

Scale
Parameters:
Name Type Description
factor Number The scale factor

View Source Duik_api_fordoc.jsxinc, line 7448

The result
DuVector

# setLength(newLength) → {DuVector}

Sets a new length for the vector
Parameters:
Name Type Description
newLength Number

View Source Duik_api_fordoc.jsxinc, line 7580

DuVector

# subtract(other) → {DuVector}

Subtraction
Parameters:
Name Type Description
other DuVector The vector to subtract

View Source Duik_api_fordoc.jsxinc, line 7430

The result
DuVector