Skip to content

Lua:Vector2D

anotak edited this page Jun 27, 2018 · 5 revisions

Properties

This is useful for doing Math on 2D vectors of X & Y. One of the more helpful aspects is that you can do math on them as if they were numbers, for example:

a = Vector2D.From(2,3)
b = Vector2D.From(1,4)
c = a + b -- c ends up being equal to (3,7)

x

y

note x/y are readonly because of weird internal technical reasons. (thinking out loud: should I change them to .GetX() / .GetY() for that reason?) if you want to change them, see .WithX() / .WithY()

Static Methods

From(a)

From(x,y)

DotProduct(a,b)

CrossProduct(a,b)

Reflect(v,m)

Reversed(r)

FromAngle(angle)

FromAngle(angle,length)

SnappedToGrid(v)

SnappedToAccuracy(v)

GetAngle(a,b)

DistanceSq(a,b)

Distance(a,b)

ManhattanDistance(a,b)

see the wikipedia article on manhattan distance

Methods

WithX(nx)

returns a new vector with a given X and the original Y. so if you want to change some_vector's x to 5, you can do some_vector = some_vector.WithX(5) for example

WithY(ny)

GetPerpendicular()

GetSign()

GetAngle()

GetLength()

GetLengthSq()

GetManhattanLength()

see the wikipedia article on manhattan distance

GetNormal()

GetScaled(s)

ToString()

GetTransformed(offsetx,offsety,scalex,scaley)

GetInvTransformed(invoffsetx,invoffsety,invscalex,invscaley)

GetRotated(theta)

IsFinite()

IsFinite() returns false if either coordinate is positive/negative infinity or NaN. If you try to use move vertices or things to non-finite positions, you will get a script error, so it may be useful to check that this returns true on your Vector2Ds if you are doing division or checking for line intersections.

GetHashCode()

Equals(vec)

Clone this wiki locally