sincerely
Singaporean
If you have not done so, read this full tutorial on how to use SGEXTN to build an application.
class SGXVector2;
part of SGEXTN module SG_Core
2D vector with basic geometry and linear algebra operations builtin
list of all including inherited members
preprocessor file inclusion directive: #include ‹SGXVector2.h›
CMake target for BuildLah: SGEXTN::SG_Core
see this link for more information about BuildLah
parent class: (none)
children classes: (none)
float x;
float y;
SGXVector2(float x, float y);
[[nodiscard]] float getArgument() const;
[[nodiscard]] float getDistanceToCircle(float a, float b, float r) const;
[[nodiscard]] float getDistanceToLine(SGXVector2 a, SGXVector2 b) const;
[[nodiscard]] float getDistanceToSegment(SGXVector2 a, SGXVector2 b) const;
[[nodiscard]] float getMagnitude() const;
[[nodiscard]] float getMagnitudeSquare() const;
[[nodiscard]] SGXVector2 getNearestPointOnCircle(float a, float b, float r) const;
[[nodiscard]] SGXVector2 getNearestPointOnLine(SGXVector2 a, SGXVector2 b) const;
[[nodiscard]] SGXVector2 getNearestPointOnSegment(SGXVector2 a, SGXVector2 b) const;
[[nodiscard]] SGXString getStringForPrinting() const;
[[nodiscard]] int hash() const;
SGXVector2& invert();
SGXVector2& normalise();
SGXVector2& normaliseGivenMagnitude(float m);
[[nodiscard]] bool operator!=(SGXVector2 x) const;
SGXVector2& operator*=(float m);
[[nodiscard]] SGXVector2 operator*(float m) const;
[[nodiscard]] SGXVector2 operator+(SGXVector2 x) const;
SGXVector2& operator+=(SGXVector2 x);
[[nodiscard]] SGXVector2 operator-(SGXVector2 x) const;
SGXVector2& operator-=(SGXVector2 x);
[[nodiscard]] SGXVector2 operator/(float m) const;
SGXVector2& operator/=(float m);
[[nodiscard]] bool operator‹(SGXVector2 x) const;
[[nodiscard]] bool operator==(SGXVector2 x) const;
[[nodiscard]] bool operator›(SGXVector2 x) const;
SGXVector2& projectToLine(SGXVector2 a, SGXVector2 b);
SGXVector2& projectToX();
SGXVector2& projectToY();
SGXVector2& redirectUsingArgument(float a);
SGXVector2& reflectAcrossLine(SGXVector2 a, SGXVector2 b);
SGXVector2& reflectAcrossPoint(SGXVector2 x);
SGXVector2& rotate180();
SGXVector2& rotateClockwise(float a);
SGXVector2& rotateClockwise90();
SGXVector2& rotateCounterclockwise(float a);
SGXVector2& rotateCounterclockwise90();
static const SGXVector2 origin;
static float crossProduct(SGXVector2 a, SGXVector2 b);
static float dotProduct(SGXVector2 a, SGXVector2 b);
static float getAngleBetween(SGXVector2 a, SGXVector2 b);
static float getDistance(SGXVector2 a, SGXVector2 b);
static float getDistanceSquare(SGXVector2 a, SGXVector2 b);
static bool isCollinear(SGXVector2 x, SGXVector2 a, SGXVector2 b, float limit);
static bool isParallel(SGXVector2 a1, SGXVector2 a2, SGXVector2 b1, SGXVector2 b2, float limit);
static bool isPerpendicular(SGXVector2 x, SGXVector2 a, SGXVector2 b, float limit);
static SGXVector2 linearInterpolate(SGXVector2 a, SGXVector2 b, float f);
static SGXVector2 midpoint(SGXVector2 a, SGXVector2 b);
SGXVector2 represents a 2D vector which depending on context can refer to either the vector itself or the endpoint of the vector. Common geometry and linear algebra operations are builtin to SGXVector2. SGEXTN currently has no plans of building a 3D vector as it is not designed for rendering in 3D.
Stores 2 floating point numbers, 1 per coordinate.
X coordinate.
Y coordinate.
Creates a SGXVector2 with x coordinate of x and y coordinate of y.
Returns the argument of this SGXVector2 in degrees, that is its signed angle away from the positive x direction.
If the SGXVector2 is the origin, this is not defined, but it will not crash.
Returns the distance from this SGXVector2 to the circle centered at (a, b) with radius r.
This is negative if this SGXVector2 is inside the circle.
a and b may be merged into a single SGXVector2 argument in a future version of SGEXTN.
Returns the distance from this SGXVector2 to the line formed by joining a with b.
Returns the distance from this SGXVector2 to the line segment formed by joining a with b.
Returns the magnitude of this SGXVector2.
Returns the square of the magnitude of this SGXVector2.
This is slightly faster than SGXVector2::getMagnitude as it does not involve square root computation.
Returns the nearest point to this SGXVector2 on the circle centered at (a, b) with radius r.
Returns the nearest point to this SGXVector2 on the line formed by joining a with b.
Returns the nearest point to this SGXVector2 on the line segment formed by joining a with b.
Returns SGXString representing this SGXVector2 in the format (x, y).
Hash function for SGLHash.
Multiplies this SGXVector2 by -1 and returns a reference to this SGXVector2 to allow operation chaining.
Normalises this SGXVector2, or sets its magnitude to 1 without changing its direction and returns a reference to this SGXVector2 to allow operation chaining.
Sets the magnitude of this SGXVector2 to m without changing its direction and returns a reference to this SGXVector2 to allow operation chaining.
Returns if this SGXVector2 is different from x.
Multiplies this SGXVector2 by m and returns a reference to this SGXVector2.
Returns (this SGXVector2 * m).
Returns (this SGXVector2 + x).
Adds x to this SGXVector2 and returns a reference to this SGXVector2.
Returns (this SGXVector2 - x).
Subtracts x from this SGXVector2 and returns a reference to this SGXVector2.
Returns (this SGXVector2 / m).
Division by 0 here follows floating point numbers division by 0 rules.
Divides this SGXVector2 by m and returns a reference to this SGXVector2.
Lesser than operator with x for SGLLesserThan and SGLMoreThan.
Returns if this SGXVector2 is the same as x.
More than operator with x for SGLLesserThan and SGLMoreThan.
Projects this SGXVector2 onto the line formed by joining a and b and returns a reference to this SGXVector2 to allow operation chaining.
Projects this SGXVector2 onto the x axis and returns a reference to this SGXVector2 to allow operation chaining.
This is equivalent to setting its y coordinate to 0.
Projects this SGXVector2 onto the y axis and returns a reference to this SGXVector2 to allow operation chaining.
This is equivalent to setting its x coordinate to 0.
Sets the argument of this SGXVector2 to a degrees without changing its magnitude and returns a reference to this SGXVector2 to allow operation chaining.
Reflects this SGXVector2 across the line formed by joining a with b and returns a reference to this SGXVector2 to allow operation chaining.
Reflects this SGXVector2 across x and returns a reference to this SGXVector2 to allow operation chaining.
Reflect this SGXVector2 across the x axis and returns a reference to this SGXVector2 to allow operation chaining.
This is equivalent to multiplying its y coordinate by -1.
Reflect this SGXVector2 across the y axis and returns a reference to this SGXVector2 to allow operation chaining.
This is equivalent to multiplying its x coordinate by -1.
Rotates this SGXVector2 by 180 degrees in either direction and returns a reference to this SGXVector2 to allow operation chaining.
This is equivalent to multiplying the SGXVector2 by -1.
Rotates this SGXVector2 by a degrees clockwise and returns a reference to this SGXVector2 to allow operation chaining.
Rotates this SGXVector2 clockwise by 90 degrees and returns a reference to this SGXVector2 to allow operation chaining.
Rotates this SGXVector2 by a degrees counterclockwise and returns a reference to this SGXVector2 to allow operation chaining.
Rotates this SGXVector2 counterclockwise by 90 degrees and returns a reference to this SGXVector2 to allow operation chaining.
The origin, which is (0, 0).
Returns the cross product of a with b.
Returns the dot product of a with b.
Returns the angle between a and b in degrees.
Returns the distance from a to b.
Returns the squared distance from a to b.
This is slightly faster than SGXVector2::getDistance as it does not involve square root computation.
Returns if x, a, and b are (almost) collinear with angle AXB at most limit degrees away from 0 or 180.
If any 2 points overlap, the behaviour is not defined but it will not crash.
Returns if the line formed by joining a1 with a2 and the line formed by joining b1 with b2 are (almost) parallel with the angle formed between them at most limit degrees.
If any 2 points overlap, the behaviour is not defined but it will not crash.
Returns if the line formed by joining this x with a is (almost) perpendicular with the line formed by joining x with b with angle AXB at most limit degrees away from 90.
If any 2 points overlap, the behaviour is not defined but it will not crash.
Returns f * a + (1 - f) * b.
It is ok for f to be below 0 or above 1.
Returns the midpoint of a and b.
©2025 05524F.sg (Singapore)