求一C++程序:计算点到直线的距离?
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 23:28:53
求一C++程序:计算点到直线的距离?
已知点(X,Y)到直线ax+by+y=0的计算公式为:
d=|(ax+by+c)/sqrt(a^2+b^2)| .分别定义一个point类和line类,利用全局函数dist计算一个点到一个直线的距离?
一楼的:你的方法 程序都对
但没有用到我给的公式
三楼:你的初始化再那里?我没有看懂
已知点(X,Y)到直线ax+by+y=0的计算公式为:
d=|(ax+by+c)/sqrt(a^2+b^2)| .分别定义一个point类和line类,利用全局函数dist计算一个点到一个直线的距离?
一楼的:你的方法 程序都对
但没有用到我给的公式
三楼:你的初始化再那里?我没有看懂
在Windows XP+VC++6.0下编译通过并正常运行
我的测试程序是用默认参数值初始化的
当然,你可以改为:
Point P(2,3);
Line L(1,2,3);
其它的都不变
懂了么?
#include
#include
using namespace std;
class Line;//声明类Line,因为Point类中声明友元函数friend dist(Point P,Line L)用到该类
class Point
{
private:
double x;
double y;
public:
Point(double xx=0,double yy=0)
{
x=xx;
y=xx;
}
friend double dist(Point P,Line L);
};
class Line
{
private:
double a;
double b;
double c;
public:
Line(double aa=1,double bb=1,double cc=1)
{
a=aa;
b=bb;
c=cc;
}
friend double dist(Point P,Line L);
};
double dist(Point P,Line L)
{
double s;
s=(L.a*P.x+L.b*P.y+L.c)/sqrt(L.a*L.a+L.b*L.b);
if(s>0)
return s;
else
return -s;
}
int main()
{
Point P;//这相当于 Point P(0,0);
Line L;//相当于 Line L(1,1,1);
cout
我的测试程序是用默认参数值初始化的
当然,你可以改为:
Point P(2,3);
Line L(1,2,3);
其它的都不变
懂了么?
#include
#include
using namespace std;
class Line;//声明类Line,因为Point类中声明友元函数friend dist(Point P,Line L)用到该类
class Point
{
private:
double x;
double y;
public:
Point(double xx=0,double yy=0)
{
x=xx;
y=xx;
}
friend double dist(Point P,Line L);
};
class Line
{
private:
double a;
double b;
double c;
public:
Line(double aa=1,double bb=1,double cc=1)
{
a=aa;
b=bb;
c=cc;
}
friend double dist(Point P,Line L);
};
double dist(Point P,Line L)
{
double s;
s=(L.a*P.x+L.b*P.y+L.c)/sqrt(L.a*L.a+L.b*L.b);
if(s>0)
return s;
else
return -s;
}
int main()
{
Point P;//这相当于 Point P(0,0);
Line L;//相当于 Line L(1,1,1);
cout
求一个计算点到直线的距离的卡西欧5800程序
平面坐标系中,点到直线距离的计算?求,
谁能提供,点到直线的距离公式 C语言程序
已知点P(x0,y0)和直线l:Ax+By+C=0,求点P到直线的距离
卡西欧5800点到直线距离程序 传哈
点到直线的距离
解析几何里的直线问题1.已知一直线方程与直线外一点坐标,求该点到直线距离.2.已知一直线方程与一点坐标,求该点到直线的垂
黄金分割计算题目已知线段AB长80CM左边有一黄金分割点D右边有一黄金分割点C求C到b d到a 的距离!
(圆心)点到直线的距离怎样求??
圆曲线计算已知圆曲线两点之间直线距离和半径,求出两点间直线到弧线任意点的垂直距离.求公式和解说.
两平行间的距离公式?点到直线的距离如果计算?
已知点A(0,1)B(5,-2)C(3,5).求点A到直线BC的距离,求的距离和三角形ABC的面积