Bitfighter  021
The Bitfighter Lua Documentation - Robots, Levelgens, and Plugins
point Class Reference

A simple object representing a coordinate pair.

Member Functions

point(x, y)
 Constructor.
 

Static Member Functions

angleTo(p1, p2)
 Compute the angle between vectors represented in the two passed points. [details]
 
cross(p1, p2)
 Compute the cross product of two points. [details]
 
distanceTo(p1, p2)
 Compute the distance between two points. [details]
 
distSquared(p1, p2)
 Compute the distance squared between two points. [details]
 
dot(p1, p2)
 Compute the dot product of two points. [details]
 
length(p)
 Compute the length of the vector contained in the passed point. [details]
 
lengthSquared(p)
 Compute the square of the length of the vector contained in the passed point. [details]
 
normalize(p)
 Normalizes the length of a vector represented by a point to have a length of 1. [details]
 

Constants

one
 Constant representing the point (1, 1). [details]
 
zero
 Constant representing the point (0, 0). [details]
 

Detailed Description

A simple object representing a coordinate pair.

Points are used to represent locations and positions in the game. Note that for historical reasons, "point" is lower case. Points can be added and subtracted from one another, as well as multiplied together. Most point methods are static.

function getAngleDiff(bullet, botPos) -- BfObject, point
local o = point.zero -- Origin; using builtin constant rather than creating new object
local bulletPos = bullet:getPos()
print(bulletPos.x, bulletPos.y) -- Access coordinates with dot notation
local bulletVel = bullet:getVel() -- Access member functions with colon notation
-- angleTo is a static method, so call with "point.angleTo"
return math.abs(angleDifference(point.angleTo(o, bulletVel), point.angleTo(bulletPos, botPos)))
end
Definition: BfObject__cpp.h:7
A simple object representing a coordinate pair.
Definition: luavec__lua.h:5
static point dot(point p1, point p2)
Compute the dot product of two points.
Definition: luavec__lua.h:9
static num angleTo(point p1, point p2)
Compute the angle between vectors represented in the two passed points.
Definition: luavec__lua.h:19
point zero
Constant representing the point (0, 0).
Definition: luavec__lua.h:30

Constructor Documentation

◆ point.new(x, y)

Arg types: x: num, y: num  |  returns point

Constructor.

Example:

pt = point.new(100, 300)
testitem = TestItem.new(pt)
levelgen:addItem(testitem)
Large bouncy ball type item.
Definition: moveObject__cpp.h:41

Member Function Documentation

◆ point.angleTo(p1, p2)

Arg types: p1: point, p2: point  |  returns num
static

Compute the angle between vectors represented in the two passed points.

Computes the angle from the vector passed in p1 and the vector passed in p2 using the atan2 function.

◆ point.cross(p1, p2)

Arg types: p1: point, p2: point  |  returns point
static

Compute the cross product of two points.

Computes and returns a point representing the cross product of two passed points.

◆ point.distanceTo(p1, p2)

Arg types: p1: point, p2: point  |  returns num
static

Compute the distance between two points.

Computes the distance between the two passed points.

◆ point.distSquared(p1, p2)

Arg types: p1: point, p2: point  |  returns num
static

Compute the distance squared between two points.

Computes the distance squared between the two passed points. This is useful if you are comparing distances to one another, and don't need the actual distance. Not computing the sqrt will make your scripts run more efficiently.

◆ point.dot(p1, p2)

Arg types: p1: point, p2: point  |  returns point
static

Compute the dot product of two points.

Computes and returns a point representing the dot product of two passed points.

◆ point.length(p)

Arg types: p: point  |  returns num
static

Compute the length of the vector contained in the passed point.

Computes the length of the vector contained in the passed point by using the Pythagorean equation; that is, it returns sqrt(p.x^2 + p.y^2).

◆ point.lengthSquared(p)

Arg types: p: point  |  returns num
static

Compute the square of the length of the vector contained in the passed point.

Computes the square of the length of the vector contained in the passed point by using the Pythagorean equation; that is, it returns (p.x^2 + p.y^2). This is useful if you are comparing lengths to one another, and don't need the actual length. Not computing the sqrt will make your scripts run more efficiently.

◆ point.normalize(p)

Arg types: p: point  |  returns point
static

Normalizes the length of a vector represented by a point to have a length of 1.

If the input vector is (3, 0), the output will be (1, 0).

Constants

◆ point.one

returns point

Constant representing the point (1, 1).

Using this constant is marginally more efficient than defining it yourself.

◆ point.zero

returns point

Constant representing the point (0, 0).

Using this constant is marginally more efficient than defining it yourself.