A vector is a geometric object that has a length and direction. Vectors can be added to other vectors according to vector algebra. The most common use in warcraft III is as a point in space. For example a unit’s position can be represented as a vector as well as a knockback force acting on it.
📖 Read the detailed guide for hand-written examples and background.
Re-exports: Real, Angle
public tuple vec2(real x, real y)
2d Vector tuple
public tuple vec3(real x, real y, real z)
3d Vector tuple
public function vec2.op_plus(vec2 v) returns vec2
public function vec2.op_plus(vec3 v) returns vec2
public function vec2.op_minus(vec2 v) returns vec2
public function vec2.op_mult(real factor) returns vec2
Operator
public function real.op_mult(vec2 vec) returns vec2
Operator
public function vec2.op_mult(vec2 v) returns vec2
dot product Operator
public function vec2.op_divReal(real factor) returns vec2
Operator
public function vec2.add(real x, real y) returns vec2
Add two reals to the coordiantes of this vector
public function vec2.dot(vec2 v) returns real
Get the dot-product
public function vec2.norm() returns vec2
Normalize this vector
public function vec2.rotate(angle angl) returns vec2
Rotate this vector
public function vec2.toVec3() returns vec3
Convert this vector to a 3d vector with z = 0.
public function vec2.getTerrainZ() returns real
public function vec3.getTerrainZ() returns real
public function vec2.withTerrainZ() returns vec3
public function vec2.withTerrainZ(real zoffset) returns vec3
public function vec2.setLength(real length) returns vec2
Set the length of this vector
public function vec2.length() returns real
Get the length of this vector
public function vec2.lengthSq() returns real
Get the squared length of this vector
public function vec2.inRange(vec2 v2, real radius) returns boolean
Is this vector inside the given circle
public function vec2.toString() returns string
Get a String-representation of this Vector (for debugging)
public function vec2.angleTo(vec2 v) returns angle
Get this vetor’s angle to another one
public function vec2.polarOffset(angle ang, real dist) returns vec2
Get a polar offset from this vector
public function vec2.normalizedPointerTo(vec2 target) returns vec2
returns a vector of length 1 which points into the direction of target, when this vector and target are equal, then the pointer will point to the right
public function vec2.moveTowards(vec2 target, real dist) returns vec2
move a vector towards a given other vector, if the current vector is equal to the target vector, then the vector will move to the right. (this emulated the behavior of using polarOffset for this task)
public function vec2.withZ(real z) returns vec3
Get a 3d Vector with the original xy and the given z coordinate
public function vec2.distanceTo(vec2 v) returns real
Get distance to another vector
public function vec2.distanceToSq(vec2 v) returns real
Get squared distance to another vector
public function vec2.distanceToSegmentSq(vec2 v1, vec2 v2) returns real
Get squared distance to a line segment
public function vec2.withRadiusRect(real nominalRadius) returns rect
Create a rect centered at this with side length 2 * nominalRadius.
public function vec2.isInTriangle(vec2 p1, vec2 p2, vec2 p3) returns bool
Checks whether the point is in a triangle defined by 3 points.
public function vec2.isInPolygon(vararg vec2 args) returns bool
Checks whether the point is in a polygon defined by a sequence of connected points.
public function vec3.op_plus(vec3 v) returns vec3
public function vec3.op_plus(vec2 v) returns vec3
public function vec3.op_minus(vec3 v) returns vec3
public function vec3.op_minus(vec2 v) returns vec3
public function vec3.op_mult(real factor) returns vec3
Operator
public function real.op_mult(vec3 v) returns vec3
dot Operator
public function vec3.add(real x, real y, real z) returns vec3
add 3 realvalues to the coordinates of this Vector
public function vec3.dot(vec3 v) returns real
Get the dot-product
public function vec3.norm() returns vec3
Normalize this Vector
public function vec3.rotate(vec3 axis, real radians) returns vec3
Rotate this vector around an axis
public function vec3.setLengthSq(real lengthSq) returns vec3
Sets the length of the given Vector
public function vec3.setLength(real length) returns vec3
Sets the length of the given Vector
public function vec3.length() returns real
Get the length of this Vector
public function vec3.lengthSquared() returns real
Get the squared length of this Vector
public function vec3.cross(vec3 v) returns vec3
Get the cross-product
public function vec3.project(vec3 direction) returns vec3
Project this vector onto the given directional vector
public function vec3.toVec2() returns vec2
Convert a vec3 to a vec2 (z-coordinate gets removed)
public function vec3.inRange(vec3 v2, real radius) returns boolean
Is this vector inside the given circle
public function vec3.distanceTo(vec3 v) returns real
Get the distance to another Vector
public function vec3.distanceTo2d(vec3 v) returns real
Get the distance to another Vector
public function vec3.distanceTo2d(vec2 v) returns real
Get the distance to another Vector
public function vec3.distanceTo2dSq(vec2 v) returns real
Get the squared distance to another Vector
public function vec3.distanceToSq(vec3 v) returns real
Get the squared distance to another Vector
public function vec3.toString() returns string
Get a String-represantation of the vector (for debugging)
public function vec3.rotate(vec3 axis, angle ang) returns vec3
Rotate this vector around an axis
public function vec3.offset2d(angle ang, real dist) returns vec3
Offset this vector in 2d space
public function vec3.angleTo2d(vec2 v) returns angle
Get the angle to a 2d vector
public function vec3.angleTo2d(vec3 v) returns angle
public function vec3.polarProject(real distance, angle angleGround, angle angleAir) returns vec3
Get a polarprojection of this Vector
public function vec3.normalizedPointerTo(vec3 target) returns vec3
returns a vector of length 1 which points into the direction of target, when this vector and target are equal, then the pointer will point to the right
public function vec3.moveTowards(vec3 target, real dist) returns vec3
move a vector towards a given other vector, if the current vector is equal to the target vector, then the vector will move to the right. (this emulated the behavior of using polarOffset for this task)
public function angle.toVec(real len) returns vec2
returns a vector of the given length pointing into the direction of this angle
public function angle.direction() returns vec2
returns a vector of length 1 pointing into the direction of this angle
public function angle.direction(real dist) returns vec2
returns a vector of length ‘dist’ pointing into the direction of this angle
public function vec2.getAngle() returns angle
returns the angle of this vector
public function vec2.assertEquals(vec2 expected)
public function vec3.assertEquals(vec3 expected)
public function vec3.isInTriangle2d(vec3 p1, vec3 p2, vec3 p3) returns bool
Checks whether the point is in a 2D triangle defined by 3 points. Works as for vec2.isInTriangle, Z-coords are discarded.
public function vec3.isInPolygon2d(vararg vec3 args) returns bool
Checks whether the point is in a 2d polygon defined by a sequence of connected points. Works as for vec2.isInPolygon, Z-coords are discarded.
public constant ZERO2 = vec2(0, 0)
public constant ZERO3 = vec3(0, 0, 0)
public constant RIGHT = vec2(1, 0)
public constant UP = vec2(0, 1)
public constant LEFT = vec2(-1, 0)
public constant DOWN = vec2(0, -1)