- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 vector ,我想计算它们之间的角度。
一个 vector 定义为两个点,即 P1(x1,y1)
和 P2(x2,y2)
。另一个 vector 定义为点 P3(x3,y3)
及其相对于 x 轴的航向角(例如 theta)。
我知道我需要获得它们的乘积,但是如何获得两点的第二个 vector ?
实际上我尝试过使用atan2(),但是当角度在pi(+-epsilon)附近时,它会从pi跳转到-pi,这是不希望的,并且我无法简单地通过添加2*pi来修复它角度小于零。在这种情况下,我的模拟会从 +pi 跳到 -pi。
我正在使用C-mex S-functions
,但任何伪代码
也可以。
非常感谢
最佳答案
从 here 获取全部内容。请阅读那里的讨论以了解该主题。
Assuming a = [x1,y1] and b = [x2,y2] are two vectors with their bases at the origin, the non-negative angle between them measured counterclockwise from a to b is given by
angle = mod(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);
对于 MATLAB 实现,mod
可以替换为 rem
:
angle = rem(atan2(x1*y2-x2*y1,x1*x2+y1*y2),2*pi);
The quantities, x1*y2-x2*y1 and x1*x2+y1*y2 are, respectively, the sine and cosine of the counterclockwise angle from vector a to vector b, multiplied by the product of their norms - that is, their cross product and the dot product restricted to two dimensions. The 'atan2' function then gives the angle between them ranging from -pi to +pi, and the 'mod' operation changes this so as to range from 0 to 2*pi.
请不要使用诸如 theta = acos(dot(a,b))
之类的公式,因为它在 pi
和 -pi< 附近存在准确性问题
.
关于计算两个 vector 之间的角度(atan2 不连续问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26658917/
我必须做一些需要使用三角函数的计算,尤其是 atan一。代码将在 Atmega328p 上运行,为了效率,我不能使用 float s:我使用的是定点数。因此,我不能使用标准 atan功能。 我有一个函
我一直在谷歌上搜索这个问题的解决方案。我见过多种计算任何 -1 #include double my_atan(double x) { return x - (x*x*x)/3 + (x*
我正在用 JavaScript 编写我的第一个项目。据我了解,Math.atan() 返回一个数字(以弧度表示的 Angular )。但不知何故,它返回了 Nan。 使用console.log(),我
我遇到 Math.atan 返回与输入相同的值的问题。 public double inchToMOA( double in, double range){ double rangeI
这里是一位非常初级的程序员(两周前开始),我目前在使用 Math.atan 时遇到问题。我目前使用 Eclipse IDE,并且一直在尝试找出如何对三角形执行 tan^-1,但目前不起作用。我在控制台
下面的代码演示了 atan 的计算时间可以有很大的不同: #include #include #include #include #include #include double get_
我有以下小程序,它在我的大型项目中重现了一个触发错误: #define _USE_MATH_DEFINES #include #include #define R2D(trig_fn, val)
我在我的代码中得到了这个函数: -(void)printAngle { int width = p2_t.x-cp1_t.x; int height = p2_t.y-cp1_t.y;
我有个小问题我不知道如何在 cobol 中转换我的 ATAN/ASIN/ACOS 函数这是代码: ACCEPT A
我试图在点的 Angular 之间做一些比较,但很快我遇到了一些奇怪的结果。 在这个例子中,我尝试旋转线条,使它们指向中心,但线条的 Angular 似乎超过了它们应该很快的 Angular 。然后,
我正在尝试计算一个实体观看另一个实体时必须观察的角度。 l是第一个实体的位置。 o是另一个实体的位置。 每个实体在 3D 空间中都有一个 3D X、Y 和 Z 坐标。 我目前使用 double ang
这个问题已经有答案了: What is the difference between atan and atan2 in C++? (11 个回答) 已关闭 6 年前。 我有一个问题。 atan 和有
我如何将我的 atan 函数放入 atan2 中?例如 float myAtan2(double a, double b) { float atan2val = //calculate ata
Java Math.atan() 函数是否已知有任何问题?我在我的代码中使用它,由于一些我无法解决的奇怪原因,该函数将在 45 度运动时返回 0,跳转到 45 并保持在 45 直到它达到 63.4 度
我在一些基本的触发方面遇到了一些麻烦。我正在做一些数学作业,我终于厌倦了将直角坐标转换为极坐标,反之亦然,所以我决定编写一个小 Python 程序来帮助我进行转换。但是, Math.atan() 给我
我的公式f=arctan(ImZ/ReZ) 有两种选择: 选项 1 (atan): ImZ=-4.593172163003 ImR=-4.297336384845 >>> z=y/x >>> f1=m
atan 和 atan2 都是反正切函数,返回的都是弧度 对于两点形成的直线,两点分别是 point(x1,y1) 和 point(x2,y2),其斜率对应角度的计算方法可以是:
我有一个 2D 侧视射击游戏,我需要一些新的视角。我目前正在研究瞄准,并且它部分有效: Guzzle 速度已知,重力已知,并且到目标的 x,y 距离也已知。使用 SE 和维基百科上的各种来源,我提出了
我在java编程中使用半正矢公式(使用eclipse)。我的问题是在等式的末尾,我收到一个错误(atan 带下划线),指出“方法 atan(double) 对于 Math 类型未定义”。 我不知道出了
所以我想获得2点之间的度数,但是当我希望它返回180时,它返回0...0、90和270确实有效,但是当它180时它返回0..这是我的代码: Location loc1 = new Location(B
我是一名优秀的程序员,十分优秀!