32using System.Runtime.InteropServices;
34using System.Xml.Serialization;
43 [StructLayout(LayoutKind.Sequential, Size = Vector2D.Size)]
44 [AdvBrowsableOrder(
"X,Y")]
45#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
61 #region readonly fields
87 #region static methods
90 Copy(ref vector, destArray, 0);
96 destArray[index] = vector.X;
97 destArray[++index] = vector.Y;
101 Copy(sourceArray, 0, out result);
107 result.X = sourceArray[index];
108 result.Y = sourceArray[++index];
144 Lerp(ref left, ref right, ref amount, out result);
149 result.X = (right.X - left.X) * amount + left.X;
150 result.Y = (right.Y - left.Y) * amount + left.Y;
155 Lerp(ref left, ref right, ref amount, out result);
160 result.X = (right.X - left.X) * amount.X + left.X;
161 result.Y = (right.Y - left.Y) * amount.Y + left.Y;
167 x = left.
X - right.
X;
168 y = left.
Y - right.
Y;
174 x = left.X - right.X;
175 y = left.Y - right.Y;
181 x = left.
X - right.
X;
182 y = left.
Y - right.
Y;
183 return x * x + y * y;
188 x = left.X - right.X;
189 y = left.Y - right.Y;
190 result = x * x + y * y;
226 Scalar negradianAngle = -radianAngle;
230 result.
X = source.
X * cos + source.
Y * sin;
231 result.
Y = source.
Y * cos - source.
X * sin;
236 Scalar negradianAngle = -radianAngle;
239 result.X = source.X * cos + source.Y * sin;
240 result.Y = source.Y * cos - source.X * sin;
290 result.
X = left.
X + right.
X;
291 result.
Y = left.
Y + right.
Y;
296 result.X = left.X + right.X;
297 result.Y = left.Y + right.Y;
309 result.
X = left.
X - right.
X;
310 result.
Y = left.
Y - right.
Y;
315 result.X = left.X - right.X;
316 result.Y = left.Y - right.Y;
327 Scalar inverseZ = 1 / (source.
X * matrix.
m20 + source.
Y * matrix.
m21 + matrix.
m22);
329 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01 + matrix.
m02) * inverseZ;
330 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11 + matrix.
m12) * inverseZ;
336 Scalar inverseZ = 1 / (
X * matrix.m20 + source.Y * matrix.m21 + matrix.m22);
337 result.X = (
X * matrix.m00 + source.Y * matrix.m01 + matrix.m02) * inverseZ;
338 result.Y = (
X * matrix.m10 + source.Y * matrix.m11 + matrix.m12) * inverseZ;
343 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01);
344 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11);
350 result.X = (
X * matrix.m00 + source.Y * matrix.m01);
351 result.Y = (
X * matrix.m10 + source.Y * matrix.m11);
363 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01 + matrix.
m02);
364 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11 + matrix.
m12);
370 result.X = (
X * matrix.m00 + source.Y * matrix.m01 + matrix.m02);
371 result.Y = (
X * matrix.m10 + source.Y * matrix.m11 + matrix.m12);
376 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01);
377 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11);
383 result.X = (
X * matrix.m00 + source.Y * matrix.m01);
384 result.Y = (
X * matrix.m10 + source.Y * matrix.m11);
396 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01);
397 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11);
403 result.X = (
X * matrix.m00 + source.Y * matrix.m01);
404 result.Y = (
X * matrix.m10 + source.Y * matrix.m11);
416 result.
X = source.
X * scalar;
417 result.
Y = source.
Y * scalar;
422 result.X = source.X * scalar;
423 result.Y = source.Y * scalar;
429 result.
X = scalar * source.
X;
430 result.
Y = scalar * source.
Y;
435 result.X = scalar * source.X;
436 result.Y = scalar * source.Y;
447 return left.
Y * right.
Y + left.
X * right.
X;
451 result = left.X * right.X + left.Y * right.Y;
473 return left.
X * right.
Y - left.
Y * right.
X;
477 result = left.X * right.Y - left.Y * right.X;
500 result.
X = -leftZ * right.
Y;
501 result.
Y = leftZ * right.
X;
507 result.X = -leftZ * right.Y;
508 result.Y = leftZ * rightX;
531 result.
X = left.
Y * rightZ;
532 result.
Y = -left.
X * rightZ;
538 result.X = left.Y * rightZ;
539 result.Y = -leftX * rightZ;
548 return source.
X * source.
X + source.
Y * source.
Y;
552 result = source.X * source.X + source.Y * source.Y;
565 result =
MathHelper.
Sqrt(source.X * source.X + source.Y * source.Y);
581 if (magnitude == 0) { result =
Zero;
return; }
583 if (oldmagnitude == 0) { result =
Zero;
return; }
584 oldmagnitude = (magnitude / oldmagnitude);
585 result.
X = source.X * oldmagnitude;
586 result.Y = source.Y * oldmagnitude;
596 result.
X = -source.
X;
597 result.
Y = -source.
Y;
602 Negate(ref source, out source);
606 result.X = -source.X;
607 result.Y = -source.Y;
620 oldmagnitude = (1 / oldmagnitude);
622 result.
X = source.
X * oldmagnitude;
623 result.
Y = source.
Y * oldmagnitude;
630 if (oldmagnitude == 0) { result =
Zero;
return; }
631 oldmagnitude = (1 / oldmagnitude);
632 result.
X = source.X * oldmagnitude;
633 result.Y = source.Y * oldmagnitude;
649 Normalize(ref source, out magnitude, out result);
657 Scalar magnitudeInv = (1 / magnitude);
658 result.X = source.X * magnitudeInv;
659 result.Y = source.Y * magnitudeInv;
676 Project(ref left, ref right, out result);
682 Dot(ref left, ref right, out tmp);
685 Multiply(ref right, ref tmp, out result);
696 result.
X = -source.
Y;
702 Scalar sourceX = source.X;
703 result.X = -source.Y;
716 result.
Y = -source.
X;
721 Scalar sourceX = source.X;
729 Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
736 result.X = h1 * value1.X + h2 * value2.X + h3 * tangent1.X + h4 * tangent2.X;
737 result.Y = h1 * value1.Y + h2 * value2.Y + h3 * tangent1.Y + h4 * tangent2.Y;
743 CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
748 Scalar amountSq = amount * amount;
749 Scalar amountCu = amountSq * amount;
751 0.5f * ((2 * value2.X) +
752 (-value1.X + value3.X) * amount +
753 (2 * value1.X - 5 * value2.X + 4 * value3.X - value4.X) * amountSq +
754 (-value1.X + 3 * value2.X - 3 * value3.X + value4.X) * amountCu);
756 0.5f * ((2 * value2.Y) +
757 (-value1.Y + value3.Y) * amount +
758 (2 * value1.Y - 5 * value2.Y + 4 * value3.Y - value4.Y) * amountSq +
759 (-value1.Y + 3 * value2.Y - 3 * value3.Y + value4.Y) * amountCu);
765 Max(ref value1, ref value2, out result);
770 result.X = (value1.X < value2.X) ? (value2.X) : (value1.X);
771 result.Y = (value1.Y < value2.Y) ? (value2.Y) : (value1.Y);
777 Min(ref value1, ref value2, out result);
782 result.X = (value1.X > value2.X) ? (value2.X) : (value1.X);
783 result.Y = (value1.Y > value2.Y) ? (value2.Y) : (value1.Y);
794 [
System.ComponentModel.Description(
"The Magnitude on the X-Axis")]
803 [
System.ComponentModel.Description(
"The Magnitude on the Y-Axis")]
813 [InstanceConstructor(
"X,Y")]
822 Copy(vals, index, out
this);
834 public Scalar this[
int index]
841 fixed (
Scalar* ptr = &this.X)
849 ThrowHelper.CheckIndex(
"index", index,
Count);
852 fixed (
Scalar* ptr = &this.X)
861 #region public properties
907 return this.X * this.X + this.Y * this.
Y;
928 SetAngle(ref
this, ref value, out
this);
947 #region public methods
951 Copy(ref
this, array, 0);
956 Copy(array, index, out
this);
960 Copy(ref
this, array, index);
982 result.
X = left.
X + right.
X;
983 result.
Y = left.
Y + right.
Y;
996 result.
X = left.
X - right.
X;
997 result.
Y = left.
Y - right.
Y;
1010 result.
X = source.
X * scalar;
1011 result.
Y = source.
Y * scalar;
1024 result.
X = scalar * source.
X;
1025 result.
Y = scalar * source.
Y;
1037 return left.
Y * right.
Y + left.
X * right.
X;
1042 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01 + matrix.
m02);
1043 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11 + matrix.
m12);
1048 Scalar inverseZ = 1 / (source.
X * matrix.
m20 + source.
Y * matrix.
m21 + matrix.
m22);
1050 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01 + matrix.
m02) * inverseZ;
1051 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11 + matrix.
m12) * inverseZ;
1057 result.
X = (source.
X * matrix.
m00 + source.
Y * matrix.
m01);
1058 result.
Y = (source.
X * matrix.
m10 + source.
Y * matrix.
m11);
1069 result.
X = -source.
X;
1070 result.
Y = -source.
Y;
1093 return left.
X * right.
Y - left.
Y * right.
X;
1116 result.
X = -leftZ * right.
Y;
1117 result.
Y = leftZ * right.
X;
1141 result.
X = left.
Y * rightZ;
1142 result.
Y = -left.
X * rightZ;
1153 return left.
X == right.
X && left.
Y == right.
Y;
1163 return !(left.
X == right.
X && left.
Y == right.
Y);
1171 result.
X = source.
X;
1172 result.
Y = source.
Y;
1196#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT
1205 if (vals.Length !=
Count)
1210 if (
Scalar.TryParse(vals[0], out result.X) &&
1211 Scalar.TryParse(vals[1], out result.Y))
1227 throw new ArgumentNullException(
"s");
1230 if (vals.Length !=
Count)
1235 value.
X =
Scalar.Parse(vals[0]);
1236 value.
Y =
Scalar.Parse(vals[1]);
1251 return X.GetHashCode() ^
Y.GetHashCode();
1265 return Equals(ref
this, ref other);
1270 left.
X == right.
X &&
1276 left.X == right.X &&
static Scalar Clamp(Scalar value, Scalar min, Scalar max)
static Scalar Cos(Scalar d)
static Scalar Atan2(Scalar y, Scalar x)
static Scalar Sin(Scalar a)
static Scalar Sqrt(Scalar d)
static void HermiteHelper(Scalar amount, out Scalar h1, out Scalar h2, out Scalar h3, out Scalar h4)
static string CreateVectorFormatableString(int Count)
static string CreateVectorFormatString(int Count)
static string[] SplitStringVector(string s)
static void ThrowVectorFormatException(string value, int count, string format)
static void CheckCopy(Scalar[] array, int index, int count)
int Count
Gets a 32-bit integer that represents the total number of elements in all the dimensions of IAdvanceV...
A 2x2 matrix which can represent rotations for 2D vectors.
A 2x3 matrix which can represent rotations around axes.
A 3x3 matrix which can represent rotations around axes.
This is the Vector Class.
static readonly Vector2D Zero
Vector2D(0,0)
static void Project(ref Vector2D left, ref Vector2D right, out Vector2D result)
static void Normalize(ref Vector2D source)
static Vector2D operator+(Vector2D left, Vector2D right)
Adds 2 Vectors2Ds.
static void TransformNormal(ref Matrix3x3 matrix, ref Vector2D source, out Vector2D result)
static void Lerp(ref Vector2D left, ref Vector2D right, ref Vector2D amount, out Vector2D result)
static void Clamp(ref Vector2D value, ref Vector2D min, ref Vector2D max, out Vector2D result)
static void CatmullRom(ref Vector2D value1, ref Vector2D value2, ref Vector2D value3, ref Vector2D value4, Scalar amount, out Vector2D result)
override string ToString()
static Vector2D Add(Vector2D left, Vector2D right)
Adds 2 Vectors2Ds.
static Vector2D Negate(Vector2D source)
Negates a Vector2D.
static void Max(ref Vector2D value1, ref Vector2D value2, out Vector2D result)
int IAdvanceValueType. Count
The Number of Variables accesable though the indexer.
static Vector2D Hermite(Vector2D value1, Vector2D tangent1, Vector2D value2, Vector2D tangent2, Scalar amount)
static Vector2D Normalize(Vector2D source, out Scalar magnitude)
This returns the Normalized Vector2D that is passed. This is also known as a Unit Vector.
static Vector2D GetRightHandNormal(Vector2D source)
Gets a Vector2D that is perpendicular(orthogonal) to the passed Vector2D while staying on the XY Plan...
static Vector2D Multiply(Vector2D source, Scalar scalar)
Does Scaler Multiplication on a Vector2D.
static void Copy(ref Vector2D vector, Scalar[] destArray)
const int Size
The Size of the class in bytes;
static void ZCross(ref Scalar leftZ, ref Vector2D right, out Vector2D result)
static Scalar Distance(Vector2D left, Vector2D right)
Scalar Magnitude
Gets or Sets the Magnitude (Length) of the Vector2D.
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
static Vector2D Transform(Matrix3x3 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
void CopyTo(Scalar[] array, int index)
static void SetMagnitude(ref Vector2D source, ref Scalar magnitude, out Vector2D result)
string ToStringInternal(string FormatString)
static Vector2D Multiply(Scalar scalar, Vector2D source)
static void SetAngle(ref Vector2D source, ref Scalar radianAngle, out Vector2D result)
static Scalar Dot(Vector2D left, Vector2D right)
Does a Dot Operation Also know as an Inner Product.
static Vector2D Transform(Matrix2x3 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
static Vector2D ZCross(Vector2D left, Scalar rightZ)
Does a "2D" Cross Product also know as an Outer Product.
static Vector2D Clamp(Vector2D value, Vector2D min, Vector2D max)
Binds a value to
static void Lerp(ref Vector2D left, ref Vector2D right, ref Scalar amount, out Vector2D result)
const int Count
The number of Scalar values in the class.
static Scalar operator^(Vector2D left, Vector2D right)
Does a "2D" Cross Product also know as an Outer Product.
static readonly string FormatableString
string ToString(string format)
Converts the numeric value of this instance to its equivalent string representation,...
static Vector2D Normalize(Vector2D source)
This returns the Normalized Vector2D that is passed. This is also known as a Unit Vector.
void CopyFrom(Scalar[] array, int index)
bool Equals(Vector2D other)
static readonly Vector2D XAxis
Vector2D(1,0)
static Vector2D operator-(Vector2D left, Vector2D right)
Subtracts 2 Vector2Ds.
static Vector2D Project(Vector2D left, Vector2D right)
Thie Projects the left Vector2D onto the Right Vector2D.
Vector2D Normalized
Gets the Normalized Vector2D. (Unit Vector)
static Vector2D FromLengthAndAngle(Scalar length, Scalar radianAngle)
Creates a Vector2D With the given length (Magnitude) and the given Angle.
static Vector2D SetAngle(Vector2D source, Scalar radianAngle)
Sets the Angle of a Vector2D without changing the Magnitude.
static void FromLengthAndAngle(ref Scalar length, ref Scalar radianAngle, out Vector2D result)
static readonly string FormatString
static void Copy(Scalar[] sourceArray, int index, out Vector2D result)
static void Subtract(ref Vector2D left, ref Vector2D right, out Vector2D result)
static void Copy(Scalar[] sourceArray, out Vector2D result)
static Vector2D TransformNormal(Matrix3x3 matrix, Vector2D source)
Vector2D RightHandNormal
Gets A perpendicular(orthogonal) Vector2D using the Right Hand Rule.
static Scalar DistanceSq(Vector2D left, Vector2D right)
static Vector2D Lerp(Vector2D left, Vector2D right, Vector2D amount)
static bool Equals(ref Vector2D left, ref Vector2D right)
static void Distance(ref Vector2D left, ref Vector2D right, out Scalar result)
Scalar MagnitudeSq
Gets the Squared Magnitude of the Vector2D.
static void Transform(ref Matrix3x3 matrix, ref Vector2D source, out Vector2D result)
static bool Equals(Vector2D left, Vector2D right)
static Vector2D GetLeftHandNormal(Vector2D source)
Gets a Vector2D that is perpendicular(orthogonal) to the passed Vector2D while staying on the XY Plan...
override int GetHashCode()
Provides a unique hash code based on the member variables of this class. This should be done because ...
static Vector2D Subtract(Vector2D left, Vector2D right)
Subtracts 2 Vector2Ds.
static void GetMagnitude(ref Vector2D source, out Scalar result)
static void Rotate(ref Scalar radianAngle, ref Vector2D source, out Vector2D result)
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
override bool Equals(object obj)
Compares this Vector to another object. This should be done because the equality operators (==,...
static void Min(ref Vector2D value1, ref Vector2D value2, out Vector2D result)
static void GetMagnitudeSq(ref Vector2D source, out Scalar result)
static void Multiply(ref Scalar scalar, ref Vector2D source, out Vector2D result)
static Scalar GetAngle(Vector2D source)
Determines the current Angle in radians of the Vector2D and Returns it.
static void Transform(ref Matrix2x2 matrix, ref Vector2D source, out Vector2D result)
Scalar Angle
Gets or Sets the Angle in radians of the Vector2D.
static Scalar GetMagnitudeSq(Vector2D source)
Gets the Squared Magnitude of the Vector2D that is passed.
static Vector2D ZCross(Scalar leftZ, Vector2D right)
Does a "2D" Cross Product also know as an Outer Product.
static bool TryParse(string s, out Vector2D result)
static Vector2D Transform(Matrix2x2 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
static Vector2D TransformNormal(Matrix2x3 matrix, Vector2D source)
static Vector2D CatmullRom(Vector2D value1, Vector2D value2, Vector2D value3, Vector2D value4, Scalar amount)
static void Copy(ref Vector2D vector, Scalar[] destArray, int index)
static Vector2D operator*(Vector2D source, Scalar scalar)
Does Scaler Multiplication on a Vector2D.
Vector2D(Scalar[] vals, int index)
Vector3D ToVector3D(Scalar Z)
static void GetRightHandNormal(ref Vector2D source, out Vector2D result)
static void Add(ref Vector2D left, ref Vector2D right, out Vector2D result)
static void TransformNormal(ref Matrix2x3 matrix, ref Vector2D source, out Vector2D result)
static void Transform(ref Matrix2x3 matrix, ref Vector2D source, out Vector2D result)
static readonly Vector2D One
Vector2D(1,1)
static readonly Vector2D XYAxis
Vector2D(0.707...,0.707...)
static Vector2D Max(Vector2D value1, Vector2D value2)
static Vector2D Min(Vector2D value1, Vector2D value2)
static void Negate(ref Vector2D source)
static void ZCross(ref Vector2D left, ref Scalar rightZ, out Vector2D result)
static void Hermite(ref Vector2D value1, ref Vector2D tangent1, ref Vector2D value2, ref Vector2D tangent2, Scalar amount, out Vector2D result)
Vector2D LeftHandNormal
Gets A perpendicular(orthogonal) Vector2D using the Left Hand Rule.
static Vector2D Parse(string s)
static void Copy(ref Vector4D source, out Vector2D dest)
static Scalar GetMagnitude(Vector2D source)
Gets the Magnitude of the Vector2D that is passed.
static Vector2D Rotate(Scalar radianAngle, Vector2D source)
Rotates a Vector2D.
static readonly Vector2D YAxis
Vector2D(0,1)
static void Multiply(ref Vector2D source, ref Scalar scalar, out Vector2D result)
static void GetAngle(ref Vector2D source, out Scalar result)
static bool operator!=(Vector2D left, Vector2D right)
Specifies whether the Vector2Ds do not contain the same coordinates.
static Scalar ZCross(Vector2D left, Vector2D right)
Does a "2D" Cross Product also know as an Outer Product.
static bool operator==(Vector2D left, Vector2D right)
Specifies whether the Vector2Ds contain the same coordinates.
static void GetLeftHandNormal(ref Vector2D source, out Vector2D result)
static void Negate(ref Vector2D source, out Vector2D result)
static void Normalize(ref Vector2D source, out Vector2D result)
static void DistanceSq(ref Vector2D left, ref Vector2D right, out Scalar result)
static void Normalize(ref Vector2D source, out Scalar magnitude, out Vector2D result)
static Vector2D SetMagnitude(Vector2D source, Scalar magnitude)
Sets the Magnitude of a Vector2D without changing the Angle.
static void ZCross(ref Vector2D left, ref Vector2D right, out Scalar result)
Vector2D(Scalar X, Scalar Y)
Creates a New Vector2D Instance on the Stack.
static void Dot(ref Vector2D left, ref Vector2D right, out Scalar result)
static void Copy(ref Vector3D source, out Vector2D dest)
static Vector2D Lerp(Vector2D left, Vector2D right, Scalar amount)
A Vector with 3 dimensions.
Scalar X
This is the X value.
Scalar Y
This is the Y value.
Scalar Z
This is the Z value.
A Vector with 4 dimensions.