如何将方向向量转换为角度?

huangapple go评论180阅读模式
英文:

How do we convert a direction vector to an angle?

问题

如果我有一个向量 v1(-4,3),它起始于 v0(0,0)。如何确定其方向,用 角度弧度 表示?向量的 大小sqrt((-4-0)^2 + (3-0)^2),即 5。如果方向是 (|-4/5|, |3/5| ),即 (0.8, 0.6),那么如何将其转换为角度表示?这会是顺时针还是逆时针?

英文:

If I have a vector v1(-4,3) where it starts from v0(0,0). How do I find out the direction in said, in angle or radian representation ?. The magnitude of the vector is sqrt((-4-0)^2 + (3-0)^2) which is 5. If the direction is (|-4/5|, |3/5| ) which is (0.8, 0.6) then how do I convert this in an angle representation? Will this be clockwise, counter-clockwise?

答案1

得分: 2

以下是翻译好的代码部分:

最快的回答这个问题的方法是进行实验:

public class TangentDemo {

    public static void main(String[] args) {
        double x = -4.0;
        double y = 3.0;
        double radians = Math.atan2(y, x);
        System.out.println(String.format("角度:%10.6f 弧度 %10.6f 度", radians, Math.toDegrees(radians)));
    }
}
英文:

The fastest way to answer this question is to experiment:

public class TangentDemo {

    public static void main(String[] args) {
        double x = -4.0;
        double y = 3.0;
        double radians = Math.atan2(y, x);
        System.out.println(String.format("Angle: %10.6f radians %10.6f degrees", radians, Math.toDegrees(radians)));
    }
}

huangapple
  • 本文由 发表于 2020年3月16日 22:18:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/60707646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定