Struct Vector4
4D Vector structure with X, Y, Z and W coordinates.
Namespace: ISynergy.Framework.Mathematics
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public struct Vector4
Remarks
The structure incapsulates X, Y, Z and W coordinates of a 4D vector and provides some operations with it.
Constructors
View SourceVector4(Single)
Initializes a new instance of the Vector4 structure.
Declaration
public Vector4(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | Value, which is set to all 4 coordinates of the vector. |
Vector4(Single, Single, Single, Single)
Initializes a new instance of the Vector4 structure.
Declaration
public Vector4(float x, float y, float z, float w)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | X coordinate of the vector. |
System.Single | y | Y coordinate of the vector. |
System.Single | z | Z coordinate of the vector. |
System.Single | w | W coordinate of the vector. |
Fields
View SourceW
W coordinate of the vector.
Declaration
public float W
Field Value
Type | Description |
---|---|
System.Single |
X
X coordinate of the vector.
Declaration
public float X
Field Value
Type | Description |
---|---|
System.Single |
Y
Y coordinate of the vector.
Declaration
public float Y
Field Value
Type | Description |
---|---|
System.Single |
Z
Z coordinate of the vector.
Declaration
public float Z
Field Value
Type | Description |
---|---|
System.Single |
Properties
View SourceMax
Returns maximum value of the vector.
Declaration
public readonly float Max { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
Returns maximum value of all 4 vector's coordinates.
MaxIndex
Returns index of the coordinate with maximum value.
Declaration
public readonly int MaxIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
Returns index of the coordinate, which has the maximum value - 0 for X, 1 for Y, 2 for Z or 3 for W.
note
If there are multiple coordinates which have the same maximum value, the property returns smallest index.
Min
Returns minimum value of the vector.
Declaration
public readonly float Min { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
Returns minimum value of all 4 vector's coordinates.
MinIndex
Returns index of the coordinate with minimum value.
Declaration
public readonly int MinIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
Returns index of the coordinate, which has the minimum value - 0 for X, 1 for Y, 2 for Z or 3 for W.
note
If there are multiple coordinates which have the same minimum value, the property returns smallest index.
Norm
Returns vector's norm.
Declaration
public readonly float Norm { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
Returns Euclidean norm of the vector, which is a square root of the sum: X2+Y2+Z2+W2.
Square
Returns square of the vector's norm.
Declaration
public readonly float Square { get; }
Property Value
Type | Description |
---|---|
System.Single |
Remarks
Return X2+Y2+Z2+W2, which is a square of vector's norm or a dot product of this vector with itself.
Methods
View SourceAbs()
Calculate absolute values of the vector.
Declaration
public Vector4 Abs()
Returns
Type | Description |
---|---|
Vector4 | Returns a vector with all coordinates equal to absolute values of this vector's coordinates. |
Add(Vector4, Vector4)
Adds corresponding coordinates of two vectors.
Declaration
public static Vector4 Add(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The vector to add to. |
Vector4 | vector2 | The vector to add to the first vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to sum of corresponding coordinates of the two specified vectors. |
Add(Vector4, Single)
Adds a value to all coordinates of the specified vector.
Declaration
public static Vector4 Add(Vector4 vector, float value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to add the specified value to. |
System.Single | value | Value to add to all coordinates of the vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates increased by the specified value. |
Divide(Vector4, Vector4)
Divides corresponding coordinates of two vectors.
Declaration
public static Vector4 Divide(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The first vector to divide. |
Vector4 | vector2 | The second vector to devide. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to coordinates of the first vector divided by corresponding coordinates of the second vector. |
Divide(Vector4, Single)
Divides coordinates of the specified vector by the specified factor.
Declaration
public static Vector4 Divide(Vector4 vector, float factor)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to divide coordinates of. |
System.Single | factor | Factor to divide coordinates of the specified vector by. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates divided by the specified factor. |
Dot(Vector4, Vector4)
Calculates dot product of two vectors.
Declaration
public static float Dot(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | First vector to use for dot product calculation. |
Vector4 | vector2 | Second vector to use for dot product calculation. |
Returns
Type | Description |
---|---|
System.Single | Returns dot product of the two specified vectors. |
Equals(Vector4)
Tests whether the vector equals to the specified one.
Declaration
public bool Equals(Vector4 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | The vector to test equality with. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two vectors are equal or false otherwise. |
Equals(Object)
Tests whether the vector equals to the specified object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to test equality with. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the vector equals to the specified object or false otherwise. |
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer hash code. |
Inverse()
Inverse the vector.
Declaration
public Vector4 Inverse()
Returns
Type | Description |
---|---|
Vector4 | Returns a vector with all coordinates equal to 1.0 divided by the value of corresponding coordinate in this vector (or equal to 0.0 if this vector has corresponding coordinate also set to 0.0). |
Multiply(Vector4, Vector4)
Multiplies corresponding coordinates of two vectors.
Declaration
public static Vector4 Multiply(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The first vector to multiply. |
Vector4 | vector2 | The second vector to multiply. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to multiplication of corresponding coordinates of the two specified vectors. |
Multiply(Vector4, Single)
Multiplies coordinates of the specified vector by the specified factor.
Declaration
public static Vector4 Multiply(Vector4 vector, float factor)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to multiply coordinates of. |
System.Single | factor | Factor to multiple coordinates of the specified vector by. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates multiplied by the specified factor. |
Normalize()
Normalizes the vector by dividing it’s all coordinates with the vector's norm.
Declaration
public float Normalize()
Returns
Type | Description |
---|---|
System.Single | Returns the value of vectors’ norm before normalization. |
Subtract(Vector4, Vector4)
Subtracts corresponding coordinates of two vectors.
Declaration
public static Vector4 Subtract(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The vector to subtract from. |
Vector4 | vector2 | The vector to subtract from the first vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to difference of corresponding coordinates of the two specified vectors. |
Subtract(Vector4, Single)
Subtracts a value from all coordinates of the specified vector.
Declaration
public static Vector4 Subtract(Vector4 vector, float value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to subtract the specified value from. |
System.Single | value | Value to subtract from all coordinates of the vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates decreased by the specified value. |
ToArray()
Returns array representation of the vector.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
System.Single[] | Array with 4 values containing X/Y/Z/W coordinates. |
ToString()
Returns a string representation of this object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of this object. |
ToVector3()
Converts the vector to a 3D vector.
Declaration
public Vector3 ToVector3()
Returns
Type | Description |
---|---|
Vector3 | Returns 3D vector which has X/Y/Z coordinates equal to X/Y/Z coordinates of this vector divided by W. |
Operators
View SourceAddition(Vector4, Vector4)
Adds corresponding coordinates of two vectors.
Declaration
public static Vector4 operator +(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The vector to add to. |
Vector4 | vector2 | The vector to add to the first vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to sum of corresponding coordinates of the two specified vectors. |
Addition(Vector4, Single)
Adds a value to all coordinates of the specified vector.
Declaration
public static Vector4 operator +(Vector4 vector, float value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to add the specified value to. |
System.Single | value | Value to add to all coordinates of the vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates increased by the specified value. |
Division(Vector4, Vector4)
Divides corresponding coordinates of two vectors.
Declaration
public static Vector4 operator /(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The first vector to divide. |
Vector4 | vector2 | The second vector to devide. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to coordinates of the first vector divided by corresponding coordinates of the second vector. |
Division(Vector4, Single)
Divides coordinates of the specified vector by the specified factor.
Declaration
public static Vector4 operator /(Vector4 vector, float factor)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to divide coordinates of. |
System.Single | factor | Factor to divide coordinates of the specified vector by. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates divided by the specified factor. |
Equality(Vector4, Vector4)
Tests whether two specified vectors are equal.
Declaration
public static bool operator ==(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The left-hand vector. |
Vector4 | vector2 | The right-hand vector. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two vectors are equal or false otherwise. |
Inequality(Vector4, Vector4)
Tests whether two specified vectors are not equal.
Declaration
public static bool operator !=(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The left-hand vector. |
Vector4 | vector2 | The right-hand vector. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the two vectors are not equal or false otherwise. |
Multiply(Vector4, Vector4)
Multiplies corresponding coordinates of two vectors.
Declaration
public static Vector4 operator *(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The first vector to multiply. |
Vector4 | vector2 | The second vector to multiply. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to multiplication of corresponding coordinates of the two specified vectors. |
Multiply(Vector4, Single)
Multiplies coordinates of the specified vector by the specified factor.
Declaration
public static Vector4 operator *(Vector4 vector, float factor)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to multiply coordinates of. |
System.Single | factor | Factor to multiple coordinates of the specified vector by. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates multiplied by the specified factor. |
Subtraction(Vector4, Vector4)
Subtracts corresponding coordinates of two vectors.
Declaration
public static Vector4 operator -(Vector4 vector1, Vector4 vector2)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector1 | The vector to subtract from. |
Vector4 | vector2 | The vector to subtract from the first vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns a vector which coordinates are equal to difference of corresponding coordinates of the two specified vectors. |
Subtraction(Vector4, Single)
Subtracts a value from all coordinates of the specified vector.
Declaration
public static Vector4 operator -(Vector4 vector, float value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector | Vector to subtract the specified value from. |
System.Single | value | Value to subtract from all coordinates of the vector. |
Returns
Type | Description |
---|---|
Vector4 | Returns new vector with all coordinates decreased by the specified value. |