FlexScript Class - Vec2

# Vec2

### Description

Represents positions, rotations, size, 2D vectors, and points. Contains functions for doing common vector operations.

### Properties

 magnitude The length of this vector (Read Only). normalized The vector sized to a magnitude of 1 (Read Only). x X component of the vector. y Y component of the vector.

### Methods

 angle Finds the angle between this vector and another (degrees). dot Finds the dot product of this vector and another. lerp Linearly interpolates between two vectors. rotate Rotates the vector about another vector.

### Constructor

 Vec2 Constructs a vector by xy component values.

### Operators

 - Subtracts one vector from another. != Compares two vectors. * Multiplies a vector by another vector or a scale factor. / Divides a vector by another vector or a scale factor. + Adds two vectors together. += Assigns the vector to be the sum of two vectors. -= Assigns the vector to be the difference of two vectors. == Compares two vectors. unary - Negates the vector.

## Details

Do no remove, this fixes the anchor on doc.flexsim.com

### Description

The length of this vector (Read Only).

The length of the vector is calculated as the square root of (x*x+y*y).

Do no remove, this fixes the anchor on doc.flexsim.com

### Description

The vector sized to a magnitude of 1 (Read Only).

A copy of the original vector that points in the same direction, but has a length of 1.

Do no remove, this fixes the anchor on doc.flexsim.com

### Description

X component of the vector.

Do no remove, this fixes the anchor on doc.flexsim.com

### Description

Y component of the vector.

Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.angle()

 double angle( Vec2 otherVec )

### Parameters

 otherVec The angle extends round to this vector.

### Returns

 double The angle between the two vectors in degrees.

### Description

Finds the angle between this vector and another (degrees).

`double angle = myVector.angle(Vec2(1, 2));`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.dot()

 double dot( Vec2 otherVec )

### Parameters

 otherVec The vector to dot with this vector.

### Returns

 double The dot product (double) of the two vectors.

### Description

Finds the dot product of this vector and another.

`double dot = myVector.dot(Vec2(1, 2));`

The dot product of two vectors is a number equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them.

Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.lerp()

 Vec2 lerp( Vec2 otherVec , double t )

### Parameters

 otherVec The vector to interpolate to. t A ratio between 0 and 1 that defines the percentage to interpolate from the current vector to otherVec.

### Returns

 Vec2 The resulting interpolated vector.

### Description

Linearly interpolates between two vectors.

The following example code sets the location vector to 20% on the path from myVector to Vec2(1,2).

`Vec2 location = myVector.lerp(Vec2(1, 2), .2);`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.rotate()

 Vec2 rotate( double degrees ) Vec2 rotate( double degrees , Vec2 otherVec )

### Parameters

 degrees The angle of rotation. otherVec The vector rotate about.

### Returns

 Vec2 The resulting vector.

### Description

Rotates the vector about another vector.

The origin will be used as the rotation point if no other vector is defined

The following example code returns the new vector after rotating myVector about Vec2(1,2) by 45 degrees.

`Vec2 location = myVector.rotate(45, Vec2(1, 2));`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2 Constructor

 Vec2( double x , double y ) Vec2( double value )

### Parameters

 x The x component. y The y component. value A value all components will be set to.

### Description

Constructs a vector by xy component values.

`Vec2 location = Vec2(1, 2);``Vec2 location = Vec2(0);`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator -

 Vec2 operator -( Vec2 otherVec )

### Parameters

 otherVec The vector to subtract from this one.

### Returns

 Vec2 The resulting vector.

### Description

Subtracts one vector from another.

Each component has the corresponding component subtracted from it.

`Vec2 location = someVector - anotherVector;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator !=

 int operator !=( Vec2 otherVec )

### Parameters

 otherVec The vector to compare to this vector.

### Returns

 int True if the two vectors are different, false otherwise.

### Description

Compares two vectors.

`int isNotZero = location != Vec2(0, 0);`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator *

 Vec2 operator *( Vec2 otherVec ) Vec2 operator *( double factor )

### Parameters

 otherVec The vector to multiply this vector by. factor A scale factor to multiply each component by.

### Returns

 Vec2 The resulting vector.

### Description

Multiplies a vector by another vector or a scale factor.

When a Vec2 is passed, the operation will perform per-component multiplication.

`Vec2 location = someVector * anotherVector;``Vec2 location = someVector * 1.2;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator /

 Vec2 operator /( Vec2 otherVec ) Vec2 operator /( double factor )

### Parameters

 otherVec The vector to divide this vector by. factor A scale factor to divide each component by.

### Returns

 Vec2 The resulting vector.

### Description

Divides a vector by another vector or a scale factor.

When a Vec2 is passed, the operation will perform per-component division.

`Vec2 location = someVector / anotherVector;``Vec2 location = someVector / 1.2;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator +

 Vec2 operator +( Vec2 otherVec )

### Parameters

 otherVec The vector to add to this one.

### Returns

 Vec2 The resulting vector.

### Description

Each component is added to the corresponding component.

`Vec2 location = someVector + anotherVector;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator +=

 Vec2 operator +=( Vec2 otherVec )

### Parameters

 otherVec The vector to add to this one.

### Returns

 Vec2 The resulting vector.

### Description

Assigns the vector to be the sum of two vectors.

Each component is added to the corresponding component.

`Vec2 location += someVector;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator -=

 Vec2 operator -=( Vec2 otherVec )

### Parameters

 otherVec The vector to subtract from this one.

### Returns

 Vec2 The resulting vector.

### Description

Assigns the vector to be the difference of two vectors.

Each component has the corresponding component subtracted from it.

`Vec2 location -= someVector;`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator ==

 int operator ==( Vec2 otherVec )

### Parameters

 otherVec The vector to compare to this vector.

### Returns

 int True if both vectors are exactly the same, false otherwise.

### Description

Compares two vectors.

`int isZero = location == Vec2(0, 0);`
Do no remove, this fixes the anchor on doc.flexsim.com

### Vec2.operator unary -

 Vec2 operator unary -( )

### Returns

 Vec2 The resulting vector.

### Description

Negates the vector.

Each component is negated.

`Vec2 location = -location;`