Jypeli 10
The simple game programming library
Matrix2x2.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26
27
28#if UseDouble
29using Scalar = System.Double;
30#else
31using Scalar = System.Single;
32#endif
33using System;
34using System.Runtime.InteropServices;
36using System.Xml.Serialization;
37
38
39// NOTE. The (x,y) coordinate system is assumed to be right-handed.
40// where t > 0 indicates a counterclockwise rotation in the zx-plane
41// RZ = cos(t) -sin(t)
42// sin(t) cos(t)
43// where t > 0 indicates a counterclockwise rotation in the xy-plane.
44
45namespace AdvanceMath
46{
47
51 [StructLayout(LayoutKind.Sequential, Size = Matrix2x2.Size)]
52 [AdvBrowsableOrder("Rx,Ry")]
53#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
54 [Serializable]
55 [System.ComponentModel.TypeConverter(typeof(AdvTypeConverter<Matrix2x2>))]
56#endif
57 public struct Matrix2x2 : IMatrix<Matrix2x2, Vector2D, Vector2D>
58 {
59 #region const fields
63 public const int RowCount = 2;
67 public const int ColumnCount = 2;
71 public const int Count = RowCount * ColumnCount;
75 public const int Size = sizeof(Scalar) * Count;
76 #endregion
77 #region static fields
80
81 public static readonly Matrix2x2 Identity = new Matrix2x2(
82 1, 0,
83 0, 1);
84 public static readonly Matrix2x2 Zero = new Matrix2x2(
85 0, 0,
86 0, 0);
87
88 #endregion
89 #region static methods
90 public static void Copy(ref Matrix2x2 matrix, Scalar[] destArray)
91 {
92 Copy(ref matrix, destArray, 0);
93 }
94 public static void Copy(ref Matrix2x2 matrix, Scalar[] destArray, int index)
95 {
96 ThrowHelper.CheckCopy(destArray, index, Count);
97
98 destArray[index] = matrix.m00;
99 destArray[++index] = matrix.m01;
100
101 destArray[++index] = matrix.m10;
102 destArray[++index] = matrix.m11;
103 }
104 public static void Copy(Scalar[] sourceArray, out Matrix2x2 result)
105 {
106 Copy(sourceArray, 0, out result);
107 }
108 public static void Copy(Scalar[] sourceArray, int index, out Matrix2x2 result)
109 {
110 ThrowHelper.CheckCopy(sourceArray, index, Count);
111
112 result.m00 = sourceArray[index];
113 result.m01 = sourceArray[++index];
114
115 result.m10 = sourceArray[++index];
116 result.m11 = sourceArray[++index];
117 }
118 public static void CopyTranspose(ref Matrix2x2 matrix, Scalar[] destArray)
119 {
120 CopyTranspose(ref matrix, destArray, 0);
121 }
122 public static void CopyTranspose(ref Matrix2x2 matrix, Scalar[] destArray, int index)
123 {
124 ThrowHelper.CheckCopy(destArray, index, Count);
125
126 destArray[index] = matrix.m00;
127 destArray[++index] = matrix.m10;
128
129 destArray[++index] = matrix.m01;
130 destArray[++index] = matrix.m11;
131 }
132 public static void CopyTranspose(Scalar[] sourceArray, out Matrix2x2 result)
133 {
134 CopyTranspose(sourceArray, 0, out result);
135 }
136 public static void CopyTranspose(Scalar[] sourceArray, int index, out Matrix2x2 result)
137 {
138 ThrowHelper.CheckCopy(sourceArray, index, Count);
139
140 result.m00 = sourceArray[index];
141 result.m10 = sourceArray[++index];
142
143 result.m01 = sourceArray[++index];
144 result.m11 = sourceArray[++index];
145 }
146
147 public static void Copy(ref Matrix4x4 source, out Matrix2x2 dest)
148 {
149 dest.m00 = source.m00;
150 dest.m01 = source.m01;
151
152 dest.m10 = source.m10;
153 dest.m11 = source.m11;
154 }
155 public static void Copy(ref Matrix3x3 source, out Matrix2x2 dest)
156 {
157 dest.m00 = source.m00;
158 dest.m01 = source.m01;
159
160 dest.m10 = source.m10;
161 dest.m11 = source.m11;
162 }
163 public static void Copy(ref Matrix2x3 source, out Matrix2x2 dest)
164 {
165 dest.m00 = source.m00;
166 dest.m01 = source.m01;
167
168 dest.m10 = source.m10;
169 dest.m11 = source.m11;
170 }
171
172 public static Matrix2x2 Lerp(Matrix2x2 left, Matrix2x2 right, Scalar amount)
173 {
174 Matrix2x2 result;
175 Lerp(ref left, ref right, ref amount, out result);
176 return result;
177 }
178 public static void Lerp(ref Matrix2x2 left, ref Matrix2x2 right, ref Scalar amount, out Matrix2x2 result)
179 {
180 result.m00 = (right.m00 - left.m00) * amount + left.m00;
181 result.m01 = (right.m01 - left.m01) * amount + left.m01;
182
183 result.m10 = (right.m10 - left.m10) * amount + left.m10;
184 result.m11 = (right.m11 - left.m11) * amount + left.m11;
185 }
186
193 public static Matrix2x2 Multiply(Matrix2x2 left, Matrix2x2 right)
194 {
195 Matrix2x2 result;
196
197 result.m00 = left.m00 * right.m00 + left.m01 * right.m10;
198 result.m01 = left.m00 * right.m01 + left.m01 * right.m11;
199
200 result.m10 = left.m10 * right.m00 + left.m11 * right.m10;
201 result.m11 = left.m10 * right.m01 + left.m11 * right.m11;
202
203 return result;
204 }
205 public static void Multiply(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
206 {
207 Scalar m00 = left.m00 * right.m00 + left.m01 * right.m10;
208 Scalar m01 = left.m00 * right.m01 + left.m01 * right.m11;
209
210 Scalar m10 = left.m10 * right.m00 + left.m11 * right.m10;
211 Scalar m11 = left.m10 * right.m01 + left.m11 * right.m11;
212
213 result.m00 = m00;
214 result.m01 = m01;
215
216 result.m10 = m10;
217 result.m11 = m11;
218
219 }
220
227 public static Matrix2x2 Multiply(Matrix2x2 left, Scalar scalar)
228 {
229 Matrix2x2 result;
230
231 result.m00 = left.m00 * scalar;
232 result.m01 = left.m01 * scalar;
233
234 result.m10 = left.m10 * scalar;
235 result.m11 = left.m11 * scalar;
236
237 return result;
238 }
239 public static void Multiply(ref Matrix2x2 left, ref Scalar scalar, out Matrix2x2 result)
240 {
241 result.m00 = left.m00 * scalar;
242 result.m01 = left.m01 * scalar;
243
244 result.m10 = left.m10 * scalar;
245 result.m11 = left.m11 * scalar;
246 }
247
254 public static Matrix2x2 Add(Matrix2x2 left, Matrix2x2 right)
255 {
256 Matrix2x2 result;
257
258 result.m00 = left.m00 + right.m00;
259 result.m01 = left.m01 + right.m01;
260
261 result.m10 = left.m10 + right.m10;
262 result.m11 = left.m11 + right.m11;
263
264 return result;
265 }
266 public static void Add(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
267 {
268 result.m00 = left.m00 + right.m00;
269 result.m01 = left.m01 + right.m01;
270
271 result.m10 = left.m10 + right.m10;
272 result.m11 = left.m11 + right.m11;
273 }
280 public static Matrix2x2 Subtract(Matrix2x2 left, Matrix2x2 right)
281 {
282 Matrix2x2 result;
283
284 result.m00 = left.m00 - right.m00;
285 result.m01 = left.m01 - right.m01;
286
287 result.m10 = left.m10 - right.m10;
288 result.m11 = left.m11 - right.m11;
289
290 return result;
291 }
292 public static void Subtract(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
293 {
294 result.m00 = left.m00 - right.m00;
295 result.m01 = left.m01 - right.m01;
296
297 result.m10 = left.m10 - right.m10;
298 result.m11 = left.m11 - right.m11;
299 }
300
305 public static Matrix2x2 Negate(Matrix2x2 source)
306 {
307 Matrix2x2 result;
308
309 result.m00 = -source.m00;
310 result.m01 = -source.m01;
311
312 result.m10 = -source.m10;
313 result.m11 = -source.m11;
314
315 return result;
316 }
317
318 public static void Negate(ref Matrix2x2 source)
319 {
320 Negate(ref source, out source);
321 }
322 public static void Negate(ref Matrix2x2 source, out Matrix2x2 result)
323 {
324 result.m00 = -source.m00;
325 result.m01 = -source.m01;
326
327 result.m10 = -source.m10;
328 result.m11 = -source.m11;
329 }
330
331 public static Matrix2x2 Invert(Matrix2x2 source)
332 {
333 Matrix2x2 result;
334 Invert(ref source, out result);
335 return result;
336 }
337 public static void Invert(ref Matrix2x2 source, out Matrix2x2 result)
338 {
339 Scalar m11 = source.m11;
340 Scalar detInv = 1 / (source.m00 * m11 - source.m01 * source.m10);
341 result.m01 = detInv * -source.m01;
342 result.m11 = detInv * source.m00;
343 result.m00 = detInv * m11;
344 result.m10 = detInv * -source.m10;
345 }
346
347 public static Scalar GetDeterminant(Matrix2x2 source)
348 {
349 Scalar result;
350 GetDeterminant(ref source, out result);
351 return result;
352 }
353 public static void GetDeterminant(ref Matrix2x2 source, out Scalar result)
354 {
355 result = (source.m00 * source.m11 - source.m01 * source.m10);
356 }
357
358 public static Matrix2x2 Transpose(Matrix2x2 source)
359 {
360 Matrix2x2 result;
361 Transpose(ref source, out result);
362 return result;
363 }
364 public static void Transpose(ref Matrix2x2 source, out Matrix2x2 result)
365 {
366 Scalar m01 = source.m01;
367 result.m00 = source.m00;
368 result.m01 = source.m10;
369 result.m10 = m01;
370 result.m11 = source.m11;
371 }
372
373 public static Matrix2x2 GetAdjoint(Matrix2x2 source)
374 {
375 Matrix2x2 result;
376 GetAdjoint(ref source, out result);
377 return result;
378 }
379 public static void GetAdjoint(ref Matrix2x2 source, out Matrix2x2 result)
380 {
381 Scalar m11 = source.m11;
382 result.m01 = -source.m01;
383 result.m11 = source.m00;
384 result.m00 = m11;
385 result.m10 = -source.m10;
386 }
387
388 public static Matrix2x2 GetCofactor(Matrix2x2 source)
389 {
390 Matrix2x2 result;
391 GetCofactor(ref source, out result);
392 return result;
393 }
394 public static void GetCofactor(ref Matrix2x2 source, out Matrix2x2 result)
395 {
396 Scalar m11 = source.m11;
397 result.m01 = source.m01;
398 result.m11 = -source.m00;
399 result.m00 = -m11;
400 result.m10 = source.m10;
401 }
402
403
404
405 public static Matrix2x2 FromArray(Scalar[] array)
406 {
407 Matrix2x2 result;
408 Copy(array, 0, out result);
409 return result;
410 }
411 public static Matrix2x2 FromTransposedArray(Scalar[] array)
412 {
413 Matrix2x2 result;
414 CopyTranspose(array, 0, out result);
415 return result;
416 }
417
418 public static Matrix2x2 FromRotation(Scalar radianAngle)
419 {
420 Matrix2x2 result;
421 result.m00 = MathHelper.Cos(radianAngle);
422 result.m10 = MathHelper.Sin(radianAngle);
423 result.m01 = -result.m10;
424 result.m11 = result.m00;
425 return result;
426 }
427 public static void FromRotation(ref Scalar radianAngle, out Matrix2x2 result)
428 {
429 result.m00 = MathHelper.Cos(radianAngle);
430 result.m10 = MathHelper.Sin(radianAngle);
431 result.m01 = -result.m10;
432 result.m11 = result.m00;
433 }
434
435 public static Matrix2x2 FromScale(Vector2D scale)
436 {
437 Matrix2x2 result;
438 result.m00 = scale.X;
439 result.m11 = scale.Y;
440 result.m01 = 0;
441 result.m10 = 0;
442 return result;
443 }
444 public static void FromScale(ref Vector2D scale, out Matrix2x2 result)
445 {
446 result.m00 = scale.X;
447 result.m11 = scale.Y;
448 result.m01 = 0;
449 result.m10 = 0;
450 }
451
452 [ParseMethod]
453 public static Matrix2x2 Parse(string s)
454 {
455 Matrix2x2 rv = Zero;
456 ParseHelper.ParseMatrix<Matrix2x2>(s, ref rv);
457 return rv;
458 }
459#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT
460 public static bool TryParse(string s, out Matrix2x2 result)
461 {
462 result = Zero;
463 return ParseHelper.TryParseMatrix<Matrix2x2>(s, ref result);
464 }
465#endif
466
467 public static bool Equals(Matrix2x2 left, Matrix2x2 right)
468 {
469 return
470 left.m00 == right.m00 && left.m01 == right.m01 &&
471 left.m10 == right.m10 && left.m11 == right.m11;
472 }
473
474 public static bool Equals(ref Matrix2x2 left, ref Matrix2x2 right)
475 {
476 return
477 left.m00 == right.m00 && left.m01 == right.m01 &&
478 left.m10 == right.m10 && left.m11 == right.m11;
479 }
480
481
482 public static Matrix2x2 CreateNormal(Matrix2x3 source)
483 {
484 Matrix2x2 result;
485 CreateNormal(ref source, out result);
486 return result;
487 }
488 public static void CreateNormal(ref Matrix2x3 source, out Matrix2x2 result)
489 {
490 Scalar detInv = 1 / (source.m00 * source.m11 - source.m01 * source.m10);
491 result.m10 = detInv * -source.m01;
492 result.m11 = detInv * source.m00;
493 result.m00 = detInv * source.m11;
494 result.m01 = detInv * -source.m10;
495 }
496 public static Matrix2x2 CreateNormal(Matrix3x3 source)
497 {
498 Matrix2x2 result;
499 CreateNormal(ref source, out result);
500 return result;
501 }
502 public static void CreateNormal(ref Matrix3x3 source, out Matrix2x2 result)
503 {
504 Scalar detInv = 1 / (source.m00 * source.m11 - source.m01 * source.m10);
505 result.m10 = detInv * -source.m01;
506 result.m11 = detInv * source.m00;
507 result.m00 = detInv * source.m11;
508 result.m01 = detInv * -source.m10;
509 }
510
511 #endregion
512 #region fields
513 // | m00 m01 |
514 // | m10 m11 |
515 [XmlIgnore]
516 public Scalar m00, m01;
517 [XmlIgnore]
518 public Scalar m10, m11;
519 #endregion
520 #region Constructors
521
525 public Matrix2x2(
528 {
529 this.m00 = m00; this.m01 = m01;
530 this.m10 = m10; this.m11 = m11;
531 }
532
538 [InstanceConstructor("Rx,Ry")]
539 public Matrix2x2(Vector2D xAxis, Vector2D yAxis)
540 {
541 m00 = xAxis.X;
542 m01 = xAxis.Y;
543 m10 = yAxis.X;
544 m11 = yAxis.Y;
545 }
546 public Matrix2x2(Scalar[] values) : this(values, 0) { }
547 public Matrix2x2(Scalar[] values, int index)
548 {
549 Copy(values, index, out this);
550 }
551 #endregion
552 #region Properties
553 [XmlIgnore]
555 {
556 get
557 {
558 return new Vector2D(m00, m10);
559 }
560 set
561 {
562 this.m00 = value.X;
563 this.m10 = value.Y;
564 }
565 }
566 [XmlIgnore]
568 {
569 get
570 {
571 return new Vector2D(m01, m11);
572 }
573 set
574 {
575 this.m01 = value.X;
576 this.m11 = value.Y;
577 }
578 }
582 [AdvBrowsable]
583#if !WINDOWS_STOREAPP
584 [System.ComponentModel.Description("The First row of the Matrix2x2")]
585#endif
587 {
588 get
589 {
590 Vector2D value;
591 value.X = m00;
592 value.Y = m01;
593 return value;
594 }
595 set
596 {
597 m00 = value.X;
598 m01 = value.Y;
599 }
600 }
604 [AdvBrowsable]
605#if !WINDOWS_STOREAPP
606 [System.ComponentModel.Description("The Second row of the Matrix2x2")]
607#endif
609 {
610 get
611 {
612 Vector2D value;
613 value.X = m10;
614 value.Y = m11;
615 return value;
616 }
617 set
618 {
619 m10 = value.X;
620 m11 = value.Y;
621 }
622 }
624 {
625 get
626 {
627 Scalar result;
628 GetDeterminant(ref this, out result);
629 return result;
630 }
631 }
637 {
638 get
639 {
640 Matrix2x2 result;
641 Transpose(ref this, out result);
642 return result;
643 }
644 }
646 {
647 get
648 {
649 Matrix2x2 result;
650 GetAdjoint(ref this, out result);
651 return result;
652 }
653 }
655 {
656 get
657 {
658 Matrix2x2 result;
659 GetCofactor(ref this, out result);
660 return result;
661 }
662 }
664 {
665 get
666 {
667 Matrix2x2 result;
668 Invert(ref this, out result);
669 return result;
670 }
671 }
672
673 int IAdvanceValueType.Count { get { return Count; } }
674 int IMatrix.RowCount { get { return RowCount; } }
675 int IMatrix.ColumnCount { get { return ColumnCount; } }
676 #endregion Properties
677 #region Methods
678
679 public Vector2D GetColumn(int columnIndex)
680 {
681 switch (columnIndex)
682 {
683 case 0:
684 return Cx;
685 case 1:
686 return Cy;
687 }
688 throw ThrowHelper.GetThrowIndex("columnIndex", ColumnCount);
689 }
690 public void SetColumn(int columnIndex, Vector2D value)
691 {
692
693 switch (columnIndex)
694 {
695 case 0:
696 Cx = value;
697 return;
698 case 1:
699 Cy = value;
700 return;
701 }
702 throw ThrowHelper.GetThrowIndex("columnIndex", ColumnCount);
703 }
704 public Vector2D GetRow(int rowIndex)
705 {
706 switch (rowIndex)
707 {
708 case 0:
709 return Rx;
710 case 1:
711 return Ry;
712 }
713 throw ThrowHelper.GetThrowIndex("rowIndex", RowCount);
714 }
715 public void SetRow(int rowIndex, Vector2D value)
716 {
717 switch (rowIndex)
718 {
719 case 0:
720 Rx = value;
721 return;
722 case 1:
723 Ry = value;
724 return;
725 }
726 throw ThrowHelper.GetThrowIndex("rowIndex", RowCount);
727 }
728
729
731 {
732 return new Scalar[RowCount, ColumnCount] { { m00, m01 }, { m10, m11 } };
733 }
734 public Scalar[] ToArray()
735 {
736 return new Scalar[Count] { m00, m01, m10, m11 };
737 }
739 {
740 return new Scalar[Count] { m00, m10, m01, m11 };
741 }
742
743
744 public void CopyTo(Scalar[] array, int index)
745 {
746 Copy(ref this, array, index);
747 }
748 public void CopyTransposedTo(Scalar[] array, int index)
749 {
750 CopyTranspose(ref this, array, index);
751 }
752 public void CopyFrom(Scalar[] array, int index)
753 {
754 Copy(array, index, out this);
755 }
756 public void CopyTransposedFrom(Scalar[] array, int index)
757 {
758 CopyTranspose(array, index, out this);
759 }
760
761 private string ToStringInternal(string FormatString)
762 {
763 return string.Format(FormatString,
764 m00, m01,
765 m10, m11);
766 }
767 public string ToString(string format)
768 {
769 return ToStringInternal(string.Format(FormatableString, format));
770 }
771 public override string ToString()
772 {
774 }
775
776 public override int GetHashCode()
777 {
778 return
779 m00.GetHashCode() ^ m01.GetHashCode() ^
780 m10.GetHashCode() ^ m11.GetHashCode();
781 }
782
783 public override bool Equals(object obj)
784 {
785 return
786 (obj is Matrix2x2) &&
787 Equals((Matrix2x2)obj);
788 }
789 public bool Equals(Matrix2x2 other)
790 {
791 return Equals(ref this, ref other);
792 }
793 #endregion
794 #region Indexors
795#if UNSAFE
803 public Scalar this[int rowIndex, int columnIndex]
804 {
805 get
806 {
807 ThrowHelper.CheckIndex("rowIndex", rowIndex, RowCount);
808 ThrowHelper.CheckIndex("columnIndex", columnIndex, ColumnCount);
809 unsafe
810 {
811 fixed (Scalar* pM = &m00)
812 {
813 return pM[(ColumnCount * rowIndex) + columnIndex];
814 }
815 }
816 }
817 set
818 {
819 ThrowHelper.CheckIndex("rowIndex", rowIndex, RowCount);
820 ThrowHelper.CheckIndex("columnIndex", columnIndex, ColumnCount);
821 unsafe
822 {
823 fixed (Scalar* pM = &m00)
824 {
825 pM[(ColumnCount * rowIndex) + columnIndex] = value;
826 }
827 }
828 }
829 }
837 public Scalar this[int index]
838 {
839 get
840 {
841 ThrowHelper.CheckIndex("index", index, Count);
842 unsafe
843 {
844 fixed (Scalar* pMatrix = &this.m00)
845 {
846 return pMatrix[index];
847 }
848 }
849 }
850 set
851 {
852 // System.Runtime.InteropServices.
853 ThrowHelper.CheckIndex("index", index, Count);
854 unsafe
855 {
856 fixed (Scalar* pMatrix = &this.m00)
857 {
858 pMatrix[index] = value;
859 }
860 }
861 }
862 }
863#endif
864 #endregion
865 #region Operator overloads
872 public static Matrix2x2 operator *(Matrix2x2 left, Matrix2x2 right)
873 {
874
875 Matrix2x2 result;
876
877 result.m00 = left.m00 * right.m00 + left.m01 * right.m10;
878 result.m01 = left.m00 * right.m01 + left.m01 * right.m11;
879
880 result.m10 = left.m10 * right.m00 + left.m11 * right.m10;
881 result.m11 = left.m10 * right.m01 + left.m11 * right.m11;
882
883 return result;
884 }
891 public static Matrix2x2 operator +(Matrix2x2 left, Matrix2x2 right)
892 {
893 Matrix2x2 result;
894
895 result.m00 = left.m00 + right.m00;
896 result.m01 = left.m01 + right.m01;
897
898 result.m10 = left.m10 + right.m10;
899 result.m11 = left.m11 + right.m11;
900
901 return result;
902 }
909 public static Matrix2x2 operator -(Matrix2x2 left, Matrix2x2 right)
910 {
911 Matrix2x2 result;
912
913 result.m00 = left.m00 - right.m00;
914 result.m01 = left.m01 - right.m01;
915
916 result.m10 = left.m10 - right.m10;
917 result.m11 = left.m11 - right.m11;
918
919 return result;
920 }
927 public static Matrix2x2 operator *(Matrix2x2 matrix, Scalar scalar)
928 {
929 Matrix2x2 result;
930
931 result.m00 = matrix.m00 * scalar;
932 result.m01 = matrix.m01 * scalar;
933
934 result.m10 = matrix.m10 * scalar;
935 result.m11 = matrix.m11 * scalar;
936
937 return result;
938 }
945 public static Matrix2x2 operator *(Scalar scalar, Matrix2x2 matrix)
946 {
947 Matrix2x2 result;
948
949 result.m00 = matrix.m00 * scalar;
950 result.m01 = matrix.m01 * scalar;
951
952 result.m10 = matrix.m10 * scalar;
953 result.m11 = matrix.m11 * scalar;
954
955 return result;
956 }
962 public static Matrix2x2 operator -(Matrix2x2 matrix)
963 {
964 Matrix2x2 result;
965
966 result.m00 = -matrix.m00;
967 result.m01 = -matrix.m01;
968
969 result.m10 = -matrix.m10;
970 result.m11 = -matrix.m11;
971
972 return result;
973 }
980 public static bool operator ==(Matrix2x2 left, Matrix2x2 right)
981 {
982 return
983 left.m00 == right.m00 && left.m01 == right.m01 &&
984 left.m10 == right.m10 && left.m11 == right.m11;
985 }
986
987 public static bool operator !=(Matrix2x2 left, Matrix2x2 right)
988 {
989 return !(left == right);
990 }
991
992 public static explicit operator Matrix2x2(Matrix3x3 source)
993 {
994 Matrix2x2 result;
995
996 result.m00 = source.m00;
997 result.m01 = source.m01;
998
999 result.m10 = source.m10;
1000 result.m11 = source.m11;
1001
1002 return result;
1003 }
1004
1005 #endregion
1006 }
1007}
1008
1009
System.Single Scalar
Definition: Clamped.cs:29
System.Single Scalar
Definition: Matrix2x2.cs:31
static Scalar Cos(Scalar d)
Definition: MathHelper.cs:302
static Scalar Sin(Scalar a)
Definition: MathHelper.cs:312
static string CreateMatrixFormatableString(int RowCount, int ColumnCount)
Definition: MatrixHelper.cs:43
static string CreateMatrixFormatString(int RowCount, int ColumnCount)
Definition: MatrixHelper.cs:39
static Exception GetThrowIndex(string name, int count)
Definition: ThrowHelper.cs:50
static void CheckCopy(Scalar[] array, int index, int count)
Definition: ThrowHelper.cs:35
int Count
Gets a 32-bit integer that represents the total number of elements in all the dimensions of IAdvanceV...
Definition: Interfaces.cs:41
int RowCount
Gets a 32-bit integer that represents the total number of Rows in the IMatrix.
Definition: Interfaces.cs:98
int ColumnCount
Gets a 32-bit integer that represents the total number of Columns in the IMatrix.
Definition: Interfaces.cs:102
A 2x2 matrix which can represent rotations for 2D vectors.
Definition: Matrix2x2.cs:58
static void CopyTranspose(Scalar[] sourceArray, out Matrix2x2 result)
Definition: Matrix2x2.cs:132
static void FromScale(ref Vector2D scale, out Matrix2x2 result)
Definition: Matrix2x2.cs:444
static void Multiply(ref Matrix2x2 left, ref Scalar scalar, out Matrix2x2 result)
Definition: Matrix2x2.cs:239
static Matrix2x2 Subtract(Matrix2x2 left, Matrix2x2 right)
Used to subtract two matrices.
Definition: Matrix2x2.cs:280
static Matrix2x2 FromArray(Scalar[] array)
Definition: Matrix2x2.cs:405
static Matrix2x2 operator-(Matrix2x2 left, Matrix2x2 right)
Used to subtract two matrices.
Definition: Matrix2x2.cs:909
Vector2D GetRow(int rowIndex)
Definition: Matrix2x2.cs:704
static void Add(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
Definition: Matrix2x2.cs:266
static Matrix2x2 GetAdjoint(Matrix2x2 source)
Definition: Matrix2x2.cs:373
static Matrix2x2 CreateNormal(Matrix2x3 source)
Definition: Matrix2x2.cs:482
static Matrix2x2 FromScale(Vector2D scale)
Definition: Matrix2x2.cs:435
Vector2D Rx
The X Row or row zero.
Definition: Matrix2x2.cs:587
Scalar[] ToArray()
Copies the elements of the IAdvanceValueType to a new array of Scalar .
Definition: Matrix2x2.cs:734
int IAdvanceValueType. Count
Definition: Matrix2x2.cs:673
static readonly string FormatableString
Definition: Matrix2x2.cs:79
static readonly string FormatString
Definition: Matrix2x2.cs:78
static void Copy(ref Matrix3x3 source, out Matrix2x2 dest)
Definition: Matrix2x2.cs:155
override string ToString()
Definition: Matrix2x2.cs:771
Vector2D GetColumn(int columnIndex)
Definition: Matrix2x2.cs:679
static void Lerp(ref Matrix2x2 left, ref Matrix2x2 right, ref Scalar amount, out Matrix2x2 result)
Definition: Matrix2x2.cs:178
static Matrix2x2 Multiply(Matrix2x2 left, Scalar scalar)
Used to multiply a Matrix2x2 object by a scalar value..
Definition: Matrix2x2.cs:227
static void Copy(ref Matrix4x4 source, out Matrix2x2 dest)
Definition: Matrix2x2.cs:147
static void Copy(ref Matrix2x3 source, out Matrix2x2 dest)
Definition: Matrix2x2.cs:163
static Scalar GetDeterminant(Matrix2x2 source)
Definition: Matrix2x2.cs:347
static void Copy(Scalar[] sourceArray, out Matrix2x2 result)
Definition: Matrix2x2.cs:104
static void CreateNormal(ref Matrix3x3 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:502
static void CopyTranspose(ref Matrix2x2 matrix, Scalar[] destArray, int index)
Definition: Matrix2x2.cs:122
Matrix2x2(Scalar m00, Scalar m01, Scalar m10, Scalar m11)
Creates a new Matrix3 with all the specified parameters.
Definition: Matrix2x2.cs:525
string ToStringInternal(string FormatString)
Definition: Matrix2x2.cs:761
static Matrix2x2 operator+(Matrix2x2 left, Matrix2x2 right)
Used to add two matrices together.
Definition: Matrix2x2.cs:891
static bool Equals(ref Matrix2x2 left, ref Matrix2x2 right)
Definition: Matrix2x2.cs:474
static void Transpose(ref Matrix2x2 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:364
void CopyTransposedTo(Scalar[] array, int index)
Definition: Matrix2x2.cs:748
string ToString(string format)
turns the object into a string representation of itself with a special format for each Scaler in it.
Definition: Matrix2x2.cs:767
static void Copy(ref Matrix2x2 matrix, Scalar[] destArray)
Definition: Matrix2x2.cs:90
static void Negate(ref Matrix2x2 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:322
static void Invert(ref Matrix2x2 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:337
const int Count
The number of Scalar values in the class.
Definition: Matrix2x2.cs:71
Matrix2x2 Transposed
Swap the rows of the matrix with the columns.
Definition: Matrix2x2.cs:637
static Matrix2x2 Add(Matrix2x2 left, Matrix2x2 right)
Used to add two matrices together.
Definition: Matrix2x2.cs:254
Vector2D Ry
The Y Row or row one.
Definition: Matrix2x2.cs:609
static void Subtract(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
Definition: Matrix2x2.cs:292
static bool TryParse(string s, out Matrix2x2 result)
Definition: Matrix2x2.cs:460
static Matrix2x2 Lerp(Matrix2x2 left, Matrix2x2 right, Scalar amount)
Definition: Matrix2x2.cs:172
static readonly Matrix2x2 Identity
Definition: Matrix2x2.cs:81
Scalar[,] ToMatrixArray()
Definition: Matrix2x2.cs:730
Matrix2x2(Scalar[] values)
Definition: Matrix2x2.cs:546
static bool operator==(Matrix2x2 left, Matrix2x2 right)
Test two matrices for (value) equality
Definition: Matrix2x2.cs:980
static void FromRotation(ref Scalar radianAngle, out Matrix2x2 result)
Definition: Matrix2x2.cs:427
static Matrix2x2 Invert(Matrix2x2 source)
Definition: Matrix2x2.cs:331
static Matrix2x2 FromRotation(Scalar radianAngle)
Definition: Matrix2x2.cs:418
override int GetHashCode()
Definition: Matrix2x2.cs:776
static bool Equals(Matrix2x2 left, Matrix2x2 right)
Definition: Matrix2x2.cs:467
static void GetCofactor(ref Matrix2x2 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:394
static Matrix2x2 GetCofactor(Matrix2x2 source)
Definition: Matrix2x2.cs:388
static void GetAdjoint(ref Matrix2x2 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:379
static void Copy(Scalar[] sourceArray, int index, out Matrix2x2 result)
Definition: Matrix2x2.cs:108
void CopyTo(Scalar[] array, int index)
Copies all the elements of the IAdvanceValueType to the specified one-dimensional Array of Scalar.
Definition: Matrix2x2.cs:744
static Matrix2x2 Multiply(Matrix2x2 left, Matrix2x2 right)
Used to multiply (concatenate) two Matrix4x4s.
Definition: Matrix2x2.cs:193
int IMatrix. RowCount
Definition: Matrix2x2.cs:674
Matrix2x2(Scalar[] values, int index)
Definition: Matrix2x2.cs:547
static void Multiply(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result)
Definition: Matrix2x2.cs:205
const int RowCount
The number of rows.
Definition: Matrix2x2.cs:63
static Matrix2x2 Parse(string s)
Definition: Matrix2x2.cs:453
static void Negate(ref Matrix2x2 source)
Definition: Matrix2x2.cs:318
static void CopyTranspose(ref Matrix2x2 matrix, Scalar[] destArray)
Definition: Matrix2x2.cs:118
static Matrix2x2 CreateNormal(Matrix3x3 source)
Definition: Matrix2x2.cs:496
static Matrix2x2 Negate(Matrix2x2 source)
Negates a Matrix2x2.
Definition: Matrix2x2.cs:305
static void GetDeterminant(ref Matrix2x2 source, out Scalar result)
Definition: Matrix2x2.cs:353
void CopyTransposedFrom(Scalar[] array, int index)
Definition: Matrix2x2.cs:756
static Matrix2x2 FromTransposedArray(Scalar[] array)
Definition: Matrix2x2.cs:411
static bool operator!=(Matrix2x2 left, Matrix2x2 right)
Definition: Matrix2x2.cs:987
const int ColumnCount
The number of columns.
Definition: Matrix2x2.cs:67
const int Size
The Size of the class in bytes;
Definition: Matrix2x2.cs:75
static void CreateNormal(ref Matrix2x3 source, out Matrix2x2 result)
Definition: Matrix2x2.cs:488
static readonly Matrix2x2 Zero
Definition: Matrix2x2.cs:84
static void Copy(ref Matrix2x2 matrix, Scalar[] destArray, int index)
Definition: Matrix2x2.cs:94
bool Equals(Matrix2x2 other)
Definition: Matrix2x2.cs:789
override bool Equals(object obj)
Definition: Matrix2x2.cs:783
Scalar[] ToTransposedArray()
Definition: Matrix2x2.cs:738
void SetColumn(int columnIndex, Vector2D value)
Definition: Matrix2x2.cs:690
static Matrix2x2 operator*(Matrix2x2 left, Matrix2x2 right)
Multiply (concatenate) two Matrix3 instances together.
Definition: Matrix2x2.cs:872
int IMatrix. ColumnCount
Definition: Matrix2x2.cs:675
static Matrix2x2 Transpose(Matrix2x2 source)
Definition: Matrix2x2.cs:358
void SetRow(int rowIndex, Vector2D value)
Definition: Matrix2x2.cs:715
static void CopyTranspose(Scalar[] sourceArray, int index, out Matrix2x2 result)
Definition: Matrix2x2.cs:136
void CopyFrom(Scalar[] array, int index)
Copies all the elements of the IAdvanceValueType, of the specified one-dimensional Array to the IAdva...
Definition: Matrix2x2.cs:752
Matrix2x2(Vector2D xAxis, Vector2D yAxis)
Create a new Matrix from 3 Vertex3 objects.
Definition: Matrix2x2.cs:539
A 2x3 matrix which can represent rotations around axes.
Definition: Matrix2x3.cs:62
A 3x3 matrix which can represent rotations around axes.
Definition: Matrix3x3.cs:62
This is the Vector Class.
Definition: Vector2D.cs:50
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
Definition: Vector2D.cs:796
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
Definition: Vector2D.cs:805