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.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 override string ToString()
  19. {
  20. return "(" + x.ToString() + "," + y.ToString() + ")";
  21. }
  22. public static int operator *(XY v1, XY v2)
  23. {
  24. return (v1.x * v2.x) + (v1.y * v2.y);
  25. }
  26. public static XY operator +(XY v1, XY v2)
  27. {
  28. return new XY(v1.x + v2.x, v1.y + v2.y);
  29. }
  30. public static XY operator -(XY v1, XY v2)
  31. {
  32. return new XY(v1.x - v2.x, v1.y - v2.y);
  33. }
  34. public static double Distance(XY p1, XY p2)
  35. {
  36. return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)));
  37. }
  38. public double Length()
  39. {
  40. return Math.Sqrt(((long)x * x) + ((long)y * y));
  41. }
  42. public double Angle()
  43. {
  44. return Math.Atan2(y, x);
  45. }
  46. }
  47. }