VectorExtender.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MathNet.Numerics.LinearAlgebra.Single;
  7. namespace bbiwarg.Helpers
  8. {
  9. public static class VectorExtender
  10. {
  11. public static Vector Cross(this Vector v, Vector other)
  12. {
  13. if ((v.Count != 3 || other.Count != 3))
  14. {
  15. string message = "Vectors must have a length of 3.";
  16. throw new Exception(message);
  17. }
  18. Vector result = new DenseVector(3);
  19. result[0] = v[1] * other[2] - v[2] * other[1];
  20. result[1] = -v[0] * other[2] + v[2] * other[0];
  21. result[2] = v[0] * other[1] - v[1] * other[0];
  22. return result;
  23. }
  24. public static float x(this Vector v)
  25. {
  26. return v[0];
  27. }
  28. public static float y(this Vector v)
  29. {
  30. return v[1];
  31. }
  32. public static float z(this Vector v)
  33. {
  34. return v[2];
  35. }
  36. }
  37. }