程序代码:
class Program
{
static void Main(string[] args)
{
Point p = new Point(0.0, 0.0)
{
//弧度和角度转换
Radian = Math.PI / 180 * 30.0,
Speed = 1.0
};
Console.WriteLine("P当前坐标,X:{0},Y:{1}", p.X, p.Y);
p.Move(10.0);
Console.WriteLine("P当前坐标,X:{0},Y:{1}", p.X, p.Y);
p.Move(10);
Console.WriteLine("P当前坐标,X:{0},Y:{1}", p.X, p.Y);
}
}
class Point
{
double x = 0.0;
double y = 0.0;
double speed = 0.0;
double radian = 0.0;
public Point(double x = 0.0, double y = 0.0)
{
this.x = x;
this.y = y;
}
public double X
{
get { return Math.Round(x, 2); }
set { x = value; }
}
public double Y
{
get { return Math.Round(y, 2); }
set { y = value; }
}
public double Speed
{
get { return speed; }
set { speed = value; }
}
/// <summary>
/// 弧度,非角度
/// </summary>
public double Radian
{
get { return radian; }
set { radian = value; }
}
/// <summary>
/// 移动
/// </summary>
/// <param name="time">移动时间</param>
public void Move(double time)
{
double s = speed * time;
x += s * Math.Sin(radian);
y += s * Math.Cos(radian);
}
}