本文目录一览:
c语言编程
第一个直线方程y = a*x + b
第二个直线方程y = c*x + d
点的坐标(x,y)
#includestdio.h
#includemath.h
void xiangJiao(int a, int b, int c, int d);
void pingXing(int a, int b, int c, int d);
void dianDaoXian(int x, int y, int a, int b);
int main()
{
// 下班了。。。调用你自己写把,有不明白的uewing@126.com找我
// 调用要判断直线是否相交,是否平行等等
getch();
return 0;
}
void xiangJiao(int a, int b, int c, int d)
{
printf("相交点x坐标:%d\n", (d - b) / (a - c) );
printf("相交点y坐标:%d\n", ((d - b) / (a - c))*a + b );
}
void pingXing(int a, int b, int c, int d)
{
printf("两直线距离:%d", abs(d - b) );
}
void dianDaoXian(int x, int y, int a, int b)
{
int newA, newB, jiaodianX, jiaodianY;
// 求出垂直直线方程
newA = -(1/a);
newB = y + (1/a)*x;
// 求出新直线与原直线焦点
jiaodianX = (newB - b) / (a - newA);
jiaodianY = ((newB - b) / (a - newA))*a + b;
// 求出距离
int distance, tempX, tempY;
tempY = jiaodianY - y;
tempX = jiaodianX - x;
distance = sqrt(tempY*tempY + tempX*tempX);
printf("点到直线距离为:%d\n", distance);
}
谁能提供,点到直线的距离公式 C语言程序
设点(x0,y0) ,直线为ax+by+c=0
则距离为fabs(ax0+by0+c)/sqrt(a*a+b*b)
前提是在文件前面加上#include math.h
求一C++程序:计算点到直线的距离?
在Windows XP+VC++6.0下编译通过并正常运行
我的测试程序是用默认参数值初始化的
当然,你可以改为:
Point P(2,3);
Line L(1,2,3);
其它的都不变
懂了么?
#includeiostream
#includecmath
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(s0)
return s;
else
return -s;
}
int main()
{
Point P;//这相当于 Point P(0,0);
Line L;//相当于 Line L(1,1,1);
coutdist(P,L)endl;
return 0;
}