3-dimensional Point class

Pooling

To avoid creating new instances, unnecessarily, used FlxPoint3Ds can be for later use. Rather than creating a new instance directly, call FlxPoint3D.get(x, y) and it will retrieve a Point from the pool, if one exists, otherwise it will create a new instance. Similarly, when you're done using a Point, call myPoint3D.put() to place it back.

You can disable Point pooling entirely with FLX_NO_Point3D_POOL.

Weak FlxPoint3Ds

Weak FlxPoint3Ds are FlxPoint3Ds meant for a singular use, rather than calling put on every Point you get, you can create a weak Point, and have it placed back once used. All FlxPoint3D methods and Flixel utilities automatically call putWeak() on every Point passed in.

In the following example, a weak Point is created, and passed into p.degreesTo where putWeak is called on it, putting it back in the pool.

var angle = p.degreesTo(FlxPoint3D.weak(FlxG.mouse.x, FlxG.mouse.y));

Overloaded Operators

  • A += B adds the value of B to A
  • A -= B subtracts the value of B from A
  • A *= k scales A by float k in both x and y components
  • A + B returns a new Point that is sum of A and B
  • A - B returns a new Point that is difference of A and B
  • A * k returns a new Point that is A scaled with coefficient k

Note: also accepts openfl.geom.Point, but always returns a FlxPoint3D.

Note: that these operators get FlxPoint3Ds from the pool, but do not put FlxPoint3Ds back in the pool, unless they are weak.

Example: 4 total FlxPoint3Ds are created, but only 3 are put into the pool

var a = FlxPoint3D.get(1, 1);
var b = FlxPoint3D.get(1, 1);
var c = (a * 2.0) + b;
a.put();
b.put();
c.put();

To put all 4 back, it should look like this:

var a = FlxPoint3D.get(1, 1);
var b = FlxPoint3D.get(1, 1);
var c = a * 2.0;
var d = c + b;
a.put();
b.put();
c.put();
d.put();

Otherwise, the remainging FlxPoint3Ds will become garbage, adding to the heap, potentially triggering a garbage collection when you don't want.

Static variables

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

Vector components less than this are considered zero, to account for rounding errors

@:value(EPSILON * FlxMath.SQUARE_ROOT_OF_TWO)staticinlineread onlyEPSILON_LENGTH:Float = EPSILON * FlxMath.SQUARE_ROOT_OF_TWO

Vector lengths less than this are considered zero, to account for rounding errors

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

staticdegrees:Float

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

staticread onlydx:Float

The horizontal component of the unit Point

staticread onlydy:Float

The vertical component of the unit Point

staticread onlydz:Float

staticlength:Float

Length of the Point

staticread onlylengthSquared:Float

length of the Point squared

staticread onlylx:Float

The horizontal component of the left normal of the Point

staticread onlyly:Float

The vertical component of the left normal of the Point

staticradians:Float

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

staticread onlyrx:Float

The horizontal component of the right normal of the Point

staticread onlyry:Float

The vertical component of the right normal of the Point

staticx:Float

staticy:Float

staticz:Float

Static methods

@:value({ z : 0, y : 0, x : 0 })staticinlineadd(this:FlxBasePoint3D, x:Float = 0, y:Float = 0, z:Float = 0):FlxPoint3D

staticinlineadd(this:FlxBasePoint3D, p:Vector3D):FlxPoint3D

staticinlineadd(this:FlxBasePoint3D, Point:FlxPoint3D):FlxPoint3D

Adds to the coordinates of this Point.

Parameters:

x

Amount to add to x

y

Amount to add to y

Returns:

This Point.

staticinlineaddNew(this:FlxBasePoint3D, p:FlxPoint3D):FlxPoint3D

Return new Point which equals to sum of this Point and passed p Point.

Parameters:

p

Point to add

Returns:

addition result

staticinlineaddPoint3D(this:FlxBasePoint3D, Point:FlxPoint3D):FlxPoint3D

Deprecated: "addPoint3D is deprecated, use add(Point), instead"

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

Parameters:

Point

The Point to add to this Point

Returns:

This Point.

