基于角度和距离在空间中查找2D点 [英] Find a 2D point in space based on angle and distance
问题描述
好吧,所以我做了一个快速图表,解释我希望完成什么。可悲的是,数学不是我的forte,我希望你的一个向导可以给我正确的公式:)这是一个c ++程序,但真的我正在寻找公式,而不是c ++代码。
好吧,现在基本上,红色圆圈是我们的0,0点,我站在那里。蓝色圆圈是我们以上300单位,我认为是0度的角度。我想知道,我可以找到一个找到x,y的点在这个图表使用我选择的角度以及一定的距离,我选择。
我想知道如何找到x,y的绿色圆圈,这是说225度和500个单位。
所以我假设我有找出一个方法来转置一个圆圈的所有点,从0,0的500单位,而不是基于我想要的角度选择一个地方在那个圆圈上?
飞机上的点可以用两个主要的数学表示来表示,即笛卡尔(因此 x,y
)和polar:使用离中心的距离和角度。通常 r
和希腊字母,但让我们使用 w
。
定义
在常见惯例下,r是从中心(0,0)到点的距离,
是逆时针注释
p>注意有关极坐标表示中的角度的一些事情:
-
角度也可以用弧度表示,其中π是相同的角度为180°,因此π/ 2 90°等。 π= 3.14(约)由2π=半径为1的圆的周长定义。
-
角度可以表示为整圆。整圆为2π或360°,因此+ 90°与-270°相同,+ 180°和-180°相同,以及3π/ 4和-5π/4,2π和0, 360°和0°等。你可以考虑[-π,π](即[-180,180])或[0,2π](即[0,360])之间的角度,或者根本不限制它们,
-
当你的点位于中心(r = 0)
-
r根据定义总是为正。如果r是负数,您可以更改其符号并添加半圈(π或180°)以获取同一点的坐标。
您的图表上的点
-
red:x = 0,y = 0或r = 0 w =任何值
-
blue:x = 0,y = 300或r = 300 and w = 90°
-
green:x = -400,y = -400或r = -565和w = 225°(近似值,我没有进行实际测量)
请注意,对于蓝点,您可以有w = -270°,绿色w = -135°等。
从一个表示转到另一个表示
最后,需要三角公式在表示之间来回转换。更容易的转换是从极地到笛卡尔:
x = r * cos(w)
y = r * sin w)
由于cos²+sin²= 1,pythagoras等等,你可以看到x²+y²=r²cos²(w)+r²sin²(w)=r²
,因此得到r,使用:
r = sqrt(x²+y²)
角度,我们使用 cos / sin = tan
其中tan是另一个三角函数。从 y / x = r sin(w)/(r cos(w))= tan(w)
,你得到:
w = arctan(y / x)[modπ]
tan是以π为模的函数,而不是2π。 arctan简单地表示函数tan的倒数,有时写为tan ^ -1或atan。
通过反转切线,可以得到-π/ 2和π/ 2(或-90°和90°):您需要最终将π添加到您的结果。这是对于[π/ 2,π]和[-π,π/ 2]([90,180]和[-180,-90])之间的角度。这些值由cos的符号表示:因为 x = r cos(w)
你知道x在所有这些角度上都是负的。尝试看看这些角度在你的图上,这是真的很简单。因此:
w = arctan(y / x)+(如果x <0,则为π)
最后,如果值为0,则不能除以x。在这种情况下,您有
-
如果y> 0,
w =π/ 2
-
如果y < 0,
w =-π/ 2
Ok.... so I made a quick diagram to sorta explain what I'm hoping to accomplish. Sadly math is not my forte and I'm hoping one of you wizards can give me the correct formulas :) This is for a c++ program, but really I'm looking for the formulas rather than c++ code.
Ok, now basically, the red circle is our 0,0 point, where I'm standing. The blue circle is 300 units above us and at what I would assume is a 0 degree's angle. I want to know, how I can find a find the x,y for a point in this chart using the angle of my choice as well as a certain distance of my choice.
I would want to know how to find the x,y of the green circle which is lets say 225 degrees and 500 units away.
So I assume I have to figure out a way to transpose a circle that is 500 units away from 0,0 at all points than pick a place on that circle based on the angle I want? But yeah no idea where to go from there.
A point on a plane can be expressed in two main mathematical representations, cartesian (thus x,y
) and polar : using a distance from the center and an angle. Typically r
and a greek letter, but let's use w
.
Definitions
Under common conventions, r is the distance from the center (0,0) to your point, and angles are measured going counterclockwise (for positive values, clockwise for negative), with the 0 being the horizontal on the right hand side.
Remarks
Note a few things about angles in polar representations :
angles can be expressed with radians as well, with π being the same angle as 180°, thus π/2 90° and so on. π=3.14 (approx.) is defined by 2π=the perimeter of a circle of radius 1.
angles can be represented modulo a full circle. A full circle is either 2π or 360°, thus +90° is the same as -270°, and +180° and -180° are the same, as well as 3π/4 and -5π/4, 2π and 0, 360° and 0°, etc. You can consider angles between [-π,π] (that is [-180,180]) or [0,2π] (i.e. [0,360]), or not restrain them at all, it doesn't matter.
when your point is in the center (r=0) then the angle w is not really defined.
r is by definition always positive. If r is negative, you can change its sign and add half a turn (π or 180°) to get coordinates for the same point.
Points on your graph
red : x=0, y=0 or r=0 w= any value
blue : x=0, y=300 or r=300 and w=90°
green : x=-400, y=-400 or r=-565 and w=225° (approximate values, I didn't do the actual measurements)
Note that for the blue point you can have w=-270°, and for the green w=-135°, etc.
Going from one representation to the other
Finally, you need trigonometry formulas to go back and forth between representations. The easier transformation is from polar to cartesian :
x=r*cos(w)
y=r*sin(w)
Since cos²+sin²=1, pythagoras, and so on, you can see that x² + y² = r²cos²(w) + r²sin²(w) = r²
, thus to get r, use :
r=sqrt(x²+y²)
And finally to get the angle, we use cos/sin = tan
where tan is another trigonometry function. From y/x = r sin(w) / (r cos(w)) = tan(w)
, you get :
w = arctan(y/x) [mod π]
tan is a function modulo π, instead of 2π. arctan simply means the inverse of the function tan, and is sometimes written tan^-1 or atan.
By inverting the tangent, you get a result betweeen -π/2 and π/2 (or -90° and 90°) : you need to eventually add π to your result. This is done for angles between [π/2,π] and [-π,π/2] ([90,180] and [-180,-90]). These values are caracterized by the sign of the cos : since x = r cos(w)
you know x is negative on all these angles. Try looking where these angles are on your graph, it's really straightforward. Thus :
w = arctan(y/x) + (π if x < 0)
Finally, you can not divide by x if it is 0. In that corner case, you have
if y > 0,
w = π/2
if y < 0,
w = -π/2
这篇关于基于角度和距离在空间中查找2D点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!