1. 输入三点的坐标,输出该三角形的面积
海伦公式————
//已知三点坐标求三角形面积 #include<iostream> #include<cstdio> #include<cmath> using namespace std; #define MAX 100 int main() { int x1,y1,x2,y2,x3,y3,i=0; double a,b,c,s,p,ss[MAX]; cin>>x1>>y1>>x2>>y2>>x3>>y3; while(x1 || y1 || x2 || y2 || x3 || y3) { a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); c=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); p=(a+b+c)*0.5; s=sqrt(p*(p-a)*(p-b)*(p-c)); ss[i]=s; i++; cin>>x1>>y1>>x2>>y2>>x3>>y3; } int n=i; for(int i=0; i<n; i++) printf("%.1f\n",ss[i]); return 0; }
2. 输入三角形三个顶点的坐标
判断该输入顺序是逆时针还是顺时针
纯解析几何题有木有!!!
//已知三点坐标判断是逆时针输入还是顺时针输入 #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { int x1,y1,x2,y2,x3,y3,i=0; double a,b,c,s,p; cin>>x1>>y1>>x2>>y2>>x3>>y3; while(x1 || y1 || x2 || y2 || x3 || y3) { cout<<((x3-x1)*(y2-y1)/(x2-x1)+y1>y3)<<endl; cin>>x1>>y1>>x2>>y2>>x3>>y3; } return 0; }
原文:http://www.cnblogs.com/fengyanlover/p/5051180.html