# Vector

# Description

The Vector class provides vector operations in three-dimensional space, including calculations between vectors, distance measurement, angle calculation, projection, rotation, etc., as well as position determination in the game scene, such as determining whether a position is in the grass, river, etc.

# How to Use

// Create a vector
Vector position(100.0f, 200.0f, 50.0f);

// Calculate the distance between two points
Vector position2(150.0f, 250.0f, 75.0f);
float distance = position.Distance(position2);

// Get normalized vector
Vector normalized = position.Normalized();

// Extend in a certain direction by a specific distance
Vector extended = position.Extend(position2, 300.0f);

// Determine if the position is in grass
bool isInGrass = position.IsGrass();

# X

float X

The X coordinate value of the vector.

Vector position(100.0f, 200.0f, 50.0f);
float xCoord = position.X;

# Y

float Y

The Y coordinate value of the vector.

Vector position(100.0f, 200.0f, 50.0f);
float yCoord = position.Y;

# Z

float Z

The Z coordinate value of the vector.

Vector position(100.0f, 200.0f, 50.0f);
float zCoord = position.Z;

# Zero

static Vector Zero

Static member variable representing the zero vector (0, 0, 0).

Vector zeroVec = Vector::Zero;

# Vector()

Vector()

Default constructor, creates a vector with all components set to 0.

Vector vec;
// Creates a vector (0, 0, 0)

# Vector(float x, float y)

Vector(float x, float y)

Creates a two-dimensional vector, with Z coordinate defaulting to 0.

Parameter Name Parameter Type Description
x float X coordinate value
y float Y coordinate value
Vector position(100.0f, 200.0f);
// Creates a vector (100, 200, 0)

# Vector(float x, float y, float z)

Vector(float x, float y, float z)

Creates a three-dimensional vector.

Parameter Name Parameter Type Description
x float X coordinate value
y float Y coordinate value
z float Z coordinate value
Vector position(100.0f, 200.0f, 50.0f);
// Creates a vector (100, 200, 50)

# Length

float Length() const

Gets the length (magnitude) of the vector.

Vector vec(3.0f, 4.0f);
float length = vec.Length(); // Returns 5.0

# LengthSquared

float LengthSquared() const

Gets the square of the vector's length, avoiding the square root operation to improve performance.

Vector vec(3.0f, 4.0f);
float lengthSquared = vec.LengthSquared(); // Returns 25.0

# Distance

float Distance(const Vector& vOther, bool squared = false) const

Calculates the distance between the current vector and another vector.

Parameter Name Parameter Type Description
vOther const Vector& Another vector
squared bool Whether to return the square of the distance, default is false
Vector pos1(100.0f, 200.0f);
Vector pos2(150.0f, 250.0f);
float dist = pos1.Distance(pos2); // Get the distance between two points
float distSquared = pos1.Distance(pos2, true); // Get the square of the distance between two points

# Distance

float Distance(AIBaseClient* unit, bool squared = false) const

Calculates the distance between the current vector and a game unit.

Parameter Name Parameter Type Description
unit AIBaseClient* Game unit
squared bool Whether to return the square of the distance, default is false
Vector myPosition(100.0f, 200.0f);
AIBaseClient* enemy = GetNearestEnemy();
float distToEnemy = myPosition.Distance(enemy);

# Distance

float Distance(const Vector& segmentStart, const Vector& segmentEnd, bool onlyIfOnSegment = false, bool squared = false) const

Calculates the distance from the current vector to a line segment.

Parameter Name Parameter Type Description
segmentStart const Vector& Start point of the line segment
segmentEnd const Vector& End point of the line segment
onlyIfOnSegment bool Whether to calculate the distance only when the projection point is on the segment, default is false
squared bool Whether to return the square of the distance, default is false
Vector myPosition(100.0f, 200.0f);
Vector lineStart(0.0f, 0.0f);
Vector lineEnd(200.0f, 200.0f);
float distToLine = myPosition.Distance(lineStart, lineEnd);

