试试这个单个三角形的情形:
程序代码:
#include<stdio.h> #include<math.h> struct point { double x; double y; }; int area(float m,float n,float t) { float p,S; p=(m+n+t)/2; S=sqrt(p*(p-m)*(p-n)*(p-t)); return S; } main() { struct point a,b,c,d,p; float AB,BC,AC; float S0,S1,S2,S3; float DA,DB,DC; scanf("%lf,%lf\n",&a.x,&a.y); scanf("%lf,%lf\n",&b.x,&b.y); scanf("%lf,%lf\n",&c.x,&c.y); AB=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); BC=sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y)); AC=sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y)); if((AB+BC)>AC && (AB+AC)>BC && (AC+BC)>AB){ printf("请输入D点坐标:\n"); scanf("%lf,%lf\n",&d.x,&d.y); DA=sqrt((d.x-a.x)*(d.x-a.x)+(d.y-a.y)+(d.y-a.y)); DB=sqrt((d.x-b.x)*(d.x-b.x)+(d.y-b.y)+(d.y-b.y)); DC=sqrt((d.x-c.x)*(d.x-c.x)+(d.y-c.y)+(d.y-c.y)); S0=area(AB,BC,AC); S1=area(DA,DB,AB); S2=area(DA,DC,AC); S3=area(DB,DC,BC); if(S1+S2+S3-S0==0) printf("点D位于三角形bai内部\n"); else printf("点D位于三角形外部\n"); } else printf("不能构成三角形"); }