public double VirtualDistanceTo(Vector2D v1) { double dx = (v1.x < (MAX_X/2.0)) ? MAX_X : -MAX_X; double dy = (v1.y < (MAX_Y/2.0)) ? MAX_Y : -MAX_Y; Vector2D v2 = v1.Add( dx, 0.0); Vector2D v3 = v1.Add(0.0, dy); Vector2D v4 = v1.Add( dx, dy); double dist = DistanceTo(v1) ; dist = Math.Min(dist, DistanceTo(v2)); dist = Math.Min(dist, DistanceTo(v3)); dist = Math.Min(dist, DistanceTo(v4)); return dist; }
public double VirtualAngleTo(Vector2D v1) { double dx = (v1.x < (MAX_X/2.0)) ? MAX_X : -MAX_X; double dy = (v1.y < (MAX_Y/2.0)) ? MAX_Y : -MAX_Y; Vector2D v2 = v1.Add( dx, 0.0); Vector2D v3 = v1.Add(0.0, dy); Vector2D v4 = v1.Add( dx, dy); double angle = AngleTo(v1); double dist = DistanceTo(v1); double dist2 = DistanceTo(v2); if (dist2 < dist) { angle = AngleTo(v2); dist = dist2; } dist2 = DistanceTo(v3); if (dist2 < dist) { angle = AngleTo(v3); dist = dist2; } dist2 = DistanceTo(v4); if (dist2 < dist) { angle = AngleTo(v4); dist = dist2; } return angle; }