Skyline Lua API  Version 1.0 Lua Script Reference for Skyline Game Engine.
vector2 Class Reference

`#include <LUA_API_Vector2.h>`

## Public Member Functions

float dotProduct (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Calculates the dot (scalar) product of this vector with another. More...

float angle (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Gets the angle between 2 vectors. More...

float angleTo (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Gets the oriented angle between 2 vectors. More...

float crossProduct (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle. More...

float distance (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Returns the distance to another vector. More...

float2 midPoint (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Returns a vector at a point half way between this and the passed in vector. More...

float normalise (float vec1_X, float vec1_Y)
Normalises the vector. More...

float2 normalisedCopy (float vec1_X, float vec1_Y)
As normalise, except that this vector is unaffected and the normalised vector is returned as a copy. More...

float length (float vec1_X, float vec1_Y)
Returns the length (magnitude) of the vector. More...

int isNAN (float vec1_X, float vec1_Y)
Check whether this vector contains valid values. More...

int isZeroLength (float vec1_X, float vec1_Y)
Returns true if this vector is zero length. More...

float2 perpendicular (float vec1_X, float vec1_Y)
Generates a vector perpendicular to this vector (eg an 'up' vector). More...

float2 randomDeviant (float vec1_X, float vec1_Y, float randomAngle)
Generates a new random vector which deviates from this vector by a given angle in a random direction. More...

float2 reflect (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Calculates a reflection vector to the plane with the given normal . More...

float squaredDistance (float vec1_X, float vec1_Y, float vec2_X, float vec2_Y)
Returns the square of the distance to another vector. More...

float squaredLength (float vec1_X, float vec1_Y)
Returns the square of the length(magnitude) of the vector. More...

## Detailed Description

This area covers vector2 functions. Use as vector2.function(); This is a utility class that gives you access to many easy functions for vector mathmatics. For more information on how these functions can be used please visit the User Manual - https://home.aurasoft-skyline.co.uk

Example Cross Product of 2 vectors:

```Lua = crossProduct = newType.vec3(  vector2.crossProduct(vec1X, vec1Y, vec1Z, vec2X, vec2Y, vec2Z ) );
```

this is essentially doing :

```c++ = Vector2 return = vec1.crossProduct(vec2);
```

all functions that take in vec1 are the primary vector to do an operation on.

## Member Function Documentation

 float vector2::angle ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Gets the angle between 2 vectors.

Vectors do not have to be unit-length but must represent directions.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be used for the operation. vec2_Y : This is the Y Axis of the vector which will be used for the operation.
Returns
angle : This is a value in degrees of the angle between 2 vectors.
 float vector2::angleTo ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Gets the oriented angle between 2 vectors.

Vectors do not have to be unit-length but must represent directions. The angle is comprised between 0 and 2 PI.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be used for the operation. vec2_Y : This is the Y Axis of the vector which will be used for the operation.
Returns
angleDeg : This is a float representing the angle in degrees between 2 vectors.
 float vector2::crossProduct ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Calculates the 2 dimensional cross-product of 2 vectors, which results in a single floating point value which is 2 times the area of the triangle.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be used for the operation. vec2_Y : This is the Y Axis of the vector which will be used for the operation.
Returns
crossProduct : A float representing the vector3 which is the result of the cross-product. This vector will NOT be normalised, to maximise efficiency
 float vector2::distance ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Returns the distance to another vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact distance (e.g. for just comparing distances) use squaredDistance() instead.
Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be compared against. vec2_Y : This is the Y Axis of the vector which will be compared against.
Returns
distance : The distance between vectors is returned as a float
 float vector2::dotProduct ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Calculates the dot (scalar) product of this vector with another.

The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be used for the operation. vec2_Y : This is the Y Axis of the vector which will be used for the operation.
Returns
dotProduct : A float representing the dot product value.
 int vector2::isNAN ( float vec1_X, float vec1_Y )

Check whether this vector contains valid values.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
state : A boolean represented by 1 or 0 for true or false.
 int vector2::isZeroLength ( float vec1_X, float vec1_Y )

Returns true if this vector is zero length.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
state : A boolean represented by 1 or 0 for true or false.
 float vector2::length ( float vec1_X, float vec1_Y )

Returns the length (magnitude) of the vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.
Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
length : This will return the length of the vector. magnitude = (x1*x2) + (y1*y2) + (z1*z2);
 float2 vector2::midPoint ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Returns a vector at a point half way between this and the passed in vector.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be used for the operation. vec2_Y : This is the Y Axis of the vector which will be used for the operation.
Returns
midpoint : This will return a float2 representing a vector position that sits halfway between the 2 inputted vectors.
 float vector2::normalise ( float vec1_X, float vec1_Y )

Normalises the vector.

This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.

Note
This function will not crash for zero-sized vectors, but there will be no changes made to their components.
Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
previousLength : The previous length of the vector.
 float2 vector2::normalisedCopy ( float vec1_X, float vec1_Y )

As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
normalised : This will return the normalised vector as float2.
 float2 vector2::perpendicular ( float vec1_X, float vec1_Y )

Generates a vector perpendicular to this vector (eg an 'up' vector).

This method will return a vector which is perpendicular to vector 1. There are an infinite number of possibilities but this method will guarantee to generate one of them.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
perpVector : A Perpendicular vector to the one pass through is returned as a float2.
 float2 vector2::randomDeviant ( float vec1_X, float vec1_Y, float randomAngle )

Generates a new random vector which deviates from this vector by a given angle in a random direction.

This method assumes that the random number generator has already been seeded appropriately.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. angleDeg : The angle at which to deviate
Returns
randVector : A random vector which deviates from this vector by angle. This vector will not be normalised, normalise it if you wish afterwards.
 float2 vector2::reflect ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Calculates a reflection vector to the plane with the given normal .

NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the normal to reflect on. vec2_Y : This is the Y Axis of the normal to reflect on.
Returns
reflectVector : A vector which is reflected by the normal.
 float vector2::squaredDistance ( float vec1_X, float vec1_Y, float vec2_X, float vec2_Y )

Returns the square of the distance to another vector.

This method is for efficiency - calculating the actual distance to another vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the distance to another vector, i.e. the same as the distance but before the square root is taken. Use this if you want to find the longest / shortest distance without incurring the square root.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on. vec2_X : This is the X Axis of the vector which will be compared against. vec2_Y : This is the Y Axis of the vector which will be compared against.
Returns
distance : A single float representing the distance between 2 vectors.
 float vector2::squaredLength ( float vec1_X, float vec1_Y )

Returns the square of the length(magnitude) of the vector.

This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.

Parameters
 vec1_X : This is the X Axis of the vector which you are going to use an operation on. vec1_Y : This is the Y Axis of the vector which you are going to use an operation on.
Returns
length : A single float representing the squared length of the vector.

The documentation for this class was generated from the following file: