Vector2
Struct · namespace System.Drawing · Since 0.45
struct Vector2 : IEquatable<Vector2>A position or a direction with fractions, for movement and physics; Vector2.ToPoint rounds it to a pixel.
var velocity = Vector2.Create(1.0, -0.5).Normalized().Scale(120.0); // 120 pixels a secondposition = position.Add(velocity.Scale(window.DeltaTime()));canvas.DrawImage(sprite, position.ToPoint().X, position.ToPoint().Y);Fields
Section titled “Fields”| Name | Description |
|---|---|
X |
The horizontal part. |
Y |
The vertical part. |
double XThe horizontal part.
double YThe vertical part.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
The vector (x, y). |
Zero |
The vector (0, 0). |
Create
Section titled “Create”static Vector2 Create(double x, double y)The vector (x, y).
static Vector2 Zero()The vector (0, 0).
Methods
Section titled “Methods”| Name | Description |
|---|---|
Add |
The sum of both vectors. |
Subtract |
This vector minus other. |
Scale |
Both parts multiplied by factor. |
Dot |
The dot product. |
Length |
The length. |
DistanceTo |
The distance to other. |
Normalized |
The same direction with length 1 (the zero vector stays zero). |
Lerp |
The vector between this one (t = 0.0) and other (t = 1.0). |
ToPoint |
The nearest pixel. |
Equals |
Whether both parts are equal. |
ToString |
“(x, y)”. |
Vector2 Add(Vector2 other)The sum of both vectors.
Subtract
Section titled “Subtract”Vector2 Subtract(Vector2 other)This vector minus other.
Vector2 Scale(double factor)Both parts multiplied by factor.
double Dot(Vector2 other)The dot product.
Length
Section titled “Length”double Length()The length.
DistanceTo
Section titled “DistanceTo”double DistanceTo(Vector2 other)The distance to other.
Normalized
Section titled “Normalized”Vector2 Normalized()The same direction with length 1 (the zero vector stays zero).
Vector2 Lerp(Vector2 other, double t)The vector between this one (t = 0.0) and other (t = 1.0).
ToPoint
Section titled “ToPoint”Point ToPoint()The nearest pixel.
Equals
Section titled “Equals”bool Equals(Vector2 other)Whether both parts are equal.
ToString
Section titled “ToString”string ToString()“(x, y)”.