Struct SpeedVector2
A 2D vector whose components represent velocity, each expressed as a UnitsNet.Speed (e.g. metres per second, kilometres per hour).
Velocity tells you how fast something is moving and in what direction. It sits in the middle of the kinematics chain: it is produced by multiplying an AccelerationVector2 by a UnitsNet.Duration (v = a·t), or by dividing a LengthVector2 by a UnitsNet.Duration (v = Δx / Δt). Multiplying by another UnitsNet.Duration gives displacement; dividing by a UnitsNet.Duration gives AccelerationVector2.
Each component is independent: a velocity of (3 m/s, 4 m/s) means 3 m/s rightward and 4 m/s upward at the same time, giving a total speed of 5 m/s.
public readonly record struct SpeedVector2 : IEquatable<SpeedVector2>
- Implements
- Inherited Members
- Extension Methods
Examples
// A projectile moving right at 10 m/s and upward at 5 m/s
var velocity = new SpeedVector2(Speed.FromMetersPerSecond(10), Speed.FromMetersPerSecond(5));
// Compute displacement after 2 seconds: Δx = v · t
LengthVector2 displacement = velocity * Duration.FromSeconds(2); // (20 m, 10 m)
Constructors
SpeedVector2(Speed, Speed)
Constructs a SpeedVector2 from two UnitsNet.Speed components.
public SpeedVector2(Speed x, Speed y)
Parameters
xSpeedThe X component.
ySpeedThe Y component.
Properties
Magnitude
Returns the Euclidean magnitude of this vector as a UnitsNet.Speed. The result is expressed in the same unit as the X component.
public Speed Magnitude { get; }
Property Value
- Speed
X
The X component.
public Speed X { get; }
Property Value
- Speed
Y
The Y component.
public Speed Y { get; }
Property Value
- Speed
Zero
A SpeedVector2 with both components set to zero.
public static SpeedVector2 Zero { get; }
Property Value
Methods
Abs()
Returns a vector with each component replaced by its absolute value.
public SpeedVector2 Abs()
Returns
- SpeedVector2
A SpeedVector2 with non-negative components.
Add(SpeedVector2)
Adds two vectors component-wise.
public SpeedVector2 Add(SpeedVector2 other)
Parameters
otherSpeedVector2The vector to add.
Returns
- SpeedVector2
The component-wise sum.
ApproximatelyEquals(SpeedVector2, Speed)
Returns true if each component of this vector is within
tolerance of the corresponding component of other.
public bool ApproximatelyEquals(SpeedVector2 other, Speed tolerance)
Parameters
otherSpeedVector2The vector to compare against.
toleranceSpeedThe maximum allowed difference per component (inclusive).
Returns
As(SpeedUnit)
Projects both components into the requested unit, returning a unit-less DoubleVector2.
public DoubleVector2 As(SpeedUnit unit)
Parameters
unitSpeedUnitThe target unit for each component.
Returns
- DoubleVector2
A DoubleVector2 with components expressed in
unit.
AsDefault()
Returns both components expressed in the SI base unit as a DoubleVector2.
public DoubleVector2 AsDefault()
Returns
- DoubleVector2
A DoubleVector2 with components in the default SI unit.
Clamp(SpeedVector2, SpeedVector2)
Returns a vector with each component clamped to the range [min, max].
public SpeedVector2 Clamp(SpeedVector2 min, SpeedVector2 max)
Parameters
minSpeedVector2The lower bound vector (inclusive, per component).
maxSpeedVector2The upper bound vector (inclusive, per component).
Returns
- SpeedVector2
A SpeedVector2 with each component in [min, max].
Divide(double)
Divides the vector by a scalar divisor.
public SpeedVector2 Divide(double scalar)
Parameters
scalardoubleThe scalar divisor.
Returns
- SpeedVector2
The divided vector.
Dot(ForceVector2)
Returns the instantaneous mechanical power delivered by a force to an object moving at this velocity (P = v⃗ · F⃗), expressed as UnitsNet.Power.
Power is the rate at which work is done. It equals the dot product of velocity
and force: P = v · F · cos(θ), where θ is the angle between the two vectors.
Only the component of force aligned with the direction of motion does
work — a perpendicular force does no work (e.g. centripetal force on a circular path).
public Power Dot(ForceVector2 other)
Parameters
otherForceVector2The force vector acting on the object. Typically the net propulsive force.
Returns
- Power
The instantaneous power in watts (W). Positive = power input; negative = braking.
Examples
// Engine thrust of 1000 N rightward, velocity 20 m/s rightward
var velocity = new SpeedVector2(Speed.FromMetersPerSecond(20), Speed.Zero);
var thrust = new ForceVector2(Force.FromNewtons(1000), Force.Zero);
Power power = velocity.Dot(thrust); // 20 000 W = 20 kW
Equals(SpeedVector2)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(SpeedVector2 other)
Parameters
otherSpeedVector2An object to compare with this object.
Returns
FromCentimetersPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromCentimetersPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromCentimetersPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromCentimetersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromCentimetersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromCentimetersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromCentimetersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromCentimetersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromCentimetersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromDecimetersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromDecimetersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromDecimetersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromDecimetersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromDecimetersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromDecimetersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromFeetPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromFeetPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromFeetPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromFeetPerMinute(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromFeetPerMinute(UnitsNet.QuantityValue).
public static SpeedVector2 FromFeetPerMinute(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromFeetPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromFeetPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromFeetPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromInchesPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromInchesPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromInchesPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromInchesPerMinute(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromInchesPerMinute(UnitsNet.QuantityValue).
public static SpeedVector2 FromInchesPerMinute(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromInchesPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromInchesPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromInchesPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromKilometersPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromKilometersPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromKilometersPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromKilometersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromKilometersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromKilometersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromKilometersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromKilometersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromKilometersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromKnots(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromKnots(UnitsNet.QuantityValue).
public static SpeedVector2 FromKnots(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMach(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMach(UnitsNet.QuantityValue).
public static SpeedVector2 FromMach(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMetersPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMetersPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromMetersPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMetersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMetersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromMetersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMetersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMetersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromMetersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMicrometersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMicrometersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromMicrometersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMicrometersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMicrometersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromMicrometersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMilesPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMilesPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromMilesPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMillimetersPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMillimetersPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromMillimetersPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMillimetersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMillimetersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromMillimetersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromMillimetersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromMillimetersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromMillimetersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromNanometersPerMinutes(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromNanometersPerMinutes(UnitsNet.QuantityValue).
public static SpeedVector2 FromNanometersPerMinutes(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromNanometersPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromNanometersPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromNanometersPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromUsSurveyFeetPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromUsSurveyFeetPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromUsSurveyFeetPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromUsSurveyFeetPerMinute(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromUsSurveyFeetPerMinute(UnitsNet.QuantityValue).
public static SpeedVector2 FromUsSurveyFeetPerMinute(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromUsSurveyFeetPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromUsSurveyFeetPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromUsSurveyFeetPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromYardsPerHour(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromYardsPerHour(UnitsNet.QuantityValue).
public static SpeedVector2 FromYardsPerHour(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromYardsPerMinute(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromYardsPerMinute(UnitsNet.QuantityValue).
public static SpeedVector2 FromYardsPerMinute(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
FromYardsPerSecond(double, double)
Creates a SpeedVector2 with both components created via UnitsNet.Speed.FromYardsPerSecond(UnitsNet.QuantityValue).
public static SpeedVector2 FromYardsPerSecond(double x, double y)
Parameters
Returns
- SpeedVector2
A SpeedVector2 with both components in the corresponding unit.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Lerp(SpeedVector2, SpeedVector2, double)
Linearly interpolates between two vectors.
The result at t = 0 is a; at t = 1 it is
b. Values of t outside [0, 1] extrapolate beyond the
endpoints — use LerpClamped(SpeedVector2, SpeedVector2, double) if you need the result bounded to the segment
between a and b.
public static SpeedVector2 Lerp(SpeedVector2 a, SpeedVector2 b, double t)
Parameters
aSpeedVector2The start vector (
t= 0).bSpeedVector2The end vector (
t= 1).tdoubleThe interpolation parameter. Values outside [0, 1] extrapolate.
Returns
- SpeedVector2
The interpolated SpeedVector2.
LerpClamped(SpeedVector2, SpeedVector2, double)
Linearly interpolates between two vectors, with t clamped to [0, 1].
public static SpeedVector2 LerpClamped(SpeedVector2 a, SpeedVector2 b, double t)
Parameters
aSpeedVector2The start vector (
t= 0).bSpeedVector2The end vector (
t= 1).tdoubleThe interpolation parameter, clamped to [0, 1].
Returns
- SpeedVector2
The interpolated SpeedVector2, always between
aandb.
Multiply(double)
Scales the vector by a scalar factor.
public SpeedVector2 Multiply(double scalar)
Parameters
scalardoubleThe scalar factor.
Returns
- SpeedVector2
The scaled vector.
Negate()
Negates both components.
public SpeedVector2 Negate()
Returns
- SpeedVector2
A vector with all components negated.
Normalize()
Returns a dimensionless unit vector pointing in the same direction. For a zero vector, Zero is returned.
public DoubleVector2 Normalize()
Returns
- DoubleVector2
A unit-length DoubleVector2 in the same direction.
Subtract(SpeedVector2)
Subtracts two vectors component-wise.
public SpeedVector2 Subtract(SpeedVector2 other)
Parameters
otherSpeedVector2The vector to subtract.
Returns
- SpeedVector2
The component-wise difference.
Operators
operator +(SpeedVector2, SpeedVector2)
Adds two vectors component-wise.
public static SpeedVector2 operator +(SpeedVector2 left, SpeedVector2 right)
Parameters
leftSpeedVector2The left operand.
rightSpeedVector2The right operand.
Returns
- SpeedVector2
The component-wise sum.
operator /(SpeedVector2, double)
Divides the vector by a scalar divisor.
public static SpeedVector2 operator /(SpeedVector2 left, double scalar)
Parameters
leftSpeedVector2The vector to divide.
scalardoubleThe scalar divisor.
Returns
- SpeedVector2
The divided vector.
operator /(SpeedVector2, Duration)
Divides a SpeedVector2 by a UnitsNet.Duration to produce a AccelerationVector2.
public static AccelerationVector2 operator /(SpeedVector2 left, Duration right)
Parameters
leftSpeedVector2The left operand.
rightDurationThe right operand.
Returns
operator *(double, SpeedVector2)
Scales the vector by a scalar factor. Operands may be supplied in either order.
public static SpeedVector2 operator *(double scalar, SpeedVector2 right)
Parameters
scalardoubleThe scalar factor.
rightSpeedVector2The vector to scale.
Returns
- SpeedVector2
The scaled vector.
operator *(SpeedVector2, double)
Scales the vector by a scalar factor.
public static SpeedVector2 operator *(SpeedVector2 left, double scalar)
Parameters
leftSpeedVector2The vector to scale.
scalardoubleThe scalar factor.
Returns
- SpeedVector2
The scaled vector.
operator *(SpeedVector2, Duration)
Multiplies a SpeedVector2 by a UnitsNet.Duration to produce a LengthVector2.
public static LengthVector2 operator *(SpeedVector2 left, Duration right)
Parameters
leftSpeedVector2The left operand.
rightDurationThe right operand.
Returns
operator *(SpeedVector2, Mass)
Multiplies a velocity vector by a mass to produce a momentum (impulse) vector (p = m·v), preserving the caller's unit pair where possible.
Linear momentum is the "quantity of motion" of an object. The result unit is derived from the (SpeedUnit, MassUnit) pair: m/s × kg = kg·m/s, ft/s × slug = slug·ft/s, ft/s × lb = lb·ft/s. All other combinations fall back to N·s.
public static ImpulseVector2 operator *(SpeedVector2 left, Mass right)
Parameters
leftSpeedVector2The velocity vector.
rightMassThe mass of the object.
Returns
- ImpulseVector2
The momentum vector in the unit matching the (speed, mass) pair.
Examples
var velocity = new SpeedVector2(Speed.FromMetersPerSecond(5), Speed.Zero);
ImpulseVector2 momentum = velocity * Mass.FromKilograms(2); // (10 kg·m/s, 0)
operator *(Duration, SpeedVector2)
Multiplies a UnitsNet.Duration by a SpeedVector2 to produce a LengthVector2. Operands may be supplied in either order.
public static LengthVector2 operator *(Duration left, SpeedVector2 right)
Parameters
leftDurationThe left operand.
rightSpeedVector2The right operand.
Returns
operator *(Mass, SpeedVector2)
Multiplies a mass by a velocity vector to produce a momentum vector (p = m·v). Operands may be supplied in either order.
public static ImpulseVector2 operator *(Mass left, SpeedVector2 right)
Parameters
leftMassThe mass of the object.
rightSpeedVector2The velocity vector.
Returns
- ImpulseVector2
The momentum vector in the unit matching the (speed, mass) pair.
operator -(SpeedVector2, SpeedVector2)
Subtracts two vectors component-wise.
public static SpeedVector2 operator -(SpeedVector2 left, SpeedVector2 right)
Parameters
leftSpeedVector2The left operand.
rightSpeedVector2The right operand.
Returns
- SpeedVector2
The component-wise difference.
operator -(SpeedVector2)
Negates both components.
public static SpeedVector2 operator -(SpeedVector2 value)
Parameters
valueSpeedVector2The vector to negate.
Returns
- SpeedVector2
A vector with all components negated.