Vector2D
This object represents a 2D vector (X and Y values only). It is used by many other objects and can also be used with other geometry objects such as Point2D to perform calculations.
Constructor
Vector2D()
This construct an uninitialised vector with invalid x and y values which can be tested for using the .IsInvalid property.
Vector2D(double x, double y)
A vector point with the specified X and Y values x(double) the value for the x coordinate of the vector y(double) the value for the y coordinate of the vector
Vector2D(Vector2D vec)
A new vector with the same X and Y values as the passed vector vec Vector2D Note:an existing vector to copy X and Y values from
Properties
.IsInvalid
Returns: (bool) true if the vector is invalid Note: not initialised or:SetInvalid called
.Length
Returns: (the length of the vector)
.LengthSq
Returns: (the length squared of the vector. If comparing distance between points etc. using LengthSq instead of Length will be faster as it avoids the square root operation required to find the exact length.
.X or .x
Interaction: Read and Write:
Returns:(double) x coordinate for point
.Y or .y
Interaction: Read and Write
Returns:(double) y coordinate for point
Methods
:Cross( Vector2D vec)
Returns: (the cross product (a Vector3D) of this vector and passed vector
:Dot( Vector2D vec)
Returns: (the dot product (a double value) of this vector and passed vector
:Normalize()
Normalize this vector to make it a unit vector
:NormalTo()
Returns: (a new vector normal
to this vector found by rotating vector 90 degrees clockwise
:Set( double x, double y)
Set both the x and y values for the vector x(double) new x value for vector y(double) new y value for vector
:SetInvalid()
Set the vector to invalid state X and Y will be lost
Operations
Double * Vector2D
Returns: a new vector multiplied by double value
Matrix2D * Vector2D
Multiplying a matrix by a point returns a transformed vector
Vector2D + Vector2D
Adding a vector to a vector will returns a new vector.
Vector2D - Vector2D
Subtracting a vector from a point will returns a new vector.
- Vector2D
Negates x,y values of vector (reverses vector direction)
References
Please Note: The base material for the contents found in this WiKi was sourced from Vectric Lua Interface for Gadgets, version 2.05, published September 12, 2018. by Vectric Ltd. Most current document from Vertric can be downloaded at Vertric Developer Information