BGE/Math
Alias: BGE.Math
Static Methods
createCornerPoints(
topLeft: Vector,
topRight: Vector,
bottomLeft: Vector,
bottomRight: Vector,
): CornerPoints
Parameters
Returns
isFloatArray44(x: dynamic): boolean
Parameters
x(dynamic)
Returns
boolean
getFloat44Identity(): dynamic
Returns
dynamic
fillFloat44(dest: dynamic, src: dynamic): void
Parameters
dest(dynamic)src(dynamic)
Returns
void
lookAt(from: Vector, lookTo: Vector): dynamic
Parameters
Returns
dynamic
orthographicMatrix(
top: float,
bottom: float,
left: float,
right: float,
far: float,
near: float,
): dynamic
Parameters
top(float)bottom(float)left(float)right(float)far(float)near(float)
Returns
dynamic
getScaleMatrix(scale: Vector): dynamic
Parameters
scale(Vector)
Returns
dynamic
getRotationMatrix(rotation: Vector): dynamic
Parameters
rotation(Vector)
Returns
dynamic
getTranslationMatrix(position: Vector): dynamic
Parameters
position(Vector)
Returns
dynamic
getTransformationMatrix(
position: Vector,
rotation: Vector,
scale: Vector,
): dynamic
Parameters
Returns
dynamic
createTransform(): Transform
Returns
Min(a: float, b: float): float
Parameters
a(float)b(float)
Returns
float
Max(a: float, b: float): float
Parameters
a(float)b(float)
Returns
float
Clamp(number: float, minVal: float, maxVal: float): float
Parameters
number(float)minVal(float)maxVal(float)
Returns
float
Atan2(y: float, x: float): float
Parameters
y(float)x(float)
Returns
float
IsIntegerEven(number: integer): boolean
Parameters
number(integer)
Returns
boolean
IsIntegerOdd(number: integer): boolean
Parameters
number(integer)
Returns
boolean
Power(number: float, pow: integer): float
Parameters
number(float)pow(integer)
Returns
float
Round(number: float, decimals?: integer): float
Parameters
number(float)decimals(integer, optional, default: 0)
Returns
float
DegreesToRadians(degrees: float): float
Parameters
degrees(float)
Returns
float
RadiansToDegrees(radians: float): float
Parameters
radians(float)
Returns
float
RandomInRange(lowestInt: integer, highestInt: integer): integer
Parameters
lowestInt(integer)highestInt(integer)
Returns
integer
constrainAngle(angleRad: float): float
Parameters
angleRad(float)
Returns
float
RotateVectorAroundPoint2d(
vector1: Vector,
point: Vector,
radians: float,
): Vector
Parameters
Returns
RotateVectorAroundPoint3d(
vector1: Vector,
point: Vector,
axis: Vector,
radians: float,
): Vector
Rotates vector1 around point in 3D by radians about the provided axis. axis does not need to be normalized.
Parameters
Returns
TotalDistance(vector1: Vector, vector2: Vector): float
Parameters
Returns
float
GetAngle(point1: Vector, point2: Vector): float
Parameters
Returns
float
GetAngleBetweenVectors(
center: vector,
point1: Vector,
point2: Vector,
): float
Parameters
Returns
float
GetAngleAtPoint3d(
center: Vector,
point1: Vector,
point2: Vector,
): float
Returns the angle at center between legs center->point1 and center->point2 in radians. Uses atan2(|u x v|, u · v) for stable 3D angle calculation in [0, PI].
Parameters
Returns
float
GetSliceAnglesAtPoint3d(
centerPoint: Vector,
lineStart: Vector,
lineEnd: Vector,
sliceLength: float,
includeRemainder?: boolean,
): dynamic
Returns one theta (radians) per slice along the segment from lineStart to lineEnd, where each theta is measured at centerPoint between consecutive slice endpoints.
Parameters
centerPoint(Vector)lineStart(Vector)lineEnd(Vector)sliceLength(float)includeRemainder(boolean, optional, default: false)
Returns
dynamic
average(num1: float, num2: float): float
Parameters
num1(float)num2(float)
Returns
float
arraySum(nums: dynamic): float
Parameters
nums(dynamic)
Returns
float
arrayAverage(nums: dynamic): float
Parameters
nums(dynamic)
Returns
float
arrayMin(nums: dynamic): float
Parameters
nums(dynamic)
Returns
float
arrayMax(nums: dynamic): float
Parameters
nums(dynamic)
Returns
float
intersectRayWithPlane(plane: Plane, ray: Ray): BGE.Math.Vector
Parameters
Returns
BGE.Math.Vector
signedDistanceFromPointToPlane(
plane: Plane,
targetPoint: BGE.Math.Vector,
): float
Returns signed distance from a point to a plane. Positive/negative sign indicates which side of the plane normal the point is on.
Parameters
plane(Plane)targetPoint(BGE.Math.Vector)
Returns
float
distanceFromPointToPlane(
plane: Plane,
targetPoint: BGE.Math.Vector,
): float
Returns the absolute shortest distance from a point to a plane.
Parameters
plane(Plane)targetPoint(BGE.Math.Vector)
Returns
float
angleToPlaneSurfaceDeg(
plane: BGE.Math.Plane,
v: BGE.Math.Vector,
): float
0..90 deg 0 = parallel to plane, 90 = perpendicular to plane
Parameters
plane(BGE.Math.Plane)v(BGE.Math.Vector)
Returns
float
angleToPlaneNormalDeg(
plane: BGE.Math.Plane,
v: BGE.Math.Vector,
): float
0..180 deg 0 = +normal, 180 = -normal, 90 = parallel to plane
Parameters
plane(BGE.Math.Plane)v(BGE.Math.Vector)
Returns
float
closestPointOnPlane(
plane: BGE.Math.Plane,
point: BGE.Math.Vector,
): BGE.Math.Vector
Parameters
plane(BGE.Math.Plane)point(BGE.Math.Vector)
Returns
BGE.Math.Vector
projectRayOntoPlane(
plane: BGE.Math.Plane,
ray: BGE.Math.Ray,
): BGE.Math.Ray
Parameters
plane(BGE.Math.Plane)ray(BGE.Math.Ray)
Returns
BGE.Math.Ray
worldPointToTexturePixel(
worldPoint: BGE.Math.Vector,
textureCenterWorldPoint: BGE.Math.Vector,
textureWidth: float,
textureHeight: float,
): BGE.Math.Vector
Maps a world-space point on a plane to pixel coordinates within a textureWidth x textureHeight texture, anchored so that textureCenterWorldPoint corresponds to the texture's own center pixel (rather than world (0,0) mapping to the texture's (0,0) pixel, which would pin the texture to a fixed absolute-world-space footprint regardless of where the plane/camera actually are).
Parameters
worldPoint(BGE.Math.Vector) — a point on the plane, in world spacetextureCenterWorldPoint(BGE.Math.Vector) — the world-space point that should map to the texture's centertextureWidth(float)textureHeight(float)
Returns
BGE.Math.Vector— pixel coordinates within the texture (z unused)
VectorZero(): BGE.Math.Vector
Returns
BGE.Math.Vector
VectorFromFloatArray(array: dynamic): BGE.Math.Vector
Parameters
array(dynamic)
Returns
BGE.Math.Vector
createScaleVector(
scale_x: float,
scale_y?: dynamic,
scale_z?: dynamic,
): BGE.Math.Vector
Parameters
scale_x(float) — horizontal scalescale_y(dynamic, optional, default: "invalid") — vertical scale, or if invalid, use the horizontal scale as vertical scalescale_z(dynamic, optional, default: "invalid")
Returns
BGE.Math.Vector
distanceFromPlane(
planePoint: BGE.Math.Vector,
planeNormal: BGE.Math.Vector,
targetPoint: BGE.Math.Vector,
): float
Parameters
planePoint(BGE.Math.Vector)planeNormal(BGE.Math.Vector)targetPoint(BGE.Math.Vector)
Returns
float
midPointBetweenPoints(
a: BGE.Math.Vector,
b: BGE.Math.Vector,
): BGE.Math.Vector
Parameters
a(BGE.Math.Vector)b(BGE.Math.Vector)
Returns
BGE.Math.Vector
averagePoint(points: Array.<BGE.Math.Vector>): BGE.Math.Vector
The centroid of a set of points - their component-wise average. Note this is not the same as the center of their bounding box (see getBounds).
Parameters
points(Array.<BGE.Math.Vector>)
Returns
BGE.Math.Vector— the average of every point, or the origin if given no points
getBounds(points: dynamic): dynamic
Parameters
points(dynamic)
Returns
dynamic
boundsOverlapRect(
points: Array.<BGE.Math.Vector>,
width: float,
height: float,
): boolean
Checks if the (x, y) bounding box of points overlaps the axis-aligned rectangle [0, width] x [0, height] at all.
Parameters
points(Array.<BGE.Math.Vector>)width(float)height(float)
Returns
boolean
getBoundingCubePoints(points: dynamic): dynamic
Parameters
points(dynamic)
Returns
dynamic
vectorArraysEqual(a?: dynamic, b?: dynamic): boolean
Parameters
a(dynamic, optional, default: "[]")b(dynamic, optional, default: "[]")
Returns
boolean
vectorArrayCopy(a?: dynamic): dynamic
Parameters
a(dynamic, optional, default: "[]")
Returns
dynamic
intersectPointPoint(
p1: Vector,
p2: Vector,
p3: Vector,
p4: Vector,
mustBeInSegment?: boolean,
): BGE.Math.Vector
From https://paulbourke.net/geometry/pointlineplane/javascript.txt
Parameters
Returns
BGE.Math.Vector
intersectPointAngle(
p1: BGE.Math.Vector,
angle1FromXAxis: float,
p2: BGE.Math.Vector,
angle2FromXAxis: float,
): BGE.Math.Vector
Parameters
p1(BGE.Math.Vector)angle1FromXAxis(float)p2(BGE.Math.Vector)angle2FromXAxis(float)
Returns
BGE.Math.Vector
Enums
BGE.Math.WindingDirection
Properties
clockwise(default: 0)counterclockwise(default: 1)
Other
CornerPoints
Properties
topLeft(dynamic)topRight(dynamic)bottomLeft(dynamic)bottomRight(dynamic)
Transform
Properties
position(BGE.Math.Vector)rotation(BGE.Math.vector)scale(BGE.Math.Vector)
Triangle
Properties
lengths(dynamic)angles(dynamic)anglesToNext(dynamic)anglesToPrevious(dynamic)points(dynamic)longestIndex(integer)height(float)winding(WindingDirection)angleRotatedFromOriginal(float)
Circle
Parameters
x(float, optional, default: 0)y(float, optional, default: 0)radius(float, optional, default: 0)
Properties
x(float)y(float)radius(float)
Returns
BGE.Math.Circle
PI
Default: 3.14159265358
HALF_PI
Default: 1.57079632679
Plane
Properties
Ray
Properties
Rectangle
Parameters
x(float, optional, default: 0)y(float, optional, default: 0)width(float, optional, default: 0)height(float, optional, default: 0)
Properties
x(float)y(float)width(float)height(float)
Returns
BGE.Math.Rectangle
Vector
Properties
x(float)y(float)z(float)