# Vector

A vector composed of components (X, Y, Z) with floating point precision.

##### Tip

This structure is Open Sourced at https://github.com/nanos-world/nanos-world-lua-lib. Feel free to push merge requests and suggest changes!

##### info

Vectors are internally and automatically compressed, which reduces it's size in the network up to 90%. Some cool details:

• Vectors parameters in Classes Methods are usually compressed with precision of 1 decimal place (with some exceptions which we need more precision).
• Vectors passed in Remote Events are compressed with precision of 2 decimal places. If you need more precision, we recommend passing them as raw number instead.

## π Usageβ

``local new_vector = Vector(1452.5, 512, 943.1)``

## π Propertiesβ

TypeNameDescription
number`X`X Coordinate
number`Y`Y Coordinate
number`Z`Z Coordinate

##### tip

Note: This structure supports `+`, `-`, `*`, `/`, `^`, `==`, and `tostring` operations.

ReturnsNameDescription
boolean`Equals(other, tolerance)`Check against another vector for equality, within specified error limits
number`Distance(other)`Distance between two points
number`DistanceSquared(other)`Squared distance between two points
Vector`GetUnsafeNormal()`Calculates normalized version of vector without checking for zero length
Vector`GetSafeNormal()`Gets a normalized copy of the vector, checking it is safe to do so based on the length
boolean`IsNearlyZero(tolerance)`Checks whether vector is near to zero within a specified tolerance
boolean`IsZero()`Checks whether all components of the vector are exactly zero
boolean`Normalize()`Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not
number`Size()`Get the length (magnitude) of this vector
number`SizeSquared()`Get the squared length of this vector
Rotator`Rotation()`Returns the orientation corresponding to the direction in which the vector points