![]() |
Roboid Control for C#
|
2-dimensional vectors
Inherits IEquatable< Vector2 >.
Public Member Functions | |
Vector2 (float x, float y) | |
Create a new 2-dimensional vector. | |
bool | Equals (Vector2 v1) |
Tests if the vector has equal values as the given vector. | |
override bool | Equals (object obj) |
Tests if the vector is equal to the given object. | |
override int | GetHashCode () |
Get an hash code for the vector. | |
Static Public Member Functions | |
static Vector2 | operator+ (Vector2 v1, Vector2 v2) |
Add two vectors. | |
static Vector2 | operator- (Vector2 v1, Vector2 v2) |
Subtract two vectors. | |
static Vector2 | operator- (Vector2 v1) |
Negate the vector. | |
static Vector2 | operator* (Vector2 v1, float f) |
Scale a vector uniformly up. | |
static Vector2 | operator* (float f, Vector2 v1) |
Scale a vector uniformly up. | |
static Vector2 | operator/ (Vector2 v1, float f) |
Scale a vector uniformly down. | |
static bool | operator== (Vector2 v1, Vector2 v2) |
Tests if the two vectors have equal values. | |
static bool | operator!= (Vector2 v1, Vector2 v2) |
Tests if two vectors have different values. | |
static float | Distance (Vector2 v1, Vector2 v2) |
Get the distance between two vectors. | |
static float | Dot (Vector2 v1, Vector2 v2) |
The dot product of two vectors. | |
static Vector2 | Lerp (Vector2 v1, Vector2 v2, float f) |
Lerp between two vectors. | |
static float | SignedAngle (Vector2 from, Vector2 to) |
Calculate the signed angle between two vectors. | |
static Vector2 | Rotate (Vector2 v1, float angle) |
Rotates the vector with the given angle. | |
static float | ToFactor (Vector2 v1, Vector2 v2) |
Map interval of angles between vectors [0..Pi] to interval [0..1]. | |
Public Attributes | |
float | x |
The right axis of the vector. | |
float | y |
The upward/forward axis of the vector. | |
Static Public Attributes | |
static readonly Vector2 | zero = new Vector2(0, 0) |
A vector with zero for all axis. | |
static readonly Vector2 | one = new Vector2(1, 1) |
A vector with values (1, 1) | |
static readonly Vector2 | up = new Vector2(0, 1) |
A vector with values (0, 1) | |
static readonly Vector2 | down = new Vector2(0, -1) |
A vector with values (0, -1) | |
static readonly Vector2 | forward = new Vector2(0, 1) |
A vector with values (0, 1) | |
static readonly Vector2 | back = new Vector2(0, -1) |
A vector with values (0, -1) | |
static readonly Vector2 | left = new Vector2(-1, 0) |
A vector3 with values (-1, 0) | |
static readonly Vector2 | right = new Vector2(1, 0) |
A vector with values (1, 0) | |
Properties | |
float | sqrMagnitude [get] |
The squared length of this vector. | |
float | magnitude [get] |
The length of this vector. | |
Vector2 | normalized [get] |
Convert the vector to a length of a 1. | |
LinearAlgebra.Vector2.Vector2 | ( | float | x, |
float | y | ||
) |
Create a new 2-dimensional vector.
x | x axis value |
y | y axis value |
Add two vectors.
v1 | The first vector |
v2 | The second vector |
Subtract two vectors.
v1 | The first vector |
v2 | The second vector |
Negate the vector.
v1 | The vector to negate |
This will result in a vector pointing in the opposite direction
Scale a vector uniformly up.
v1 | The vector to scale |
f | The scaling factor |
Each component of the vector will be multipled with the same factor.
Scale a vector uniformly up.
f | The scaling factor |
v1 | The vector to scale |
Each component of the vector will be multipled with the same factor.
Scale a vector uniformly down.
v1 | The vector to scale |
f | The scaling factor |
Each component of the vector will be devided by the same factor.
bool LinearAlgebra.Vector2.Equals | ( | Vector2 | v1 | ) |
Tests if the vector has equal values as the given vector.
v1 | The vector to compare to |
override bool LinearAlgebra.Vector2.Equals | ( | object | obj | ) |
Tests if the vector is equal to the given object.
obj | The object to compare to |
Tests if the two vectors have equal values.
v1 | The first vector |
v2 | The second vector |
Note that this uses a Float equality check which cannot be not exact in all cases. In most cases it is better to check if the Vector2.Distance between the vectors is smaller than Float.epsilon Or more efficient: (v1 - v2).sqrMagnitude < Float.sqrEpsilon
Tests if two vectors have different values.
v1 | The first vector |
v2 | The second vector |
Note that this uses a Float equality check which cannot be not exact in all case. In most cases it is better to check if the Vector2.Distance between the vectors is smaller than Float.epsilon. Or more efficient: (v1 - v2).sqrMagnitude < Float.sqrEpsilon
override int LinearAlgebra.Vector2.GetHashCode | ( | ) |
Get an hash code for the vector.
Get the distance between two vectors.
v1 | The first vector |
v2 | The second vector |
The dot product of two vectors.
v1 | The first vector |
v2 | The second vector |
Lerp between two vectors.
v1 | The from vector |
v2 | The to vector |
f | The interpolation distance [0..1] |
The factor f is unclamped. Value 0 matches the v1 vector, Value 1 matches the v2 vector Value -1 is v1 vector minus the difference between v1 and v2 etc.
Calculate the signed angle between two vectors.
from | The starting vector |
to | The ending vector |
axis | The axis to rotate around |
Rotates the vector with the given angle.
v1 | The vector to rotate |
angle | The angle in degrees |
Map interval of angles between vectors [0..Pi] to interval [0..1].
v1 | The first vector |
v2 | The second vector |
Vectors a and b must be normalized
|
get |
The squared length of this vector.
The squared length is computationally simpler than the real length. Think of Pythagoras A^2 + B^2 = C^2. This leaves out the calculation of the squared root of C.
|
get |
The length of this vector.
|
get |
Convert the vector to a length of a 1.