staticinlineaddToFlash(this:FlxBasePoint3D, p:Vector3D):Vector3D

Helper function, just increases the values of the specified Flash Point by the values of this Point.

Parameters:

p

Any Point.

Returns:

A reference to the altered Point parameter.

@:value({ bounceCoeff : 1 })staticinlinebounce(this:FlxBasePoint3D, normal:FlxPoint3D, bounceCoeff:Float = 1):FlxPoint3D

Reflect the Point 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 Point (angle of incidence equals to angle of reflection)

@:value({ friction : 0, bounceCoeff : 1 })staticinlinebounceWithFriction(this:FlxBasePoint3D, normal:FlxPoint3D, bounceCoeff:Float = 1, friction:Float = 0):FlxPoint3D

Reflect the Point 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 Point

staticinlineceil(this:FlxBasePoint3D):FlxPoint3D

Rounds x and y using Math.ceil()

staticinlineclone(this:FlxBasePoint3D, ?p:FlxPoint3D):FlxPoint3D

Copies this Point.

Parameters:

p

An optional Point to copy this Point to

Returns:

The new Point

staticinlinecopyFrom(this:FlxBasePoint3D, p:FlxPoint3D):FlxPoint3D

staticinlinecopyFrom(this:FlxBasePoint3D, p:Vector3D):FlxPoint3D

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

Parameters:

p

Any FlxPoint3D.

Returns:

A reference to itself.

staticinlinecopyFromFlash(this:FlxBasePoint3D, p:Vector3D):FlxPoint3D

Deprecated: "copyFromFlash is deprecated, use copyFrom, instead"

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

Parameters:

p

Any Point.

Returns:

A reference to itself.

staticinlinecopyTo(this:FlxBasePoint3D, ?p:FlxPoint3D):FlxPoint3D

staticinlinecopyTo(this:FlxBasePoint3D, p:Vector3D):Vector3D

Helper function, just copies the values from this Point to the specified Point.

Parameters:

p

An optional Point to copy this Point to

Returns:

The new Point

staticinlinecopyToFlash(this:FlxBasePoint3D, ?p:Vector3D):Vector3D

Deprecated: "copyToFlash is deprecated, use copyTo, instead"

Helper function, just copies the values from this Point to the specified Flash Point.

Parameters:

p

Any Point.

Returns:

A reference to the altered Point parameter.

staticinlinecrossProductLength(this:FlxBasePoint3D, p:FlxPoint3D):Float

Find the length of cross product between two FlxPoint3Ds.

Parameters:

p

Point to multiply

Returns:

the length of cross product of two FlxPoint3Ds

staticinlinedegreesBetween(this:FlxBasePoint3D, p:FlxPoint3D):Float

The angle between FlxPoint3Ds (in degrees).

Parameters:

p

second Point, which we find the angle

Returns:

the angle in degrees

staticinlinedegreesFrom(this:FlxBasePoint3D, Point:FlxPoint3D):Float

Calculates the angle from another Point to this. If this is straight right of the Point, 0 is returned.

Parameters:

Point

The other Point.

Returns:

The angle, in degrees, between -180 and 180

Available since

5.0.0

.

staticinlinedegreesTo(this:FlxBasePoint3D, Point:FlxPoint3D):Float

Calculates the angle from this to another Point. If the Point is straight right of this, 0 is returned.

Parameters:

Point

The other Point.

Returns:

The angle, in degrees, between -180 and 180

Available since

5.0.0

.

staticinlinedist(this:FlxBasePoint3D, x:Float, y:Float):Float

staticinlinedist(this:FlxBasePoint3D, p:FlxPoint3D):Float

The distance between FlxPoint3Ds

Available since

6.0.0

.

staticinlinedistSquared(this:FlxBasePoint3D, p:FlxPoint3D):Float

staticinlinedistSquared(this:FlxBasePoint3D, x:Float, y:Float):Float

The squared distance between FlxPoint3Ds

staticinlinedistanceSquaredTo(this:FlxBasePoint3D, Point:FlxPoint3D):Float

staticinlinedistanceSquaredTo(this:FlxBasePoint3D, x:Float, y:Float):Float

Calculate the squared distance to another Point.

