2-dimensional vector class

Constructor

@:value({ y : 0, x : 0 })@:implinlinenew(x:Float = 0, y:Float = 0)

Variables

@:impldegrees:Float

The angle formed by the vector with the horizontal axis (in degrees)

@:implread onlydx:Float

The horizontal component of the unit vector

@:implread onlydy:Float

The vertical component of the unit vector

@:impllength:Float

Length of the vector

@:implread onlylengthSquared:Float

length of the vector squared

@:implread onlylx:Float

The horizontal component of the left normal of the vector

@:implread onlyly:Float

The vertical component of the left normal of the vector

@:implradians:Float

The angle formed by the vector with the horizontal axis (in radians)

@:implread onlyrx:Float

The horizontal component of the right normal of the vector

@:implread onlyry:Float

The vertical component of the right normal of the vector

@:implx:Float

@:imply:Float

Methods

@:value({ y : 0, x : 0 })@:implinlineadd(this:FlxPoint, x:Float = 0):FlxVector

Adds to the coordinates of this point.

Parameters:

x

Amount to add to x

y

Amount to add to y

Returns:

This point.

@:implinlineaddNew(this:FlxPoint):FlxVector

Return new vector which equals to sum of this vector and passed v vector.

Parameters:

v

vector to add

Returns:

addition result

@:implinlineaddPoint(this:FlxPoint):FlxVector

Adds the coordinates of another point to the coordinates of this point.

Parameters:

point

The point to add to this point

Returns:

This point.

@:value({ bounceCoeff : 1 })@:implinlinebounce(this:FlxPoint, normal:FlxVector):FlxVector

Reflect the vector with respect to the normal of the "wall".

Parameters:

normal

left normal of the "wall". It must be normalized (no checks)

bounceCoeff

bounce coefficient (0 <= bounceCoeff <= 1)

Returns:

reflected vector (angle of incidence equals to angle of reflection)

@:value({ friction : 0, bounceCoeff : 1 })@:implinlinebounceWithFriction(this:FlxPoint, normal:FlxVector, bounceCoeff:Float = 1):FlxVector

Reflect the vector with respect to the normal. This operation takes "friction" into account.

Parameters:

normal

left normal of the "wall". It must be normalized (no checks)

bounceCoeff

bounce coefficient (0 <= bounceCoeff <= 1)

friction

friction coefficient

Returns:

reflected vector

@:implinlineceil():FlxVector

Rounds x and y using Math.ceil()

@:implclone(this:FlxPoint):FlxVector

Copies this vector.

Parameters:

vec

optional vector to copy this vector to

Returns:

copy of this vector

@:implinlinecopyFrom(this:FlxPoint):FlxVector

Helper function, just copies the values from the specified point.

Parameters:

point

Any FlxPoint.

Returns:

A reference to itself.

@:implinlinecopyFromFlash(this:FlxPoint):FlxVector

Helper function, just copies the values from the specified Flash point.

Parameters:

Point

Any Point.

Returns:

A reference to itself.

@:implinlinecrossProductLength(this:FlxPoint):Float

Find the length of cross product between two vectors.

Parameters:

v

vector to multiply

Returns:

the length of cross product of two vectors

@:implinlinedegreesBetween(this:FlxPoint):Float

The angle between vectors (in degrees).

Parameters:

v

second vector, which we find the angle

Returns:

the angle in radians

@:implinlinedist(this:FlxPoint):Float

The distance between points

@:implinlinedistSquared(this:FlxPoint):Float

The squared distance between points

@:implinlinedotProdWithNormalizing(this:FlxPoint):Float

Dot product of vectors with normalization of the second vector.

Parameters:

v

vector to multiply

Returns:

dot product of two vectors

@:implinlinedotProduct(this:FlxPoint):Float

Dot product between two vectors.

Parameters:

v

vector to multiply

Returns:

dot product of two vectors

@:implfindIntersection(this:FlxPoint, a:FlxVector, b:FlxVector, v:FlxVector):FlxVector

Finding the point of intersection of vectors.

Parameters:

a

start point of the vector

b

start point of the v vector

v

the second vector

Returns:

the point of intersection of vectors

@:implfindIntersectionInBounds(this:FlxPoint, a:FlxVector, b:FlxVector, v:FlxVector):FlxVector

Finding the point of intersection of vectors if it is in the "bounds" of the vectors.

Parameters:

a

start point of the vector

b

start point of the v vector

v

the second vector

Returns:

the point of intersection of vectors if it is in the "bounds" of the vectors

@:implinlinefloor():FlxVector

Rounds x and y using Math.floor()

@:implinlineisNormalized():Bool

Check the vector for unit length

@:implinlineisParallel(this:FlxPoint):Bool

Check for parallelism of two vectors.

Parameters:

v

vector to check

Returns:

true - if they are parallel

@:implinlineisPerpendicular(this:FlxPoint):Bool

Check the perpendicularity of two vectors.

Parameters:

v

vector to check

Returns:

true - if they are perpendicular

@:implinlineisValid():Bool

Checking if this is a valid vector.

Returns:

true - if the vector is valid

@:implinlineisZero():Bool

Check if this vector has zero length.

Returns:

true - if the vector is zero

