文章
15
粉丝
0
获赞
64
访问
3.9k
知道三点坐标用海伦公式求三角形面积
1.利用两点间距离公式,算出三条边的长度 a、b、c
2.计算半周长p = (a + b + c) /2
3.面积S = sqrt(p * (p - a) * (p - b) * (p - c))
#include<bits/stdc++.h>
using namespace std;
//求两点间的距离
double get_dist(double x1, double x2, double y1, double y2){
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int main(){
double x1, y1, x2, y2, x3, y3;
while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3){
double a = get_dist(x1, x2, y1, y2);
double b = get_dist(x1, x3, y1, y3);
double c = get_dist(x2, x3, y2, y3);
double p = (a + b + c) / 2;
//海伦公式
double area = sqrt(p * (p - a) * (p - b) * (p - c));
printf("%.2f\n&...
登录后发布评论
暂无评论,来抢沙发