Parameters:

Point

A FlxPoint3D object to calculate the distance to.

Returns:

The distance between the two FlxPoint3Ds as a Float.

Available since

6.0.0

.

staticinlinedistanceTo(this:FlxBasePoint3D, Point:FlxPoint3D):Float

staticinlinedistanceTo(this:FlxBasePoint3D, x:Float, y:Float):Float

Calculate the distance to another Point.

Parameters:

Point

A FlxPoint3D object to calculate the distance to.

Returns:

The distance between the two FlxPoint3Ds as a Float.

staticinlinedot(this:FlxBasePoint3D, p:FlxPoint3D):Float

Short for dot product.

Parameters:

p

Point to multiply

Returns:

dot product of two FlxPoint3Ds

staticinlinedotProdWithNormalizing(this:FlxBasePoint3D, p:FlxPoint3D):Float

Dot product of FlxPoint3Ds with normalization of the second Point.

Parameters:

p

Point to multiply

Returns:

dot product of two FlxPoint3Ds

staticinlinedotProduct(this:FlxBasePoint3D, p:FlxPoint3D):Float

Dot product between two FlxPoint3Ds.

Parameters:

p

Point to multiply

Returns:

dot product of two FlxPoint3Ds

staticfindIntersection(this:FlxBasePoint3D, a:FlxPoint3D, b:FlxPoint3D, p:FlxPoint3D, ?intersection:FlxPoint3D):FlxPoint3D

Finding the Point of intersection of FlxPoint3Ds.

Parameters:

a

start Point of the Point

b

start Point of the p Point

p

the second Point

Returns:

the Point of intersection of FlxPoint3Ds

staticfindIntersectionInBounds(this:FlxBasePoint3D, a:FlxPoint3D, b:FlxPoint3D, p:FlxPoint3D, ?intersection:FlxPoint3D):FlxPoint3D

Finding the Point of intersection of FlxPoint3Ds if it is in the "bounds" of the FlxPoint3Ds.

Parameters:

a

start Point of the Point

b

start Point of the p Point

p

the second Point

Returns:

the Point of intersection of FlxPoint3Ds if it is in the "bounds" of the FlxPoint3Ds

staticinlinefloor(this:FlxBasePoint3D):FlxPoint3D

Rounds x and y using Math.floor()

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

Recycle or create new FlxPoint3D. 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.

z

The Z-coordinate of the Point in space.

staticinlineinCoords(this:FlxBasePoint3D, x:Float, y:Float, width:Float, height:Float):Bool

Returns true if this Point is within the given rectangular bounds

Parameters:

x

The X value of the region to test within

y

The Y value of the region to test within

width

The width of the region to test within

height

The height of the region to test within

Returns:

True if the Point is within the region, otherwise false

staticinlineinRect(this:FlxBasePoint3D, rect:FlxRect):Bool

Returns true if this Point is within the given rectangular block

Parameters:

rect

The FlxRect to test within

Returns:

True if Point3DX/Point3DY is within the FlxRect, otherwise false

staticinlineisNormalized(this:FlxBasePoint3D):Bool

Check the Point for unit length

staticinlineisParallel(this:FlxBasePoint3D, p:FlxPoint3D):Bool

Check for parallelism of two FlxPoint3Ds.

Parameters:

p

Point to check

Returns:

true - if they are parallel

staticinlineisPerpendicular(this:FlxBasePoint3D, p:FlxPoint3D):Bool

Check the perpendicularity of two FlxPoint3Ds.

Parameters:

p

Point to check

Returns:

true - if they are perpendicular

staticinlineisValid(this:FlxBasePoint3D):Bool

Checking if this is a valid Point.

Returns:

true - if the Point is valid

staticinlineisZero(this:FlxBasePoint3D):Bool

Check if this Point has zero length.

Returns:

true - if the Point is zero

staticleftNormal(this:FlxBasePoint3D, ?p:FlxPoint3D):FlxPoint3D

Left normal of the Point

staticinlinenegate(this:FlxBasePoint3D):FlxPoint3D

Change direction of the Point to opposite

staticinlinenegateNew(this:FlxBasePoint3D, ?result:FlxPoint3D):FlxPoint3D

