Guest User

Untitled

a guest
Apr 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class Node
  2. {
  3. public Vector GetReplusiveForce(Node n)
  4. {
  5. // 反発は距離の2乗に反比例 (比例定数 g)
  6. const double g = 500.0d;
  7. double dx = this.R.X - n.R.X;
  8. double dy = this.R.Y - n.R.Y;
  9. double d2 = dx * dx + dy * dy;
  10. if (d2 < double.Epsilon)
  11. {
  12. // 距離0の時は例外として乱数で決定
  13. Random rand = new Random();
  14. return new Vector()
  15. {
  16. X = rand.NextDouble() - 0.5d,
  17. Y = rand.NextDouble() - 0.5d
  18. };
  19. }
  20. double d = Math.Sqrt(d2);
  21. double cos = dx / d;
  22. double sin = dy / d;
  23. return new Vector()
  24. {
  25. X = g / d2 * cos,
  26. Y = g / d2 * sin
  27. };
  28. }
  29. }
Add Comment
Please, Sign In to add comment