试图计算圆上两点之间的角度? [英] Trying to calculate the angle between two points on a circle?

查看:1298
本文介绍了试图计算圆上两点之间的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图计算两个点之间的角度,一个是在数学上圆圈,两点是用户在一定时间内拖动的距离。



这是我到目前为止:

  intervalId = setInterval (函数(){

if(p1x!= undefined){
p2x = Xpos;

}

if(p1y! = $ p


$ b (p1a * p1a)+(p1b * p1b));

p2a = p2x - wheelMiddleVer;
p2b = p2y - wheelMiddleHor;
b = Math.sqrt((p2a * p2a)+(p2b * p2b));

u = p1x - p2x;
v = p1y - p2y;
c = Math.sqrt((u * u)+(v * v));


}

p1x = Xpos;
p1y = Ypos;


},1000);

我不知道如何完成它。我尝试过使用cos A =(b ^ 2 + c ^ 2 - a ^ 2)/ 2bc公式,但对我而言并不成功。我会很感激你对此的投入。如果我能让问题更清楚,让我知道。

解决方案

首先,请记住,大多数语言都有一个Y轴反转。意思是比例越高 - > Y值越小。

至于你的问题,你应该使用arctan:

  var angle = Math.atan((p1y  -  p2y)/(p2x  -  p1x))*(180 / Math.PI); 


First and foremost let me say I am an absolutely atrocious at maths, please bear with me.

I'm trying to calculate the angle between two points on a circle, the two points being the distance the user has dragged in a certain amount of time.

This is what I have so far:

intervalId = setInterval(function(){

      if(p1x != undefined){
        p2x = Xpos;

      }

      if(p1y != undefined){
        p2y = Ypos;
      }


      if( p1x != p2x || p1y != p2y ){

        p1a = p1x - wheelMiddleVer;
        p1b = p1y - wheelMiddleHor;
        a = Math.sqrt((p1a * p1a) + (p1b * p1b));

        p2a = p2x - wheelMiddleVer;
        p2b = p2y - wheelMiddleHor;
        b = Math.sqrt((p2a * p2a) + (p2b * p2b));

        u = p1x - p2x;
        v = p1y - p2y;
        c = Math.sqrt((u * u) + (v * v));


      }

      p1x = Xpos;
      p1y = Ypos;


  }, 1000);

I'm not sure how to finish it. I have tried using the cos A = (b^2 + c^2 - a^2)/2bc formula but it's not worked out for me. I will appreciate your input on this. If I can make the question clearer let me know.

解决方案

First of all, keep in mind that most of the languages have an invert Y axis. Meaning the higher the point on the scale -> the smaller it Y value is.

As for your question, you should use arctan:

var angle = Math.atan((p1y - p2y) / (p2x - p1x)) * (180 / Math.PI);

这篇关于试图计算圆上两点之间的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