喜 我想知道是否有任何efficent的方式来计算点的坐标(这是移动距离d从它的原始位置)。
Hi I was wondering if there is any efficent way to calculating coordinates of point (which was moved distance d from it's original location).
让我们说我有一个点P(0.3,0.5),我需要移动这一点上任意方向与距离d。
Let's say I have a point P(0.3,0.5) and I need to move that point random direction with distance d.
到目前为止,我做到了随机挑选新的X和Y坐标,我被检查,如果旧的和新的点之间的距离等于Ð。我当然知道,岂不等于太eficient办法做到这一点。 你会怎么做呢??
So far I did it by random picking new x and y coordinates and I was checking if distance between old and new point equals d. I do realize that is't too eficient way to do that. How would You do it ??
给定一个点(X1,Y1)
,我们希望找到一个随机点(x2,y2)
在离它的距离 D
。
Given a point (x1, y1)
, we want to find a "random" point (x2, y2)
at a distance d
from it.
选择一个随机的角度 THETA
。然后:
Pick a random angle theta
. Then:
x2 = x1 + d * cos(theta)
y2 = y1 + d * sin(theta)
这将是对半径 D
集中于(X1,Y1)的圆一个随机点
证明
Distance between (x1, y1) and (x2, y2)
= sqrt ( (x2 - x1) ^ 2 + (y2 - y1) ^ 2)
= sqrt ( d^2 * (sin^2 (theta) + cos^2 (theta) ) )
= d
您可能想看看:
极坐标系 距离公式 毕达哥拉斯三角恒等式 Polar coordinate system Distance Formula Pythagorean trigonometric identity