简体   繁体   English

反正切函数返回怪异值

[英]Arc tangent function returns weird values

In Processing, I'm trying to set a sprite's direction and momentum by clicking where to place it, and releasing the mouse to show what direction it should move in, with 0 degrees being directly upwards. 在“处理”中,我试图通过单击放置精灵的方向来设置精灵的方向和动量,然后释放鼠标以显示精灵应向哪个方向移动,0度直接向上。 However, the atan() function returns weird values, ranging from about 30 degrees to about 60. I've already made sure it's not a problem converting radians/degrees, and I still can't figure it out. 但是,atan()函数返回的怪异值大约在30度到60度之间。我已经确定转换弧度/度数不是问题,而且我仍然无法弄清楚。

void mousePressed(){
  if (ballCount<limit){
    ballX[ballCount]=mouseX;
    ballY[ballCount]=mouseY;
    ball[ballCount]=true;
    ballSize[ballCount]=currentSize;
  }
}

void mouseReleased(){
  if (ballCount<limit){ //This next line is the one I'm having problems with
    ballDir[ballCount]=atan((ballX[ballCount]-mouseX)/(ballY[ballCount]-mouseY));
    println(degrees((ballDir[ballCount])));

    ballCount++;
  }
}

Never mind, I found the answer. 没关系,我找到了答案。 A different method was running in draw() that would update the ballCount variable based on the amount of balls[] that were true, and so the ballCount variable would differ between mousePressed() and mouseReleased(). 在draw()中运行了另一种方法,该方法将根据true []的数量来更新ballCount变量,因此,mousePressed()和mouseReleased()之间的ballCount变量将有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM