Struct MagneticFieldVector2
A 2D vector whose components represent a magnetic field, each expressed as a UnitsNet.MagneticField (e.g. tesla).
public readonly record struct MagneticFieldVector2 : IEquatable<MagneticFieldVector2>
- Implements
- Inherited Members
- Extension Methods
Examples
var field = new MagneticFieldVector2(MagneticField.FromTeslas(0.5), MagneticField.Zero);
Constructors
MagneticFieldVector2(MagneticField, MagneticField)
Constructs a MagneticFieldVector2 from two UnitsNet.MagneticField components.
public MagneticFieldVector2(MagneticField x, MagneticField y)
Parameters
xMagneticFieldThe X component.
yMagneticFieldThe Y component.
Properties
Magnitude
Returns the Euclidean magnitude of this vector as a UnitsNet.MagneticField. The result is expressed in the same unit as the X component.
public MagneticField Magnitude { get; }
Property Value
- MagneticField
X
The X component.
public MagneticField X { get; }
Property Value
- MagneticField
Y
The Y component.
public MagneticField Y { get; }
Property Value
- MagneticField
Zero
A MagneticFieldVector2 with both components set to zero.
public static MagneticFieldVector2 Zero { get; }
Property Value
Methods
Abs()
Returns a vector with each component replaced by its absolute value.
public MagneticFieldVector2 Abs()
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with non-negative components.
Add(MagneticFieldVector2)
Adds two vectors component-wise.
public MagneticFieldVector2 Add(MagneticFieldVector2 other)
Parameters
otherMagneticFieldVector2The vector to add.
Returns
- MagneticFieldVector2
The component-wise sum.
ApproximatelyEquals(MagneticFieldVector2, MagneticField)
Returns true if each component of this vector is within
tolerance of the corresponding component of other.
public bool ApproximatelyEquals(MagneticFieldVector2 other, MagneticField tolerance)
Parameters
otherMagneticFieldVector2The vector to compare against.
toleranceMagneticFieldThe maximum allowed difference per component (inclusive).
Returns
As(MagneticFieldUnit)
Projects both components into the requested unit, returning a unit-less DoubleVector2.
public DoubleVector2 As(MagneticFieldUnit unit)
Parameters
unitMagneticFieldUnitThe 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(MagneticFieldVector2, MagneticFieldVector2)
Returns a vector with each component clamped to the range [min, max].
public MagneticFieldVector2 Clamp(MagneticFieldVector2 min, MagneticFieldVector2 max)
Parameters
minMagneticFieldVector2The lower bound vector (inclusive, per component).
maxMagneticFieldVector2The upper bound vector (inclusive, per component).
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with each component in [min, max].
Divide(double)
Divides the vector by a scalar divisor.
public MagneticFieldVector2 Divide(double scalar)
Parameters
scalardoubleThe scalar divisor.
Returns
- MagneticFieldVector2
The divided vector.
Equals(MagneticFieldVector2)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(MagneticFieldVector2 other)
Parameters
otherMagneticFieldVector2An object to compare with this object.
Returns
FromGausses(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromGausses(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromGausses(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with both components in the corresponding unit.
FromMicroteslas(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromMicroteslas(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromMicroteslas(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with both components in the corresponding unit.
FromMilligausses(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromMilligausses(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromMilligausses(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with both components in the corresponding unit.
FromMilliteslas(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromMilliteslas(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromMilliteslas(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with both components in the corresponding unit.
FromNanoteslas(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromNanoteslas(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromNanoteslas(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 with both components in the corresponding unit.
FromTeslas(double, double)
Creates a MagneticFieldVector2 with both components created via UnitsNet.MagneticField.FromTeslas(UnitsNet.QuantityValue).
public static MagneticFieldVector2 FromTeslas(double x, double y)
Parameters
Returns
- MagneticFieldVector2
A MagneticFieldVector2 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(MagneticFieldVector2, MagneticFieldVector2, 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(MagneticFieldVector2, MagneticFieldVector2, double) if you need the result bounded to the segment
between a and b.
public static MagneticFieldVector2 Lerp(MagneticFieldVector2 a, MagneticFieldVector2 b, double t)
Parameters
aMagneticFieldVector2The start vector (
t= 0).bMagneticFieldVector2The end vector (
t= 1).tdoubleThe interpolation parameter. Values outside [0, 1] extrapolate.
Returns
- MagneticFieldVector2
The interpolated MagneticFieldVector2.
LerpClamped(MagneticFieldVector2, MagneticFieldVector2, double)
Linearly interpolates between two vectors, with t clamped to [0, 1].
public static MagneticFieldVector2 LerpClamped(MagneticFieldVector2 a, MagneticFieldVector2 b, double t)
Parameters
aMagneticFieldVector2The start vector (
t= 0).bMagneticFieldVector2The end vector (
t= 1).tdoubleThe interpolation parameter, clamped to [0, 1].
Returns
- MagneticFieldVector2
The interpolated MagneticFieldVector2, always between
aandb.
Multiply(double)
Scales the vector by a scalar factor.
public MagneticFieldVector2 Multiply(double scalar)
Parameters
scalardoubleThe scalar factor.
Returns
- MagneticFieldVector2
The scaled vector.
Negate()
Negates both components.
public MagneticFieldVector2 Negate()
Returns
- MagneticFieldVector2
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(MagneticFieldVector2)
Subtracts two vectors component-wise.
public MagneticFieldVector2 Subtract(MagneticFieldVector2 other)
Parameters
otherMagneticFieldVector2The vector to subtract.
Returns
- MagneticFieldVector2
The component-wise difference.
Operators
operator +(MagneticFieldVector2, MagneticFieldVector2)
Adds two vectors component-wise.
public static MagneticFieldVector2 operator +(MagneticFieldVector2 left, MagneticFieldVector2 right)
Parameters
leftMagneticFieldVector2The left operand.
rightMagneticFieldVector2The right operand.
Returns
- MagneticFieldVector2
The component-wise sum.
operator /(MagneticFieldVector2, double)
Divides the vector by a scalar divisor.
public static MagneticFieldVector2 operator /(MagneticFieldVector2 left, double scalar)
Parameters
leftMagneticFieldVector2The vector to divide.
scalardoubleThe scalar divisor.
Returns
- MagneticFieldVector2
The divided vector.
operator *(double, MagneticFieldVector2)
Scales the vector by a scalar factor. Operands may be supplied in either order.
public static MagneticFieldVector2 operator *(double scalar, MagneticFieldVector2 right)
Parameters
scalardoubleThe scalar factor.
rightMagneticFieldVector2The vector to scale.
Returns
- MagneticFieldVector2
The scaled vector.
operator *(MagneticFieldVector2, double)
Scales the vector by a scalar factor.
public static MagneticFieldVector2 operator *(MagneticFieldVector2 left, double scalar)
Parameters
leftMagneticFieldVector2The vector to scale.
scalardoubleThe scalar factor.
Returns
- MagneticFieldVector2
The scaled vector.
operator -(MagneticFieldVector2, MagneticFieldVector2)
Subtracts two vectors component-wise.
public static MagneticFieldVector2 operator -(MagneticFieldVector2 left, MagneticFieldVector2 right)
Parameters
leftMagneticFieldVector2The left operand.
rightMagneticFieldVector2The right operand.
Returns
- MagneticFieldVector2
The component-wise difference.
operator -(MagneticFieldVector2)
Negates both components.
public static MagneticFieldVector2 operator -(MagneticFieldVector2 value)
Parameters
valueMagneticFieldVector2The vector to negate.
Returns
- MagneticFieldVector2
A vector with all components negated.