
用C#的构造函数和属性如何求一个三维空间的两个点的距离
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
1个回答
展开全部
public class Distance
{
public Distance()
{ }
public static double getDistance(Point p1,Point p2)
{
return Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z));
}
class Point
{
int x; int y; int z;
public Point(int x,int y, int z)
{
this.x=x;
this.y=y;
this.z=z;
}
}
}
To be continue
更多追问追答
追问
能不能再具体点
追答
字数超出最大允许值,请删减!我去!
/// <summary>
/// 构造函数
/// </summary>
class Point
{
private int x;
/// <summary>
/// 属性X
/// </summary>
public int X
{
get { return x; }
set { x = value; }
}
private int y;
/// <summary>
/// 属性Y
/// </summary>
public int Y
{
get { return y; }
set { y = value; }
}
private int z;
/// <summary>
/// 属性Z
/// </summary>
public int Z
{
get { return z; }
set { z = value; }
}
public Point(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
/// <summary>
/// 测试方法
/// </summary>
public void Test()
{
Point p1 = new Point(1, 1, 1);
Point p2 = new Point(2, 2, 2);
double d = Distance.getDistance(p1, p2);
Console.WriteLine("p1与p2点的距离为:" + d);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询