CSU1403: 三角形面积

1403: 三角形面积

Time Limit: 1 Sec   Memory Limit: 128 MB   Special Judge
Submit: 176   Solved: 62
[ Submit][ Status][ Web Board]

Description

给出三维空间上的三个点,计算以这三个点为顶点的三角形的面积。

Input

输入的第一行包含一个整数T (T > 0),表示一共有T组测试数据。
每组数据占三行,每行各描述了一个点的坐标。点的坐标会以x y z的形式给出,表示这个点的坐标为(xyz),其中xyz均为[-100, 100]范围内的浮点数。

Output

对于每组测试数据,输出三角形的面积(和标准答案的误差不超过10-6即可)。

Sample Input

2
0 1 0
1 0 0
0 0 0
0 0.0 1.00
1.0 0.00 0
0.00 1.0 0

Sample Output

0.50
0.8660254


三角形面积公式S=0.5*A*B*sinC.利用余弦定理求出角度吧。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#include <ctime>
#define LL __int64
#define eps 1e-8
using namespace std;
struct point 
{
	double x,y,z;
	point(double x=0,double y=0,double z=0):x(x),y(y),z(z){} 
}a,b,c;
point operator - (point a,point b)
{
	return point(a.x-b.x,a.y-b.y,a.z-b.z);
}
double dis(point a,point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int main()
{
	int n;
	scanf("%d",&n);
	while (n--)
	{
		scanf("%lf%lf%lf",&a.x,&a.y,&a.z);
		scanf("%lf%lf%lf",&b.x,&b.y,&b.z);
		scanf("%lf%lf%lf",&c.x,&c.y,&c.z);
		double A=dis(a,b);
		double B=dis(b,c);
		double C=dis(a,c);
		double D=2*A*B;
		double ac=(A*A+B*B-C*C)/D;
		double sc=sqrt(1-ac*ac);
		double ans=0.5*A*B*sc;
		printf("%.6lf\n",ans);
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值