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.

XY.cs 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace Preparation.Utility
  3. {
  4. public struct XY
  5. {
  6. public int x;
  7. public int y;
  8. public XY(int x, int y)
  9. {
  10. this.x = x;
  11. this.y = y;
  12. }
  13. public XY(double angle, double length)
  14. {
  15. this.x = (int)(length * Math.Cos(angle));
  16. this.y = (int)(length * Math.Sin(angle));
  17. }
  18. public XY(XY Direction, double length)
  19. {
  20. this.x = (int)(length * Math.Cos(Direction.Angle()));
  21. this.y = (int)(length * Math.Sin(Direction.Angle()));
  22. }
  23. public override string ToString()
  24. {
  25. return "(" + x.ToString() + "," + y.ToString() + ")";
  26. }
  27. public static int operator *(XY v1, XY v2)
  28. {
  29. return (v1.x * v2.x) + (v1.y * v2.y);
  30. }
  31. public static XY operator +(XY v1, XY v2)
  32. {
  33. return new XY(v1.x + v2.x, v1.y + v2.y);
  34. }
  35. public static XY operator -(XY v1, XY v2)
  36. {
  37. return new XY(v1.x - v2.x, v1.y - v2.y);
  38. }
  39. public static double Distance(XY p1, XY p2)
  40. {
  41. return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)));
  42. }
  43. public double Length()
  44. {
  45. return Math.Sqrt(((long)x * x) + ((long)y * y));
  46. }
  47. public double Angle()
  48. {
  49. return Math.Atan2(y, x);
  50. }
  51. }
  52. }