C#中 - 如何移动点给定的距离d(并得到一个新的坐标) [英] c# - how to move point a given distance d (and get a new coordinates)

查看:256
本文介绍了C#中 - 如何移动点给定的距离d(并得到一个新的坐标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜 我想知道是否有任何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

这篇关于C#中 - 如何移动点给定的距离d(并得到一个新的坐标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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