You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Vector.cs 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. namespace Preparation.Utility
  3. {
  4. public struct Vector
  5. {
  6. public double angle;
  7. public double length;
  8. public static XYPosition VectorToXY(Vector v)
  9. {
  10. return new XYPosition((int)(v.length * Math.Cos(v.angle)), (int)(v.length * Math.Sin(v.angle)));
  11. }
  12. public Vector2 ToVector2()
  13. {
  14. return new Vector2((int)(this.length * Math.Cos(this.angle)), (int)(this.length * Math.Sin(this.angle)));
  15. }
  16. public static Vector XYToVector(double x, double y)
  17. {
  18. return new Vector(Math.Atan2(y, x), Math.Sqrt((x * x) + (y * y)));
  19. }
  20. public Vector(double angle, double length)
  21. {
  22. if (length < 0)
  23. {
  24. angle += Math.PI;
  25. length = -length;
  26. }
  27. this.angle = Tools.CorrectAngle(angle);
  28. this.length = length;
  29. }
  30. }
  31. public struct Vector2
  32. {
  33. public double x;
  34. public double y;
  35. public Vector2(double x, double y)
  36. {
  37. this.x = x;
  38. this.y = y;
  39. }
  40. public static double operator*(Vector2 v1, Vector2 v2)
  41. {
  42. return (v1.x * v2.x) + (v1.y * v2.y);
  43. }
  44. public static Vector2 operator +(Vector2 v1, Vector2 v2)
  45. {
  46. return new Vector2(v1.x + v2.x, v1.y + v2.y);
  47. }
  48. public static Vector2 operator -(Vector2 v1, Vector2 v2)
  49. {
  50. return new Vector2(v1.x - v2.x, v1.y - v2.y);
  51. }
  52. }
  53. }