# DistanceSquared

float DistanceSquared(const Vector& vOther) const

Calculates the square of the distance between the current vector and another vector.

Parameter Name Parameter Type Description
vOther const Vector& Another vector
Vector pos1(100.0f, 200.0f);
Vector pos2(150.0f, 250.0f);
float distSquared = pos1.DistanceSquared(pos2);

# Polar

float Polar() const

Gets the polar angle (in radians) of the vector.

Vector vec(1.0f, 1.0f);
float angle = vec.Polar(); // Returns π/4 (approximately 0.785)

# AngleBetween

float AngleBetween(const Vector& other) const

Calculates the angle (in radians) between the current vector and another vector.

Parameter Name Parameter Type Description
other const Vector& Another vector
Vector vec1(1.0f, 0.0f);
Vector vec2(0.0f, 1.0f);
float angle = vec1.AngleBetween(vec2); // Returns π/2 (approximately 1.57)

# CrossProduct

float CrossProduct(const Vector& other) const

Calculates the cross product of the current vector and another vector.

Parameter Name Parameter Type Description
other const Vector& Another vector
Vector vec1(1.0f, 0.0f);
Vector vec2(0.0f, 1.0f);
float cross = vec1.CrossProduct(vec2);

# DotProduct

float DotProduct(const Vector& other) const

Calculates the dot product of the current vector and another vector.

Parameter Name Parameter Type Description
other const Vector& Another vector
Vector vec1(1.0f, 0.0f);
Vector vec2(0.0f, 1.0f);
float dot = vec1.DotProduct(vec2); // Returns 0.0

# Extend

Vector Extend(const Vector& to, float distance) const

Extends from the current vector towards the target vector by a specified distance.

Parameter Name Parameter Type Description
to const Vector& Target vector
distance float Extension distance
Vector myPosition(100.0f, 100.0f);
Vector targetPosition(200.0f, 200.0f);
Vector extended = myPosition.Extend(targetPosition, 150.0f);

# Normalized

Vector Normalized() const

Returns the unit vector (length 1) of the current vector.

Vector vec(3.0f, 4.0f);
Vector normalized = vec.Normalized(); // Returns unit vector (0.6, 0.8)

# Perpendicular

Vector Perpendicular() const

Returns a perpendicular vector to the current vector.

Vector vec(1.0f, 0.0f);
Vector perp = vec.Perpendicular(); // Returns (0.0, 1.0)

# Perpendicular2

Vector Perpendicular2() const

Returns another perpendicular vector to the current vector.

Vector vec(1.0f, 0.0f);
Vector perp = vec.Perpendicular2(); // Returns (0.0, -1.0)

# Rotated

Vector Rotated(float angle) const

Returns the vector after rotating by a specified angle.

Parameter Name Parameter Type Description
angle float Rotation angle (in radians)
Vector vec(1.0f, 0.0f);
Vector rotated = vec.Rotated(1.57f); // Rotate by π/2 radians, approximately (0.0, 1.0)

# RotateAroundPoint

Vector RotateAroundPoint(const Vector& around, float angle) const

Rotates the vector around a specified point.

Parameter Name Parameter Type Description
around const Vector& Center point of rotation
angle float Rotation angle (in radians)
Vector vec(200.0f, 100.0f);
Vector center(100.0f, 100.0f);
Vector rotated = vec.RotateAroundPoint(center, 1.57f); // Rotate around the center point by π/2 radians

# Shorten

Vector Shorten(const Vector& to, float distance) const

Shortens from the current vector towards the target vector by a specified distance.

Parameter Name Parameter Type Description
to const Vector& Target vector
distance float Shortening distance
Vector myPosition(100.0f, 100.0f);
Vector targetPosition(200.0f, 200.0f);
Vector shortened = myPosition.Shorten(targetPosition, 50.0f);