staticnormalize(this:FlxBasePoint3D):FlxPoint3D

Normalization of the Point (reduction to unit length)

staticinlineperpProduct(this:FlxBasePoint3D, p:FlxPoint3D):Float

Dot product of left the normal Point and Point p.

staticinlinepivotDegrees(this:FlxBasePoint3D, pivot:FlxPoint3D, degrees:Float):FlxPoint3D

Rotates this Point clockwise in 2D space around another Point by the given degrees. Note: To rotate a Point around 0,0 you can use p.degrees += angle

Parameters:

pivot

The pivot you want to rotate this Point around

degrees

Rotate the Point by this many degrees clockwise.

Returns:

A FlxPoint3D containing the coordinates of the rotated Point.

Available since

5.0.0

.

staticpivotRadians(this:FlxBasePoint3D, pivot:FlxPoint3D, radians:Float):FlxPoint3D

Rotates this Point clockwise in 2D space around another Point by the given radians. Note: To rotate a Point around 0,0 you can use p.radians += angle

Parameters:

pivot

The pivot you want to rotate this Point around

radians

Rotate the Point by this many radians clockwise.

Returns:

A FlxPoint3D containing the coordinates of the rotated Point.

Available since

5.0.0

.

staticprojectTo(this:FlxBasePoint3D, p:FlxPoint3D, ?proj:FlxPoint3D):FlxPoint3D

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

Parameters:

p

Point to project

proj

optional argument - result Point

Returns:

projection of the Point

staticprojectToNormalized(this:FlxBasePoint3D, p:FlxPoint3D, ?proj:FlxPoint3D):FlxPoint3D

Projecting this Point on the normalized Point p.

Parameters:

p

this Point has to be normalized, ie have unit length

proj

optional argument - result Point

Returns:

projection of the Point

staticinlineradiansBetween(this:FlxBasePoint3D, p:FlxPoint3D):Float

Get the angle between FlxPoint3Ds (in radians).

Parameters:

p

second Point, which we find the angle

Returns:

the angle in radians

staticinlineradiansFrom(this:FlxBasePoint3D, Point:FlxPoint3D):Float

Calculates the angle from another Point to this. If this is straight right of the Point, 0 is returned.

Parameters:

Point

The other Point.

Returns:

The angle, in radians, between -PI and PI

Available since

5.0.0

.

staticinlineradiansTo(this:FlxBasePoint3D, Point:FlxPoint3D):Float

Calculates the angle from this to another Point. If the Point is straight right of this, 0 is returned.

Parameters:

Point

The other Point.

Returns:

The angle, in radians, between -PI and PI

Available since

5.0.0

.

staticinlineratio(this:FlxBasePoint3D, a:FlxPoint3D, b:FlxPoint3D, p:FlxPoint3D):Float

Find the ratio between the perpProducts of this Point and p Point. This helps to find the intersection Point.

Parameters:

a

start Point of the Point

b

start Point of the p Point

p

the second Point

Returns:

the ratio between the perpProducts of this Point and p Point

staticrightNormal(this:FlxBasePoint3D, ?p:FlxPoint3D):FlxPoint3D

Right normal of the Point

staticinlinerotateByDegrees(this:FlxBasePoint3D, degs:Float):FlxPoint3D

Rotate the Point for a given angle.

Parameters:

degs

angle to rotate

Returns:

rotated Point

staticinlinerotateByRadians(this:FlxBasePoint3D, rads:Float):FlxPoint3D

Rotate the Point for a given angle.

Parameters:

rads

angle to rotate

Returns:

rotated Point

staticinlinerotateWithTrig(this:FlxBasePoint3D, sin:Float, cos:Float):FlxPoint3D

Rotate the Point 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 Point

staticinlineround(this:FlxBasePoint3D):FlxPoint3D

Rounds x and y using Math.round()

staticinlinescale(this:FlxBasePoint3D, x:Float, y:Float, z:Float):FlxPoint3D

staticinlinescale(this:FlxBasePoint3D, point:Vector3D):FlxPoint3D

staticinlinescale(this:FlxBasePoint3D, Point:FlxPoint3D):FlxPoint3D

