-(CGPoint)Rule2:(Boid*)b
{
CGPoint v = CGPointMake(0, 0);
for (Boid *boid in ActiveBoids)
{
if (boid != b)
{
NSLog(@"%f", [Utilities Magnitude:boid.position] - [Utilities Magnitude:b.position]);
if(([Utilities Magnitude:boid.position] - [Utilities Magnitude:b.position]) < 150)
{
v = [Utilities MinusVector:v Vector2:CGPointMake(boid.position.x - b.position.x, boid.position.y - b.position.y)];
NSLog(@"%f", v.x);
NSLog(@"%f", v.y);
}
}
}
return v;
}
我的幅度和减法都可以正常工作:
+ (CGPoint)MinusVector:(CGPoint)v1 Vector2:(CGPoint)v2
{
return CGPointMake(v1.x - v2.x, v1.y - v2.y);
}
+ (float)Magnitude:(CGPoint)p1
{
return hypot(p1.x, p1.y);
}
出于某种原因,这是我从该方法得到的输出:
我已经看这个太久了,看不出有什么问题。有任何想法吗?