Struct double2
Represents a 2D vector using two double-precision.
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct double2 : IEquatable<double2>
Remarks
The double2 structure is suitable for inter-operation with unmanaged code requiring two consecutive doubles.
Constructors
double2(Double)
Constructs a new double2.
Declaration
public double2(double val)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val | This value will be set for the x and y component. |
double2(Double, Double)
Constructs a new double2.
Declaration
public double2(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The x coordinate of the net double2. |
System.Double | y | The y coordinate of the net double2. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly double2 One
Field Value
Type | Description |
---|---|
double2 |
UnitX
Defines a unit-length double2 that points towards the x-axis.
Declaration
public static readonly double2 UnitX
Field Value
Type | Description |
---|---|
double2 |
UnitY
Defines a unit-length double2 that points towards the y-axis.
Declaration
public static readonly double2 UnitY
Field Value
Type | Description |
---|---|
double2 |
x
The x component of the double2.
Declaration
public double x
Field Value
Type | Description |
---|---|
System.Double |
y
The y component of the double2.
Declaration
public double y
Field Value
Type | Description |
---|---|
System.Double |
Zero
Defines a zero-length double2.
Declaration
public static readonly double2 Zero
Field Value
Type | Description |
---|---|
double2 |
Properties
g
The green component (same as y)
Declaration
public double g { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
Item[Int32]
Gets or sets the individual components x and y, depending on their index.
Declaration
public double this[int idx] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | idx | The index (between 0 and 1). |
Property Value
Type | Description |
---|---|
System.Double | The x or y component of the double2. |
Length
Gets the length (magnitude) of the vector.
Declaration
public readonly double Length { get; }
Property Value
Type | Description |
---|---|
System.Double | The length. |
LengthSquared
Gets the square of the vector length (magnitude).
Declaration
public readonly double LengthSquared { get; }
Property Value
Type | Description |
---|---|
System.Double | The length squared. |
Remarks
This property avoids the costly square root operation required by the Length property. This makes it more suitable for comparisons.
ParseConverter
Gets and sets the Converter object. Has the ability to convert a string to a double2.
Declaration
public static Converter<string, double2> ParseConverter { get; set; }
Property Value
Type | Description |
---|---|
Converter<System.String, double2> | The parse property. |
PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
Declaration
public readonly double2 PerpendicularLeft { get; }
Property Value
Type | Description |
---|---|
double2 | The perpendicular left. |
PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Declaration
public readonly double2 PerpendicularRight { get; }
Property Value
Type | Description |
---|---|
double2 | The perpendicular right. |
r
The red component (same as x)
Declaration
public double r { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
rg
The rg component (same as xy)
Declaration
public double2 rg { get; set; }
Property Value
Type | Description |
---|---|
double2 |
xy
Gets and sets an OpenTK.double2 with the x and y components of this instance.
Declaration
public double2 xy { get; set; }
Property Value
Type | Description |
---|---|
double2 |
yx
Gets or sets an OpenTK.double2 with the y and x components of this instance.
Declaration
public double2 yx { get; set; }
Property Value
Type | Description |
---|---|
double2 |
Methods
Add(double2, double2)
Adds two vectors.
Declaration
public static double2 Add(double2 a, double2 b)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | Left operand. |
double2 | b | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of operation. |
Barycentric(double2, double2, double2, Double, Double)
Interpolate 3 Vectors using Barycentric coordinates
Declaration
public static double2 Barycentric(double2 a, double2 b, double2 c, double u, double v)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First input Vector |
double2 | b | Second input Vector |
double2 | c | Third input Vector |
System.Double | u | First Barycentric Coordinate |
System.Double | v | Second Barycentric Coordinate |
Returns
Type | Description |
---|---|
double2 | a when u=1,v=9, b when u=0,v=1, c when u=v=1, and a linear combination of a,b,c otherwise |
Clamp(double2, double2, double2)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static double2 Clamp(double2 vec, double2 min, double2 max)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | Input vector |
double2 | min | Minimum vector |
double2 | max | Maximum vector |
Returns
Type | Description |
---|---|
double2 | The clamped vector |
ComponentMax(double2, double2)
Calculate the component-wise maximum of two vectors
Declaration
public static double2 ComponentMax(double2 a, double2 b)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First operand |
double2 | b | Second operand |
Returns
Type | Description |
---|---|
double2 | The component-wise maximum |
ComponentMin(double2, double2)
Calculate the component-wise minimum of two vectors
Declaration
public static double2 ComponentMin(double2 a, double2 b)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First operand |
double2 | b | Second operand |
Returns
Type | Description |
---|---|
double2 | The component-wise minimum |
Divide(double2, double2)
Divides a vector by the components of a vector (scale).
Declaration
public static double2 Divide(double2 vector, double2 scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vector | Left operand. |
double2 | scale | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of the operation. |
Divide(double2, Double)
Divides a vector by a scalar.
Declaration
public static double2 Divide(double2 vector, double scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vector | Left operand. |
System.Double | scale | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of the operation. |
Dot(double2, double2)
Calculate the dot (scalar) product of two vectors
Declaration
public static double Dot(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | First operand |
double2 | right | Second operand |
Returns
Type | Description |
---|---|
System.Double | The dot product of the two inputs |
Equals(double2)
Indicates whether the current vector is equal to another vector.
Declaration
public bool Equals(double2 other)
Parameters
Type | Name | Description |
---|---|---|
double2 | other | A vector to compare with this vector. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current vector is equal to the vector parameter; otherwise, false. |
Equals(Object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to compare to. |
Returns
Type | Description |
---|---|
System.Boolean | True if the instances are equal; false otherwise. |
Overrides
GetBarycentric(double2, double2, double2, double2, out Double, out Double)
Calculates the barycentric coordinates for the given point in the given triangle, such that ua + vb + (1-u-v)*c = point.
Declaration
public static void GetBarycentric(double2 a, double2 b, double2 c, double2 point, out double u, out double v)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | The first point of the triangle. |
double2 | b | The second point of the triangle. |
double2 | c | The third point of the triangle. |
double2 | point | The point to calculate the barycentric coordinates for. |
System.Double | u | The resulting barycentric u coordinate (weight for vertex a). |
System.Double | v | The resulting barycentric v coordinate (weight for vertex b). |
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A System.Int32 containing the unique hashcode for this instance. |
Overrides
IsTriangleCW(double2, double2, double2)
Checks if the three given 2D points form a clockwise (CW) triangle
Declaration
public static bool IsTriangleCW(double2 a, double2 b, double2 c)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | The first point of the triangle. |
double2 | b | The second point of the triangle. |
double2 | c | The third point of the triangle. |
Returns
Type | Description |
---|---|
System.Boolean | true if the triangle is clockwise, otherwise false. |
Lerp(double2, double2, double2)
Returns a new Vector that is the linear blend of the 2 given Vectors. Each component of vector a is blended with its equivalent in vector b.
Declaration
public static double2 Lerp(double2 a, double2 b, double2 blend)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First input vector |
double2 | b | Second input vector |
double2 | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
double2 |
Lerp(double2, double2, Double)
Returns a new Vector that is the linear blend of the 2 given Vectors
Declaration
public static double2 Lerp(double2 a, double2 b, double blend)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First input vector |
double2 | b | Second input vector |
System.Double | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
double2 | a when blend=0, b when blend=1, and a linear combination otherwise |
Max(double2, double2)
Returns the double3 with the minimum magnitude
Declaration
public static double2 Max(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand |
double2 | right | Right operand |
Returns
Type | Description |
---|---|
double2 | The minimum double3 |
Min(double2, double2)
Returns the double3 with the minimum magnitude
Declaration
public static double2 Min(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand |
double2 | right | Right operand |
Returns
Type | Description |
---|---|
double2 | The minimum double3 |
Multiply(double2, double2)
Multiplies a vector by the components a vector (scale).
Declaration
public static double2 Multiply(double2 vector, double2 scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vector | Left operand. |
double2 | scale | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of the operation. |
Multiply(double2, Double)
Multiplies a vector by a scalar.
Declaration
public static double2 Multiply(double2 vector, double scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vector | Left operand. |
System.Double | scale | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of the operation. |
Normalize()
Scales the double2 to unit length.
Declaration
public double2 Normalize()
Returns
Type | Description |
---|---|
double2 |
Normalize(double2)
Scale a vector to unit length
Declaration
public static double2 Normalize(double2 vec)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | The input vector |
Returns
Type | Description |
---|---|
double2 | The normalized vector |
NormalizeFast()
Scales the double2 to approximately unit length.
Declaration
public double2 NormalizeFast()
Returns
Type | Description |
---|---|
double2 |
NormalizeFast(double2)
Scale a vector to approximately unit length
Declaration
public static double2 NormalizeFast(double2 vec)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | The input vector |
Returns
Type | Description |
---|---|
double2 | The normalized vector |
Parse(String, IFormatProvider)
Parses a string into a double2.
Declaration
public static double2 Parse(string source, IFormatProvider provider = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | |
System.IFormatProvider | provider |
Returns
Type | Description |
---|---|
double2 |
PointInTriangle(double2, double2, double2, double2, out Double, out Double)
Checks if the give point is inside the given triangle (a, b, c). Returns the barycentric coordinates using GetBarycentric(double2, double2, double2, double2, out Double, out Double).
Declaration
public static bool PointInTriangle(double2 a, double2 b, double2 c, double2 point, out double u, out double v)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | The first point of the triangle. |
double2 | b | The second point of the triangle. |
double2 | c | The third point of the triangle. |
double2 | point | The point to calculate the barycentric coordinates for. |
System.Double | u | The resulting barycentric u coordinate (weight for vertex a). |
System.Double | v | The resulting barycentric v coordinate (weight for vertex b). |
Returns
Type | Description |
---|---|
System.Boolean | true, if the point is inside the triangle a, b, c. Otherwise false. |
Pow(double2, Double)
Returns a double2 where all components are raised to the specified power.
Declaration
public static double2 Pow(double2 val, double exp)
Parameters
Type | Name | Description |
---|---|---|
double2 | val | The double3 to be raised to a power. |
System.Double | exp | A double that specifies a power. |
Returns
Type | Description |
---|---|
double2 |
Step(double2, double2)
Performs Step(Double, Double) for each component of the input vectors.
Declaration
public static double2 Step(double2 edge, double2 val)
Parameters
Type | Name | Description |
---|---|---|
double2 | edge | Specifies the location of the edge of the step function. |
double2 | val | Specifies the value to be used to generate the step function. |
Returns
Type | Description |
---|---|
double2 |
Subtract(double2, double2)
Subtract one Vector from another
Declaration
public static double2 Subtract(double2 a, double2 b)
Parameters
Type | Name | Description |
---|---|---|
double2 | a | First operand |
double2 | b | Second operand |
Returns
Type | Description |
---|---|
double2 | Result of subtraction |
ToArray()
Returns an array of doubles with the two components of the vector.
Declaration
public double[] ToArray()
Returns
Type | Description |
---|---|
System.Double[] | Returns an array of doubles with the two components of the vector. |
ToString()
Returns a System.String that represents the current double2.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Overrides
ToString(IFormatProvider)
Returns a System.String that represents the current double2.
Declaration
public string ToString(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider | Provides information about a specific culture. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Operators
Addition(double2, double2)
Adds the specified instances.
Declaration
public static double2 operator +(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
double2 | right | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of addition. |
Addition(double2, Double)
Adds a scalar to the specified instance.
Declaration
public static double2 operator +(double2 left, double scalar)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
System.Double | scalar | The scalar. |
Returns
Type | Description |
---|---|
double2 | Result of addition. |
Division(double2, Double)
Divides the specified instance by a scalar.
Declaration
public static double2 operator /(double2 vec, double scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | Left operand |
System.Double | scale | Right operand |
Returns
Type | Description |
---|---|
double2 | Result of the division. |
Equality(double2, double2)
Compares the specified instances for equality.
Declaration
public static bool operator ==(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
double2 | right | Right operand. |
Returns
Type | Description |
---|---|
System.Boolean | True if both instances are equal; false otherwise. |
Inequality(double2, double2)
Compares the specified instances for inequality.
Declaration
public static bool operator !=(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
double2 | right | Right operand. |
Returns
Type | Description |
---|---|
System.Boolean | True if both instances are not equal; false otherwise. |
Multiply(double2, double2)
Multiplies two instances.
Declaration
public static double2 operator *(double2 vec1, double2 vec2)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec1 | Left operand. |
double2 | vec2 | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of multiplication. |
Multiply(double2, Double)
Multiplies the specified instance by a scalar.
Declaration
public static double2 operator *(double2 vec, double scale)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | Left operand. |
System.Double | scale | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of multiplication. |
Multiply(Double, double2)
Multiplies the specified instance by a scalar.
Declaration
public static double2 operator *(double scale, double2 vec)
Parameters
Type | Name | Description |
---|---|---|
System.Double | scale | Left operand. |
double2 | vec | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of multiplication. |
Subtraction(double2, double2)
Subtracts the specified instances.
Declaration
public static double2 operator -(double2 left, double2 right)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
double2 | right | Right operand. |
Returns
Type | Description |
---|---|
double2 | Result of subtraction. |
Subtraction(double2, Double)
Subtracts a scalar from the specified instance.
Declaration
public static double2 operator -(double2 left, double scalar)
Parameters
Type | Name | Description |
---|---|---|
double2 | left | Left operand. |
System.Double | scalar | The scalar. |
Returns
Type | Description |
---|---|
double2 | Result of addition. |
UnaryNegation(double2)
Negates the specified instance.
Declaration
public static double2 operator -(double2 vec)
Parameters
Type | Name | Description |
---|---|---|
double2 | vec | Operand. |
Returns
Type | Description |
---|---|
double2 | Result of negation. |