Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node
- {
- public Vector GetReplusiveForce(Node n)
- {
- // 反発は距離の2乗に反比例 (比例定数 g)
- const double g = 500.0d;
- double dx = this.R.X - n.R.X;
- double dy = this.R.Y - n.R.Y;
- double d2 = dx * dx + dy * dy;
- if (d2 < double.Epsilon)
- {
- // 距離0の時は例外として乱数で決定
- Random rand = new Random();
- return new Vector()
- {
- X = rand.NextDouble() - 0.5d,
- Y = rand.NextDouble() - 0.5d
- };
- }
- double d = Math.Sqrt(d2);
- double cos = dx / d;
- double sin = dy / d;
- return new Vector()
- {
- X = g / d2 * cos,
- Y = g / d2 * sin
- };
- }
- }
Add Comment
Please, Sign In to add comment