c# - 如何将点移动给定距离 d (并获取新坐标)
你好 我想知道是否有任何有效的方法来计算点的坐标(从原始位置移动了距离 d)。
假设我有一个点 P(0.3,0.5),我需要将该点随机方向移动距离 d。
到目前为止,我通过随机选取新的 x 和 y 坐标来完成此操作,并且检查新旧点之间的距离是否等于 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).
Let's say I have a point P(0.3,0.5) and I need to move that point random direction with distance d.
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 ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
给定一个点
(x1, y1)
,我们想要找到一个距离它d
的“随机”点(x2, y2)
。选择一个随机角度
theta
。那么:这将是一个以
(x1, y1)
为中心、半径为d
的圆上的随机点证明:
您可能想看看:
Given a point
(x1, y1)
, we want to find a "random" point(x2, y2)
at a distanced
from it.Pick a random angle
theta
. Then:This will be a random point on a circle of radius
d
centered at(x1, y1)
Proof:
You might want to look at:
其公式涉及基本的三角函数。
顺便说一句,角度应该以弧度为单位。
The formula for that involves basic trig functions.
By the way, angle should be in radians.
您需要解简单的方程:
You need to resolve simple equation:
如果点移动的方向没有限制,最简单的方法是仅沿一个轴移动。
因此,如果您必须将点移动 1 个单位的距离,则您的点 P(0.3,0.5) 可以简单地变为以下任一:
P(1.3,0.5),或
P(0.3,1.5)
If there is no constraint as to in which direction the point is to move, the easiest way is to move it along only one axis.
So, if you have to move the point by a distance of 1 unit, your point P(0.3,0.5), can simply become either of the following:
P(1.3,0.5), or
P(0.3,1.5)