mathtools.cs
来自「两种AstarPathFinder 一种DijkstraPathfinder 」· CS 代码 · 共 44 行
CS
44 行
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace PathFinder
{
class MathTools
{
/// <summary>
/// 返回两点间的直线距离
/// </summary>
/// <param name="from">起点</param>
/// <param name="to">终点</param>
/// <returns>距离</returns>
static public double DirectDistance(Point from, Point to)
{
return System.Math.Pow((from.X - to.X) * (from.X - to.X) + (from.Y - to.Y) * (from.Y - to.Y), 0.5);
}
/// <summary>
/// 算平方的距离
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
static public int SquareDistance(Point from, Point to)
{
return (from.X - to.X) * (from.X - to.X) + (from.Y - to.Y) * (from.Y - to.Y);
}
/// <summary>
/// 返回两点间的欧式几何距离
/// </summary>
/// <param name="from">起点</param>
/// <param name="to">终点</param>
/// <returns>距离</returns>
static public double MDistance(Point from, Point to)
{
return System.Math.Abs(from.X - to.X) + System.Math.Abs(from.Y - to.Y);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?