找到两点之间的角度 [英] finding angle between two points

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

问题描述

嗨帮,

我的程序中有一个充满粒子的网格,我想在两个粒子之间找到一个

的角度。我遇到了麻烦,因为看起来好像

答案取决于目标粒子是否高于或低于参考粒子前后的
。 br />

如果我有一个参考粒子在(10,10),另一个粒子在

(20,20),我现在正在寻找角度通过:


angle = atan((10-20)/(10-20))= 45度。当我画出来的时候,我可以看到(20,20)对象在

(10,10)对象的x轴下方45度。好的。


但是如果我看另一个粒子并将其与(10,10)的角度进行比较,

例如位于( 2,20),我得到了一些不同的东西:
atan((10-20)/(10-2))= -51.34度


当我拍摄这些角度的x和y分量时,事情就不会加起来。

有时它会给我x的负值应该是积极的。


我不觉得我在这里很清楚,但我希望这是一个足够的

错误,有人知道我想说什么。我是

想知道是否有更好的方法可以找到两个可能相对于某个轴的两个点之间的角度,因为它似乎是

我的角度在不同时间相对于不同的轴。谢谢你们

解决方案

cw ********@ucdavis.edu 写道:

嗨帮,
我的程序中有一个充满粒子的网格,我想找一个两个粒子之间的角度。我遇到了麻烦,因为看起来答案取决于目标粒子是否高于或低于引用粒子的前方或后方。

如果我有一个参考粒子在(10,10),另一个粒子在(20,20),我现在找到角度:

angle = atan((10 -20)/(10-20))= 45度。当我画出来的时候,我可以看到(20,20)物体距离
(10,10)物体x轴下方45度。好吧。

但是如果我看另一个粒子并将其与(10,10)的角度进行比较,例如位于(2,20)的粒子,我会得到一些东西有点不同:

atan((10-20)/(10-2))= -51.34度

当我拿x和y组件时这些角度,事情并没有加起来。
当它应该是积极的时候它给了我x的负值。

我不觉得我一直很好在这里清楚,但我希望这是一个足够常见的错误,有人知道我想说什么。我也想知道是否有更好的方法可以找到两个可能相对于某个轴的点之间的角度,因为看起来我的角度是相对于不同的轴在不同的时间。谢谢你们




首次使用任何

三角函数进行计算时,这种性质的符号错误是一个常见问题。它不是特定于C ++的,但是这里有一些指针,如果你按照它们的话,应该引导你:


1。仔细考虑象限以及它们与你正在使用的

三角函数的关系,以及所涉及的符号。

2.请记住,无数个角度都有相同的

三角测量。

3.熟悉触发功能的行为(在这种情况下,atan,

)你是使用。阅读文档。你应该先了解一下这个标志会给出一个特定的输入。


你必须知道你的触发器,你已经知道了得阅读文档。

休息只是摆弄。


Luke


* cw ******** @ ucdavis.edu


我的程序中有一个充满粒子的网格,我想找到两个粒子之间的角度。我遇到了麻烦,因为看起来答案取决于目标粒子是否高于或低于引用粒子的前方或后方。

如果我有一个参考粒子在(10,10),另一个粒子在
(20,20),我现在通过以下方式找到角度:




两点之间没有角度;如果你的意思是矢量之间的角度

,那么在这种情况下就是0度。


在数学方面,你可以使用点积,参见例如

< url:http://mathworld.wolfram.com/DotProduct.html>。


C ++并不多支持三角函数,所以你可能需要根据那里的内容滚动

你自己的弧cos函数。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:Top -posting。

问:usenet和电子邮件中最烦人的事情是什么?


2006年2月1日19:30: 32 -0800, cw********@ucdavis.edu 写道:
< blockquote class =post_quotes>嗨帮,
我的程序中有一个充满粒子的网格,我想找到两个粒子之间的角度。我遇到了麻烦,因为看起来答案取决于目标粒子是否高于或低于引用粒子的前方或后方。

如果我有一个参考粒子在(10,10),另一个粒子在(20,20),我现在找到角度:

angle = atan((10 -20)/(10-20))= 45度。当我画出来的时候,我可以看到(20,20)物体距离
(10,10)物体x轴下方45度。好吧。

但是如果我看另一个粒子并将其与(10,10)的角度进行比较,例如位于(2,20)的粒子,我会得到一些东西有点不同:

atan((10-20)/(10-2))= -51.34度

当我拿x和y组件时这些角度,事情并没有加起来。
当它应该是积极的时候它给了我x的负值。

我不觉得我一直很好在这里清楚,但我希望这是一个足够常见的错误,有人知道我想说什么。我也想知道是否有更好的方法可以找到两个可能相对于某个轴的点之间的角度,因为看起来我的角度是相对于不同的轴在不同的时间。谢谢你们




Trig就在几年前了。


需要测量线之间的角度,而不是点数。

所以必须有一个共同的参考。

原点是典型的:(0,0)

