如何计算从垂直矢量的角度θ [英] How to calculate the angle of a vector from the vertical?

查看:196
本文介绍了如何计算从垂直矢量的角度θ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着找了两次二维向量的夹角(度)。我知道我需要使用触发,但我不太好它。这就是我试图找出(Y轴向下增加):

Im trying to find out the angle (in degrees) between two 2D vectors. I know I need to use trig but I'm not too good with it. This is what I'm trying to work out (the Y axis increases downward):

我试图用这个code的时刻,但它不工作(计算任意角度出于某种原因):

I'm trying to use this code at the moment, but it's not working at all (calculates random angles for some reason):

private float calcAngle(float x, float y, float x1, float y1)
{
    float _angle = (float)Math.toDegrees(Math.atan2(Math.abs(x1-x), Math.abs(y1-y)));
    Log.d("Angle","Angle: "+_angle+" x: "+x+" y: "+y+" x1: "+x1+" y1: "+y1);
    return _angle;
}

(提供恒定的位置时,有恒定的,但是当我改变位置,角度的变化,我无法找到两个角度之间的任何链接)这是我的结果:

These are my results (There constant when providing a constant position, but when I change the position, the angle changes and I can't find any link between the two angles):

位置1: X:100 Y:100 X1:50 Y1:50 角度:45

Position 1: x:100 y:100 x1:50 y1:50 Angle: 45

位置2: X:92 Y:85 X1:24 Y1:16 角度:44.58

Position 2: x:92 y:85 x1:24 y1:16 Angle: 44.58

位置3: X:44 Y:16 X1:106 Y1:132 角度:28.12

Position 3: x:44 y: 16 x1:106 y1:132 Angle: 28.12

编辑:谢谢大家谁回答和帮助我弄清楚,错了!对不起标题和问题混淆了。

Thanks everyone who answered and helped me figure out that was wrong! Sorry the title and the question was confusing.

推荐答案

啊哈!原来我只是需要我的翻转角度和使用ATAN2。这是我最后的code:

Aha! Turns out I just needed to flip my angle and use atan2. This is my final code:

private float calcAngle(float x, float y, float x1, float y1)
{
    float _angle = (float)Math.toDegrees(Math.atan2(x1-x, y-y1));
    return _angle;
}

谢谢大家帮助我弄清楚了这一点,同时也帮助我了解我实际上做! :)

Thanks everyone for helping me figure this out and also for helping me to understand what I'm actually doing! :)

这篇关于如何计算从垂直矢量的角度θ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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