staticinlinescale(this:FlxBasePoint3D, amount:Float):FlxPoint3D

Scale this Point.

Parameters:

x

The x scale coefficient

y

The y scale coefficient

Returns:

this Point

staticinlinescaleNew(this:FlxBasePoint3D, k:Float):FlxPoint3D

Returns scaled copy of this Point.

Parameters:

k
  • scale coefficient

Returns:

scaled Point

staticinlinescalePoint3D(this:FlxBasePoint3D, point:FlxPoint3D):FlxPoint3D

Deprecated: "scalePoint3D is deprecated, use scale(Point), instead"

Scale this Point by another Point.

Parameters:

Point

The x and y scale coefficient

Returns:

scaled Point

staticinlineset(this:FlxBasePoint3D, x:Float, y:Float, z:Float):FlxPoint3D

staticinlineset(this:FlxBasePoint3D):FlxPoint3D

staticinlineset(this:FlxBasePoint3D, x:Float):FlxPoint3D

staticinlineset(this:FlxBasePoint3D, x:Float, y:Float):FlxPoint3D

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.

staticinlinesetPolarDegrees(this:FlxBasePoint3D, length:Float, degrees:Float):FlxPoint3D

Sets the polar coordinates of the Point

Parameters:

length

The length to set the Point

degrees

The angle to set the Point, in degrees

Returns:

The rotated Point

Available since

4.10.0

.

staticsetPolarRadians(this:FlxBasePoint3D, length:Float, radians:Float):FlxPoint3D

Sets the polar coordinates of the Point

Parameters:

length

The length to set the Point

radians

The angle to set the Point, in radians

Returns:

The rotated Point

Available since

4.10.0

.

staticinlinesetXYZ(this:FlxBasePoint3D, n:Float):FlxPoint3D

Set the coordinates of this Point object.

Parameters:

n

The X and Y coordinate of the Point in space.

staticsign(this:FlxBasePoint3D, a:FlxPoint3D, b:FlxPoint3D):Int

The sign of half-plane of Point with respect to the Point through the a and b FlxPoint3Ds.

Parameters:

a

start Point of the wall-Point

b

end Point of the wall-Point

@:value({ z : 0, y : 0, x : 0 })staticinlinesubtract(this:FlxBasePoint3D, x:Float = 0, y:Float = 0, z:Float = 0):FlxPoint3D

staticinlinesubtract(this:FlxBasePoint3D, point:Vector3D):FlxPoint3D

staticinlinesubtract(this:FlxBasePoint3D, Point:FlxPoint3D):FlxPoint3D

Subtracts from the coordinates of this Point.

Parameters:

x

Amount to subtract from x

y

Amount to subtract from y

Returns:

This Point.

staticinlinesubtractFromFlash(this:FlxBasePoint3D, p:Vector3D):Vector3D

Helper function, just decreases the values of the specified Flash Point by the values of this Point.

Parameters:

p

Any Point.

Returns:

A reference to the altered Point parameter.

staticinlinesubtractNew(this:FlxBasePoint3D, p:FlxPoint3D):FlxPoint3D

Returns new Point which is result of subtraction of p Point from this Point.

Parameters:

p

Point to subtract

Returns:

subtraction result

staticinlinesubtractPoint3D(this:FlxBasePoint3D, Point:FlxPoint3D):FlxPoint3D

Deprecated: "subtractPoint3D is deprecated, use subtract(Point), instead"

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

Parameters:

Point

The Point to subtract from this Point

Returns:

This Point.

staticinlinetransform(this:FlxBasePoint3D, matrix:Matrix):FlxPoint3D

Applies transformation matrix to this Point

Parameters:

matrix

transformation matrix

Returns:

transformed Point

staticinlinetruncate(this:FlxBasePoint3D, max:Float):FlxPoint3D

Limit the length of this Point.

Parameters:

max

maximum length of this Point

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

Recycle or create a new FlxPoint3D 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.

z

The Z-coordinate of the Point in space.

Available since

4.6.0

.

staticinlinezero(this:FlxBasePoint3D):FlxPoint3D

Point reset