#include
#include
float dis(float x1,float y1,float x2,float y2)
{
float dx,dy;
dx=x1-x2;dy=y1-y2;
return sqrt(dx*dx+dy*dy);
}
int main()
{
float x1,x2,x3,y1,y2,y3,p,s,a,b,c;
scanf("%f %f",&x1,&y1);
scanf("%f %f",&x2,&y2);
scanf("%f %f",&x3,&y3);
a=dis(x1,y1,x2,y2);
b=dis(x2,y2,x3,y3);
c=dis(x1,y1,x3,y3);
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("%f\n",s);
return 0;
}
运行结果
//三个顶点坐标是6个参数。。。
#include
#include
double S_triangle(double ax,double ay,double bx,double by,double cx,double cy)
{
double mx=cx-ax,my=cy-ay,nx=bx-ax,ny=by-ay;
double Lm= sqrt(mx*mx+my*my),Ln= sqrt(nx*nx+ny*ny),cosA=(mx*nx+my*ny)/Lm/Ln;
double sinA=sqrt(1-cosA*cosA);
double S_tri=0.5*Lm*Ln*sinA;
if(S_tri>=0)return S_tri;
else return (-1*S_tri);
}
void main()
{
double S_tri,ax,ay,bx,by,cx,cy;
ax=1;
ay=1;//第一个点的横纵坐标
bx=2;
by=2;//第二个点的横纵坐标
cx=1;
cy=2;//第三个点的横纵坐标
S_tri=S_triangle(ax,ay,bx,by,cx,cy);
printf("S_triangle=%lf",S_tri);
}
#include
#include
double S_triangle(double ax,double ay,double bx,double by,double cx,double cy)
{
double mx=cx-ax,my=cy-ay,nx=bx-ax,ny=by-ay;
double Lm= sqrt(mx*mx+my*my),Ln= sqrt(nx*nx+ny*ny),cosA=(mx*nx+my*ny)/Lm/Ln;
double sinA=sqrt(1-cosA*cosA);
double S_tri=0.5*Lm*Ln*sinA;
if(S_tri>=0)return S_tri;
else return (-1*S_tri);
}
void main()
{
double S_tri,ax,ay,bx,by,cx,cy;
ax=1;
ay=1;//第一个点的横纵坐标
bx=2;
by=2;//第二个点的横纵坐标
cx=1;
cy=2;//第三个点的横纵坐标
S_tri=S_triangle(ax,ay,bx,by,cx,cy);
printf("S_triangle=%lf",S_tri);
}