Created
November 3, 2009 00:57
-
-
Save matarillo/224672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment