重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#include
创新互联建站主要从事网站建设、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务安康,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
#include
#include
int
main()
{
struct
dian
{
float
x;
float
y;
}a,b,c;
float
m;
int
k;
printf("计算两点距离请输入2,判断三点共线请按3\n");
scanf("%d",k);
if(k==2)
{
printf("请输入第一个点的坐标\n");
scanf("%f%f",a.x,a.y);
printf("请输入第二个点的坐标\n");
scanf("%f%f",b.x,b.y);
m=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
printf("distance=%f\n",m);
}
else
if(k==3)
{
printf("请输入第一个点的坐标\n");
scanf("%f%f",a.x,a.y);
printf("请输入第二个点的坐标\n");
scanf("%f%f",b.x,b.y);
printf("请输入第三个点的坐标\n");
scanf("%f%f",c.x,c.y);
{
if(((b.y-a.y)/(b.x-a.x))==((c.y-a.y)/(c.x-a.x)))
printf("这三点共线\n");
else
printf("这三点不共线\n");
}
}
else
{
printf("system
wrong\n");
}
system
("pause");
return
0;
}
#include "iostream.h"
void main()
{
double x1,y1;
double x2,y2;
double x3,y3;
cout"请输入第一个点的坐标(X,Y)";
cinx1y1;
cout"请输入第二个点的坐标(X,Y)";
cinx2y2;
cout"请输入第三个点的坐标(X,Y)";
cinx3y3;
if(((y2-y1)/(x2-x1)-(y3-y1)/(x3-x1))==0)
cout"yes"endl;
else
cout"no"endl;
}
#include "stdafx.h"
#includestdio.h
#includemath.h
int main()
{
float x1, x2, x3, y1, y2, y3;
scanf("(%f,%f)\n", x1, y1);
scanf("(%f,%f)\n", x2, y2);
scanf("(%f,%f)", x3, y3);
if ((y1 - y2) / (x1 - x2) == (y2 - y3) / (x2 - x3))
printf("在同一直线上。\n");
else printf("不在同一直线上。\n");
return 0;
}
举例:输入
(1,2)
(2,4)
(4,8)
/***************
* 已知三点求圆的 get_circle() 函数
* x1, y1为第一个点的坐标,以此类推
* r为求出的半径,x0, y0为圆心坐标
* 调用函数之前应先检查三点是否共线 否则会弹出被零除的错误
***************/
# include math.h
void get_circle(double x1, double y1, double x2, double y2, double x3, double y3, double* r, double* x0, double* y0)
{
double m1, n1, m2, n2, a1, b1, a2, b2;
m1 = (x1 + x3) / 2;
n1 = (y1 + y3) / 2;
m2 = (x2 + x3) / 2;
n2 = (y2 + y3) / 2;
a1 = (y3 - y1) / (x3 - x1);
b1 = n1 - a1*m1;
a2 = (y3 - y2) / (x3 - x2);
b2 = n2 - a2*m2;
*x0 = (b2 - b1) / (a1 - a2);
*y0 = a1 * *x0 + b1;
*r = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
return;
}
希望对你有帮助!