将欧几里德距离转换为曼哈顿距离c#
我发现了一个代码,它对我实现*非常有用。但我面临一个问题。 我需要计算曼哈顿距离,我试图实现一个,但它不起作用。这段代码提供了欧几里得距离的计算将欧几里德距离转换为曼哈顿距离c#,c#,a-star,C#,A Star,我发现了一个代码,它对我实现*非常有用。但我面临一个问题。 我需要计算曼哈顿距离,我试图实现一个,但它不起作用。这段代码提供了欧几里得距离的计算 public Node(Node parentNode, Node goalNode, int gCost,int x, int y) { this.parentNode = parentNode; this._goalNode = goalNode; this.gCost = gCost;
public Node(Node parentNode, Node goalNode, int gCost,int x, int y)
{
this.parentNode = parentNode;
this._goalNode = goalNode;
this.gCost = gCost;
this.x=x;
this.y=y;
InitNode();
}
private void InitNode()
{
this.g = (parentNode!=null)? this.parentNode.g + gCost:gCost;
this.h = (_goalNode!=null)? (int) Euclidean_H():0;
}
private double Euclidean_H()
{
double xd = this.x - this._goalNode .x ;
double yd = this.y - this._goalNode .y ;
return Math.Sqrt((xd*xd) + (yd*yd));
}
代码使用c#。
多谢各位 A和B之间的曼哈顿距离(又称L1标准)为 当A和B之间的欧几里得1(又称L2范数)为 其中a[i],b[i]是a和b点的对应坐标。 所以代码可能是
private double Manhattan_H()
{
double xd = this.x - this._goalNode.x;
double yd = this.y - this._goalNode.y;
return Math.Abs(xd) + Math.Abs(yd);
}
A和B之间的曼哈顿距离(又称L1标准)为 当A和B之间的欧几里得1(又称L2范数)为 其中a[i],b[i]是a和b点的对应坐标。 所以代码可能是
private double Manhattan_H()
{
double xd = this.x - this._goalNode.x;
double yd = this.y - this._goalNode.y;
return Math.Abs(xd) + Math.Abs(yd);
}
我做的第一次搜索-有一个完全相同的问题-有一个很好的解决方案..我真的搜索了,但我找不到。谢谢你我做的第一次搜索-有一个完全相同的问题-有一个伟大的解决方案..我真的搜索了,但我找不到。非常感谢。
private double Manhattan_H()
{
double xd = this.x - this._goalNode.x;
double yd = this.y - this._goalNode.y;
return Math.Abs(xd) + Math.Abs(yd);
}