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 7364

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 7380

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 7398

DuVector

# add(other) → {DuVector}

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

View Source Duik_api_fordoc.jsxinc, line 7410

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 7547

The angle in degrees
Number

# cross(other) → {DuVector}

Cross Product
Parameters:
Name Type Description
other DuVector

View Source Duik_api_fordoc.jsxinc, line 7528

DuVector

# dot(other) → {Number}

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

View Source Duik_api_fordoc.jsxinc, line 7470

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 7506

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 7495

Boolean

# isPerpendicular(other) → {Boolean}

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

View Source Duik_api_fordoc.jsxinc, line 7517

Boolean

# length() → {Number}

+The length of the vector

View Source Duik_api_fordoc.jsxinc, line 7461

The length
Number

# negate() → {DuVector}

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

View Source Duik_api_fordoc.jsxinc, line 7559

DuVector

# normalize() → {DuVector}

Create a normalized vector (with length equal to 1)

View Source Duik_api_fordoc.jsxinc, line 7486

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 7596

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 7608

Number

# projectOn(other) → {DuVector}

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

View Source Duik_api_fordoc.jsxinc, line 7568

DuVector

# scale(factor) → {DuVector}

Scale
Parameters:
Name Type Description
factor Number The scale factor

View Source Duik_api_fordoc.jsxinc, line 7446

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 7578

DuVector

# subtract(other) → {DuVector}

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

View Source Duik_api_fordoc.jsxinc, line 7428

The result
DuVector