# Center

Vector Center(const Vector& to) const

Returns the midpoint between the current vector and the target vector.

Parameter Name Parameter Type Description
to const Vector& Target vector
Vector pos1(100.0f, 100.0f);
Vector pos2(200.0f, 200.0f);
Vector center = pos1.Center(pos2); // Returns (150.0, 150.0)

# SetZ

Vector SetZ(float value = -1.f) const

Sets the Z coordinate of the vector, by default using GetHeightForPosition to get the terrain height.

Parameter Name Parameter Type Description
value float Z coordinate value, default is -1.f indicating use of GetHeightForPosition
Vector position(100.0f, 200.0f);
Vector withHeight = position.SetZ(); // Use terrain height
Vector withCustomHeight = position.SetZ(50.0f); // Use custom height

# ProjectOn

ProjectionInfo ProjectOn(const Vector& segmentStart, const Vector& segmentEnd) const

Projects the current vector onto a line segment formed by two points.

Parameter Name Parameter Type Description
segmentStart const Vector& Start point of the line segment
segmentEnd const Vector& End point of the line segment
Vector position(150.0f, 150.0f);
Vector lineStart(100.0f, 100.0f);
Vector lineEnd(200.0f, 200.0f);
ProjectionInfo proj = position.ProjectOn(lineStart, lineEnd);

# Intersection

IntersectionResult Intersection(const Vector& lineSegment1End, const Vector& lineSegment2Start, const Vector& lineSegment2End) const

Calculates the intersection point of two line segments.

Parameter Name Parameter Type Description
lineSegment1End const Vector& End point of the first line segment (current vector is the start point)
lineSegment2Start const Vector& Start point of the second line segment
lineSegment2End const Vector& End point of the second line segment
Vector line1Start(100.0f, 100.0f);
Vector line1End(200.0f, 200.0f);
Vector line2Start(100.0f, 200.0f);
Vector line2End(200.0f, 100.0f);
IntersectionResult result = line1Start.Intersection(line1End, line2Start, line2End);

# IsValid

bool IsValid() const

Checks if the vector is valid.

Vector position(100.0f, 200.0f);
bool valid = position.IsValid();

# CountAlliesInRange

int CountAlliesInRange(float range) const

Counts the number of allied units within the specified range.

Parameter Name Parameter Type Description
range float Calculation range
Vector position = GetMyPosition();
int alliesCount = position.CountAlliesInRange(500.0f);

# CountEnemiesInRange

int CountEnemiesInRange(float range) const

Counts the number of enemy units within the specified range.

Parameter Name Parameter Type Description
range float Calculation range
Vector position = GetMyPosition();
int enemiesCount = position.CountEnemiesInRange(500.0f);

# CountEnemyMinionsInRange

int CountEnemyMinionsInRange(float range) const

Counts the number of enemy minions within the specified range.

Parameter Name Parameter Type Description
range float Calculation range
Vector position = GetMyPosition();
int enemyMinionsCount = position.CountEnemyMinionsInRange(500.0f);

# CountAllyMinionsInRange

int CountAllyMinionsInRange(float range) const

Counts the number of allied minions within the specified range.

Parameter Name Parameter Type Description
range float Calculation range
Vector position = GetMyPosition();
int allyMinionsCount = position.CountAllyMinionsInRange(500.0f);

# IsOnScreenV2

bool IsOnScreenV2() const

Checks if the position is on screen (2D view).

Vector position = GetObjectPosition();
bool onScreen = position.IsOnScreenV2();

# IsOnScreenV3

bool IsOnScreenV3() const

Checks if the position is on screen (3D view).

Vector position = GetObjectPosition();
bool onScreen = position.IsOnScreenV3();

# IsWall

bool IsWall() const

Checks if the position is a wall.

Vector position(1000.0f, 1000.0f);
bool isWall = position.IsWall();

# IsGrass