@:implleftNormal(this:FlxPoint):FlxVector

Left normal of the vector

@:implinlinenegate():FlxVector

Change direction of the vector to opposite

@:implinlinenegateNew():FlxVector

@:implnormalize():FlxVector

Normalization of the vector (reduction to unit length)

@:implinlineperpProduct(this:FlxPoint):Float

Dot product of left the normal vector and vector v.

@:implprojectTo(this:FlxPoint, v:FlxVector):FlxVector

The projection of this vector to vector that is passed as an argument (without modifying the original Vector!).

Parameters:

v

vector to project

proj

optional argument - result vector

Returns:

projection of the vector

@:implprojectToNormalized(this:FlxPoint, v:FlxVector):FlxVector

Projecting this vector on the normalized vector v.

Parameters:

v

this vector has to be normalized, ie have unit length

proj

optional argument - result vector

Returns:

projection of the vector

@:implinlineradiansBetween(this:FlxPoint):Float

Get the angle between vectors (in radians).

Parameters:

v

second vector, which we find the angle

Returns:

the angle in radians

@:implinlineratio(this:FlxPoint, a:FlxVector, b:FlxVector):Float

Find the ratio between the perpProducts of this vector and v vector. This helps to find the intersection point.

Parameters:

a

start point of the vector

b

start point of the v vector

v

the second vector

Returns:

the ratio between the perpProducts of this vector and v vector

@:implrightNormal(this:FlxPoint):FlxVector

Right normal of the vector

@:implrotate(this:FlxPoint, pivot:FlxPoint):FlxVector

Rotates this point clockwise in 2D space around another point by the given angle.

Parameters:

Pivot

The pivot you want to rotate this point around

Angle

Rotate the point by this many degrees clockwise.

Returns:

A FlxPoint containing the coordinates of the rotated point.

@:implinlinerotateByDegrees(this:FlxPoint):FlxVector

Rotate the vector for a given angle.

Parameters:

degs

angle to rotate

Returns:

rotated vector

@:implinlinerotateByRadians(this:FlxPoint):FlxVector

Rotate the vector for a given angle.

Parameters:

rads

angle to rotate

Returns:

rotated vector

@:implinlinerotateWithTrig(this:FlxPoint, sin:Float):FlxVector

Rotate the vector with the values of sine and cosine of the angle of rotation.

Parameters:

sin

the value of sine of the angle of rotation

cos

the value of cosine of the angle of rotation

Returns:

rotated vector

@:implinlineround():FlxVector

Rounds x and y using Math.round()

@:implinlinescale(this:FlxPoint):FlxVector

Scale this vector.

Parameters:

k
  • scale coefficient

Returns:

scaled vector

@:implinlinescaleNew(this:FlxPoint):FlxVector

Returns scaled copy of this vector.

Parameters:

k
  • scale coefficient

Returns:

scaled vector

@:value({ y : 0, x : 0 })@:implinlineset(this:FlxPoint, x:Float = 0):FlxVector

Set the coordinates of this point object.

Parameters:

x

The X-coordinate of the point in space.

y

The Y-coordinate of the point in space.

@:implsign(this:FlxPoint, a:FlxVector):Int

The sign of half-plane of point with respect to the vector through the a and b points.

Parameters:

a

start point of the wall-vector

b

end point of the wall-vector

@:value({ y : 0, x : 0 })@:implinlinesubtract(this:FlxPoint, x:Float = 0):FlxVector

Subtracts from the coordinates of this point.

Parameters:

x

Amount to subtract from x

y

Amount to subtract from y

Returns:

This point.

@:implinlinesubtractNew(this:FlxPoint):FlxVector

Returns new vector which is result of subtraction of v vector from this vector.

Parameters:

v

vector to subtract

Returns:

subtraction result

@:implinlinesubtractPoint(this:FlxPoint):FlxVector

Subtracts the coordinates of another point from the coordinates of this point.

Parameters:

point

The point to subtract from this point

Returns:

This point.

@:implinlinetransform(this:FlxPoint):FlxVector

Applies transformation matrix to this point

Parameters:

matrix

transformation matrix

Returns:

transformed point

@:implinlinetruncate(this:FlxPoint):FlxVector

Limit the length of this vector.

Parameters:

max

maximum length of this vector

@:implinlinezero():FlxVector

Vector reset

Static variables

@:value(0.0000001)staticinlineread onlyEPSILON:Float = 0.0000001

@:value(EPSILON * EPSILON)staticinlineread onlyEPSILON_SQUARED:Float = EPSILON * EPSILON

staticread onlypool:IFlxPool<FlxPoint>

Static methods

@:value({ y : 0, x : 0 })staticinlineget(x:Float = 0, y:Float = 0):FlxVector

Recycle or create new FlxVector. Be sure to put() them back into the pool after you're done with them!

Parameters:

x

The X-coordinate of the point in space.

y

The Y-coordinate of the point in space.

@:value({ y : 0, x : 0 })staticinlineweak(x:Float = 0, y:Float = 0):FlxVector

Recycle or create a new FlxVector which will automatically be released to the pool when passed into a flixel function.

Parameters:

x

The X-coordinate of the point in space.

y

The Y-coordinate of the point in space.

Available since

4.6.0

.