Link Search Menu Expand Document

Vector

fermat.js/src/vector.ts#L12

Class Vector

A n-dimensional Vector class.

Extends Array<number>

constructor (args: Array<number>): Vector

Name Type Default Description
args Array<number>    

readonly Property .[Symbol.species] : ArrayConstructor

Property .length : number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

Accessor .magnitude : number

Returns the magnitude of the Vector

Accessor .unitVector

Returns the unitVector of the Vector

Method .[Symbol.iterator] (): IterableIterator<number>

Iterator

Method .[Symbol.unscopables] (): {copyWithin: boolean, entries: boolean, fill: boolean, find: boolean, findIndex: boolean, keys: boolean, values: boolean}

Returns an object whose properties have the value ‘true’ when they will be absent when used in a ‘with’ statement.

Method .concat (items: Array<ConcatArray<number>>): Array<number>

Combines two or more arrays. This method returns a new array without modifying any existing arrays.

Name Type Default Description
items Array<ConcatArray<number>>    

Combines two or more arrays. This method returns a new array without modifying any existing arrays.

Name Type Default Description  
items Array<number ConcatArray<number>>    

Method .copyWithin (target: number, start: number, end: number): Vector

Returns the this object after copying a section of the array identified by start and end to the same array starting at position target

Name Type Default Description
target number    
start number    
end number    

Method .entries (): IterableIterator<[number, number]>

Returns an iterable of key, value pairs for every entry in the array

Method .every (predicate: (value: number, index: number, array: Array<number>): value is S, thisArg: any): this is Array<S>

Determines whether all the members of an array satisfy the specified test.

Name Type Default Description
predicate (value: number, index: number, array: Array<number>): value is S    
thisArg any    

Determines whether all the members of an array satisfy the specified test.

Name Type Default Description
predicate (value: number, index: number, array: Array<number>): unknown    
thisArg any    

Method .fill (value: number, start: number, end: number): Vector

Returns the this object after filling the section identified by start and end with value

Name Type Default Description
value number    
start number    
end number    

Method .filter (predicate: (value: number, index: number, array: Array<number>): value is S, thisArg: any): Array<S>

Returns the elements of an array that meet the condition specified in a callback function.

Name Type Default Description
predicate (value: number, index: number, array: Array<number>): value is S    
thisArg any    

Returns the elements of an array that meet the condition specified in a callback function.

Name Type Default Description
predicate (value: number, index: number, array: Array<number>): unknown    
thisArg any    

Method .find (predicate: (value: number, index: number, obj: Array<number>): value is S, thisArg: any): undefined|S

Returns the value of the first element in the array where predicate is true, and undefined otherwise.

Name Type Default Description
predicate (value: number, index: number, obj: Array<number>): value is S    
thisArg any    
Name Type Default Description
predicate (value: number, index: number, obj: Array<number>): unknown    
thisArg any    

Method .findIndex (predicate: (value: number, index: number, obj: Array<number>): unknown, thisArg: any): number

Returns the index of the first element in the array where predicate is true, and -1 otherwise.

Name Type Default Description
predicate (value: number, index: number, obj: Array<number>): unknown    
thisArg any    

Method .forEach (callbackfn: (value: number, index: number, array: Array<number>): void, thisArg: any): void

Performs the specified action for each element in an array.

Name Type Default Description
callbackfn (value: number, index: number, array: Array<number>): void    
thisArg any    

Method .from (arrayLike: ArrayLike<T>): Array<T>

Creates an array from an array-like object.

Name Type Default Description
arrayLike ArrayLike<T>    

Creates an array from an iterable object.

Name Type Default Description
arrayLike ArrayLike<T>    
mapfn (v: T, k: number): U    
thisArg any    

Creates an array from an iterable object.

Name Type Default Description  
iterable Iterable<T> ArrayLike<T>    

Creates an array from an iterable object.

Name Type Default Description  
iterable Iterable<T> ArrayLike<T>    
mapfn (v: T, k: number): U      
thisArg any      

Method .includes (searchElement: number, fromIndex: number): boolean

Determines whether an array includes a certain element, returning true or false as appropriate.

Name Type Default Description
searchElement number    
fromIndex number    

Method .indexOf (searchElement: number, fromIndex: number): number

