Skip to content
CShift0.45

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 second
position = position.Add(velocity.Scale(window.DeltaTime()));
canvas.DrawImage(sprite, position.ToPoint().X, position.ToPoint().Y);
Name Description
X The horizontal part.
Y The vertical part.
double X

The horizontal part.

double Y

The vertical part.

Name Description
Create The vector (x, y).
Zero The vector (0, 0).
static Vector2 Create(double x, double y)

The vector (x, y).

static Vector2 Zero()

The vector (0, 0).

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.

Vector2 Subtract(Vector2 other)

This vector minus other.

Vector2 Scale(double factor)

Both parts multiplied by factor.

double Dot(Vector2 other)

The dot product.

double Length()

The length.

double DistanceTo(Vector2 other)

The distance to other.

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).

Point ToPoint()

The nearest pixel.

bool Equals(Vector2 other)

Whether both parts are equal.

string ToString()

“(x, y)”.