bool IsGrass() const

Checks if the position is grass.

Vector position(1000.0f, 1000.0f);
bool isGrass = position.IsGrass();

# IsRiver

bool IsRiver() const

Checks if the position is in the river.

Vector position(1000.0f, 1000.0f);
bool isRiver = position.IsRiver();

# IsInFOW

bool IsInFOW() const

Checks if the position is in the Fog of War.

Vector position(1000.0f, 1000.0f);
bool inFog = position.IsInFOW();

# GetHeightForPosition

float GetHeightForPosition() const

Gets the terrain height at the position.

Vector position(1000.0f, 1000.0f);
float height = position.GetHeightForPosition();

# UnderAllyTurret

bool UnderAllyTurret(float ExtraRange = 0.f) const

Checks if the position is under an allied turret's range.

Parameter Name Parameter Type Description
ExtraRange float Extra range, default is 0
Vector position = GetMyPosition();
bool underTurret = position.UnderAllyTurret();
bool underTurretWithExtraRange = position.UnderAllyTurret(100.0f);

# UnderEnemyTurret

bool UnderEnemyTurret(float ExtraRange = 0.f) const

Checks if the position is under an enemy turret's range.

Parameter Name Parameter Type Description
ExtraRange float Extra range, default is 0
Vector position = GetMyPosition();
bool underTurret = position.UnderEnemyTurret();
bool underTurretWithExtraRange = position.UnderEnemyTurret(100.0f);

# WorldToMinimap

Vector WorldToMinimap() const

Converts world coordinates to minimap coordinates.

Vector worldPos(1000.0f, 1000.0f);
Vector minimapPos = worldPos.WorldToMinimap();

# WorldToScreen

Vector WorldToScreen() const

Converts world coordinates to screen coordinates.

Vector worldPos(1000.0f, 1000.0f);
Vector screenPos = worldPos.WorldToScreen();

# operator=

Vector& operator=(const Vector& other)

Vector assignment operator.

Vector v1(100.0f, 200.0f);
Vector v2 = v1; // v2 is now a vector (100.0, 200.0)

# operator-

Vector operator-() const

Vector negation operator.

Vector v1(100.0f, 200.0f);
Vector v2 = -v1; // v2 is now a vector (-100.0, -200.0)

# operator+

Vector operator+(const Vector& other) const

Vector addition operator.

Vector v1(100.0f, 200.0f);
Vector v2(50.0f, 50.0f);
Vector sum = v1 + v2; // sum is a vector (150.0, 250.0)

# operator-

Vector operator-(const Vector& other) const

Vector subtraction operator.

Vector v1(100.0f, 200.0f);
Vector v2(50.0f, 50.0f);
Vector diff = v1 - v2; // diff is a vector (50.0, 150.0)

# operator*

Vector operator*(float scalar) const

Vector multiplication by scalar operator.

Vector v1(100.0f, 200.0f);
Vector scaled = v1 * 2.0f; // scaled is a vector (200.0, 400.0)

# operator*

friend Vector operator*(float scalar, const Vector& vec)

Scalar multiplication by vector operator.

Vector v1(100.0f, 200.0f);
Vector scaled = 2.0f * v1; // scaled is a vector (200.0, 400.0)

# operator/

Vector operator/(float scalar) const

Vector division by scalar operator.

Vector v1(100.0f, 200.0f);
Vector divided = v1 / 2.0f; // divided is a vector (50.0, 100.0)

# operator==

bool operator==(const Vector& other) const

Vector equality comparison operator.

Vector v1(100.0f, 200.0f);
Vector v2(100.0f, 200.0f);
bool equal = (v1 == v2); // equal is true

# operator!=

bool operator!=(const Vector& other) const

Vector inequality comparison operator.

Vector v1(100.0f, 200.0f);
Vector v2(50.0f, 50.0f);
bool notEqual = (v1 != v2); // notEqual is true