Returns the index of the first occurrence of a value in an array, or -1 if it is not present.

Name Type Default Description
searchElement number    
fromIndex number    

Method .isArray (arg: any): arg is Array<any>

Name Type Default Description
arg any    

Method .join (separator: string): string

Adds all the elements of an array into a string, separated by the specified separator string.

Name Type Default Description
separator string    

Method .keys (): IterableIterator<number>

Returns an iterable of keys in the array

Method .lastIndexOf (searchElement: number, fromIndex: number): number

Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.

Name Type Default Description
searchElement number    
fromIndex number    

Method .map (callbackfn: (value: number, index: number, array: Array<number>): U, thisArg: any): Array<U>

Calls a defined callback function on each element of an array, and returns an array that contains the results.

Name Type Default Description
callbackfn (value: number, index: number, array: Array<number>): U    
thisArg any    

Method .of (items: Array<T>): Array<T>

Returns a new array from a set of elements.

Name Type Default Description
items Array<T>    

Method .pop (): undefined|number

Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.

Method .push (items: Array<number>): number

Appends new elements to the end of an array, and returns the new length of the array.

Name Type Default Description
items Array<number>    

Method .reduce (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number): number

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Name Type Default Description
callbackfn (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number    
Name Type Default Description
callbackfn (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number    
initialValue number    

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Name Type Default Description
callbackfn (previousValue: U, currentValue: number, currentIndex: number, array: Array<number>): U    
initialValue U    

Method .reduceRight (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number): number

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Name Type Default Description
callbackfn (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number    
Name Type Default Description
callbackfn (previousValue: number, currentValue: number, currentIndex: number, array: Array<number>): number    
initialValue number    

Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Name Type Default Description
callbackfn (previousValue: U, currentValue: number, currentIndex: number, array: Array<number>): U    
initialValue U    

Method .reverse (): Array<number>

Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array.

Method .scale (q: number): Array<number>

Scales this vector by a factor q.

Name Type Default Description
q number    

Method .shift (): undefined|number

Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.

Method .slice (start: number, end: number): Array<number>

Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.

Name Type Default Description
start number    
end number    

Method .some (predicate: (value: number, index: number, array: Array<number>): unknown, thisArg: any): boolean

Determines whether the specified callback function returns true for any element of an array.

Name Type Default Description
predicate (value: number, index: number, array: Array<number>): unknown    
thisArg any    

Method .sort (compareFn: (a: number, b: number): number): Vector

Sorts an array in place. This method mutates the array and returns a reference to the same array.

Name Type Default Description
compareFn (a: number, b: number): number    

Method .splice (start: number, deleteCount: number): Array<number>

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

Name Type Default Description
start number    
deleteCount number    

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

Name Type Default Description
start number    
deleteCount number    
items Array<number>    

Method .toLocaleString (): string

Returns a string representation of an array. The elements are converted to string using their toLocalString methods.

Method .toString (): string

Returns a string representation of an array.

Method .unshift (items: Array<number>): number

Inserts new elements at the start of an array, and returns the new length of the array.

Name Type Default Description
items Array<number>    

Method .values (): IterableIterator<number>

Returns an iterable of values in the array

static Method .cross (v1: Vector, v2: Vector): Vector

Finds the cross product of two 3-dimensional vectors v1 and v2.

Name Type Default Description
v1 Vector    
v2 Vector    

static Method .difference (v1: Vector, v2: Vector): Array<number>

Calculates the difference of two vectors v1 and v2.

Name Type Default Description
v1 Vector    
v2 Vector    

static Method .dot (v1: Vector, v2: Vector): number

Calculates the dot product of two vectors v1 and v2.

Name Type Default Description
v1 Vector    
v2 Vector    

static Method .equals (v1: Vector, v2: Vector): boolean

Checks if two vectors are equal.

Name Type Default Description
v1 Vector    
v2 Vector    

static Method .product (v1: Vector, v2: Vector): Array<number>

Calculates the element-wise product of two vectors v1 and v2.

Name Type Default Description
v1 Vector    
v2 Vector    

static Method .sum (v1: Vector, v2: Vector): Array<number>

Calculates the sum of two vectors v1 and v2.

Name Type Default Description
v1 Vector    
v2 Vector    

Copyright © 2021 Mathigon.org