C#径处理算法从一点移动的对象(​​X,Y)为点(X,Y) [英] C# Pathing algorithm for moving a object from point(X, Y) to point(X, Y)

查看:276
本文介绍了C#径处理算法从一点移动的对象(​​X,Y)为点(X,Y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于它可以向前移动一个对象,后,左,右,在一个给定的X,Y点。如何使用给定的运动力学以最有效的和人类自然的方式在对象有效地引导到一个X,Y点

目的是提供实时的运动,你可以告诉他们startMoving |方向|()和stopMoving |方向|()。虽然作为一个附加的捻和上部分我有麻烦,是对象的衬面是从来没有已知的,只有其当前位置是已知的,所以该算法必须检测的方向。物体的位置在一个单独的线程被更新在500-1second间隔。阿请求以更新算法中所处的位置作出的任何一点进行的,但它不是立即可用的算法必须保持在考虑。是完全可以接受的,但是可能没有必要做这样的事情requestAndWaitForCoordUpdate()。

此外,没有障碍的出现,我们可以假设你是一个主要为开飞机,流浪到远处的路径之间的直接直线,你可能会遇到的障碍。它是安全的假设,1/4的目标和源之间的距离,应在宽度上提供一个给定的直接路径。

我也想提一下,我不知道A * applys在这种情况下,如果是这样我不能确定如何执行给定的约束。这里唯一的真正变量是对象的面

下面是一些例子code:

 公众诠释[] currentCoords;
公共无效移动(){
  currentCoords [0] = 1005; //开始y坐标
  currentCoords [1] = 1007; //启动X坐标
  MOVETO(1050,1025);
}

公共无效MOVETO(INT X,int y)对{
  ... 怎么样?
}

公共无效threadUpdatingCoords(){
   ...定期检查源坐标更新
   ... 200毫秒和1000毫秒之间相隔。
}
 

解决方案

要计算你应该使用A *算法的最佳路径。但是这样做的最有人情味的方式,你让只是它走,并采取随机方向。除非这是一个聪明的人,他就坚持他的右手在墙上,一直走,而不会失去联系。最终你会到达目的地

人类效率不高,这是随机的。 A *是不是随机的,它是有效的。

Given a object which may move forward, backward, left and right at a given X,Y point. How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way.

The object is available for movement in real time, you may tell them to "startMoving|Direction|()" and "stopMoving|Direction|()". Though as a additional twist and the part I am having trouble with, is the facing of the object is never known, only its current location is known, so the algorithm must "detect" direction. The location of the object is updated in a separate thread in 500-1second intervals. A "Request" to update the location within the algorithm made be made at any point, but it is not immediately available and the algorithm must keep that in consideration. Doing something like requestAndWaitForCoordUpdate() is perfectly acceptable, however likely not needed.

In addition, no obstacles appear, it can be assumed you are on a MOSTLY open plane, stray to far from the direct straight line between the paths and you may run into obstacles. It is safe to assume that 1/4th the distance between a target and source, should be available in width on a given direct path.

I would also mention I am not sure A* applys in this scenario, if it does I am unsure how to implement it given the constraints. The only real variable here is the facing of the object.

Here is some example code:

public int[] currentCoords;
public void movement() {
  currentCoords[0] = 1005; // starting y coord
  currentCoords[1] = 1007; // starting x coord
  moveTo(1050, 1025);
}

public void moveTo(int x, int y) {
  ... how?
}

public void threadUpdatingCoords() {
   ... periodically check for source coord updates
   ... between 200ms and 1000ms apart.
}

解决方案

To calculate the optimal route you should use A* algorithm. However to do it in the most human way, you just let it walk and take random directions. Unless it's a smart human, he'll just stick his right hand to the wall and keep walking without losing touch: eventually you will reach your destination.

Human isn't efficient, it's random. A* isn't random, it's efficient.

这篇关于C#径处理算法从一点移动的对象(​​X,Y)为点(X,Y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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