我有一个处理循环斥力的小演示。除了当物体及其斥力(鼠标)的度数接近360 |0区域(或PI | -PI )时,它的效果很好。

或YouTube video
这是100%的原因,但我不知道如何克服它。已经玩过模数了。
发布于 2017-07-29 03:09:17
首先,我希望你在比较时不要把弧度和度数混在一起。
你的计算
float angleDist = abs(angle - repulsor.angle);
and later comparison with
inc=45 degrees例如,如果一个角度为359,而另一个角度为1,则会出现错误。
您可以构建一些if条件或使用表达式:
angleDist = arrcos(cos(angle - repulsor.angle)); 正确对待所有情况
发布于 2017-07-29 02:44:34
它在对象中,Processing / JAVA,大约0.0,0.0中心
float repulsorAngle = atan2(repulsor.y, repulsor.x);
if(rad < 0.0) { angle = map(rad, -PI, 0, 180, 360); }
else { angle = map(rad, 0, PI, 0, 180); }
float angleDist = abs(angle - repulsor.angle);
float dist = PVector.dist(new PVector(x, y), new PVector(repulsor.x, repulsor.y));
float inc = 45.0;
if (angleDist < inc) {
float sine = sin(map(angleDist, inc, 0, 0, PI / 2)) * 50.0;
println(sine);
x = cos(radians(angle)) * (r + sine * dir);
y = sin(radians(angle)) * (r + sine * dir);
} else {
x = cos(radians(angle)) * (r);
y = sin(radians(angle)) * (r);
}https://stackoverflow.com/questions/45380210
复制相似问题