如果在同一象限中>>使用:abs(arctan(角度#1) - arctan(角度#2))


arctan(20/2) - arctan(10/10)

记住>>上涨超过运行


1.471128 - 0.785398 = 0.68573弧度


0.68573弧度x 180度/ PI弧度= 39.28941度


10,10显然是45度

2,20接近y轴

答案略低于45度退出。


如果在象限#1和#2 ......与上面相同

如果在象限#1和#4 ...画画并正确添加它们

您的参考是原点和x轴

如果在象限#1和#3或#2和#3 ...再次..绘制图片

独立查看x轴的每个角度。

添加它们或减去它们取决于象限。

有时你必须减去计算出的角度为180度

以获得与轴的工作角度。

答案通常为180度或更低..除非指示为

指定了遍历。例如......(10,1)& (10,0)可以包裹

并且接近360度...或者可能非常小......取决于问题规格的

$祝你好运。


- 汤姆



Hi gang,
I have a grid full of particles in my program, and I want to find an
angle between two particles. I''m having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.

If I have a reference particle at (10,10), and another particle at
(20,20), i''m currently finding the angle by:

angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this out, I can
see that the (20,20) object is 45 degrees below the x-axis from the
(10,10) object. Fine.

But if I look at another particle and compare it''s angle to (10,10),
for example a particle located at (2,20), I get something kind of
different:

atan((10-20)/(10-2)) = -51.34 degrees

When I take x and y components of these angles, things don''t add up.
Somtimes it gives me a negative value of x when it should be positive.

I don''t think I''ve been very clear here, but I''m hoping this is a
common enough mistake that someone knows what I''m trying to say. I''m
wondering also if there is a better way to find a angle between two
points that might be relative to a certain axis, because it seems like
my angle is relative to different axes at different times. Thanks guys

解决方案

cw********@ucdavis.edu wrote:

Hi gang,
I have a grid full of particles in my program, and I want to find an
angle between two particles. I''m having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.

If I have a reference particle at (10,10), and another particle at
(20,20), i''m currently finding the angle by:

angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this out, I can
see that the (20,20) object is 45 degrees below the x-axis from the
(10,10) object. Fine.

But if I look at another particle and compare it''s angle to (10,10),
for example a particle located at (2,20), I get something kind of
different:

atan((10-20)/(10-2)) = -51.34 degrees

When I take x and y components of these angles, things don''t add up.
Somtimes it gives me a negative value of x when it should be positive.

I don''t think I''ve been very clear here, but I''m hoping this is a
common enough mistake that someone knows what I''m trying to say. I''m
wondering also if there is a better way to find a angle between two
points that might be relative to a certain axis, because it seems like
my angle is relative to different axes at different times. Thanks guys



Sign errors of this nature are a common problem when first using any
trigonometry for computation. It''s not C++-specific, but here''s a few
pointers which, if you follow them, should lead you right:

1. Think carefully about quadrants and how they relate to the
trigonometric function you''re using, and the signs involved.
2. Remember that an infinite number of angles have the same
trigonometric measures.
3. Familiarize yourself with the behavior of the trig function (atan,
in this case) you''re using. Read the documentation. You should know a
priori what the sign will be given a particular input.

You''ve got to know your trig, and you''ve got to read the docs. The
rest is just fiddling bits.

Luke


* cw********@ucdavis.edu:


I have a grid full of particles in my program, and I want to find an
angle between two particles. I''m having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.

If I have a reference particle at (10,10), and another particle at
(20,20), i''m currently finding the angle by:



There''s no such thing as angle between two points; if you mean the angle
between the vectors, then that''s the exactly 0 degrees in this case.

At the mathematics side you can use the dot product, see e.g.
<url: http://mathworld.wolfram.com/DotProduct.html>.

C++ doesn''t much support trigonometry, so you''ll probably have to roll
your own arc cos function, based on what''s there.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


On 1 Feb 2006 19:30:32 -0800, cw********@ucdavis.edu wrote:

Hi gang,
I have a grid full of particles in my program, and I want to find an
angle between two particles. I''m having trouble because it seems like
the answer depends on whether or not the target particle is above or
below, in front or behind the refernce particle.

If I have a reference particle at (10,10), and another particle at
(20,20), i''m currently finding the angle by:

angle = atan((10-20)/(10-20)) = 45 degrees. When I draw this out, I can
see that the (20,20) object is 45 degrees below the x-axis from the
(10,10) object. Fine.

But if I look at another particle and compare it''s angle to (10,10),
for example a particle located at (2,20), I get something kind of
different:

atan((10-20)/(10-2)) = -51.34 degrees

When I take x and y components of these angles, things don''t add up.
Somtimes it gives me a negative value of x when it should be positive.

I don''t think I''ve been very clear here, but I''m hoping this is a
common enough mistake that someone knows what I''m trying to say. I''m
wondering also if there is a better way to find a angle between two
points that might be relative to a certain axis, because it seems like
my angle is relative to different axes at different times. Thanks guys



Trig was a few years back.

Need to measure angles between lines, not points.
So must have a common reference.
The origin is typical: (0,0)
if in same quadrant >> Use: abs(arctan(angle #1) - arctan(angle #2))

arctan(20/2) - arctan(10/10)

remember >> rise over run

1.471128 - 0.785398 = 0.68573 radians

0.68573 radians x 180 degree / PI radians = 39.28941 degrees

10,10 is obviously 45 degrees
2,20 is close to the y-axis
answer slightly less than 45 degrees checks out.

if in quadrants #1 and #2 ... same as above
if in quadrants #1 and #4 ... draw the picture and add them correctly
your reference is the origin and the x-axis
if in quadrants #1 and #3 or #2 and #3 ... again .. draw the picture
look at each angle with the x-axis independently.
to add them or subtract them depends on the quadrants.
sometimes you have to subtract the calculated angle from 180 degrees
to get the working angle with the axis.
answer is typically 180 degrees or less .. unless direction to
traverse is specified. For example ... (10,1) & (10,0) could wrap
around and be near 360 degrees ... or could be very small ... depends
on problem specification.
good luck.

-- Tom



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

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