Description
Recently in Farland, a country in Asia, a famous scientist Mr. Log Archeo has discovered ancient pyramids. But unlike those in Egypt and Central America, they have triangular (not rectangular) foundation. That is, they are tetrahedrons in mathematical sense. In order to find out some important facts about the early society of the country (it is widely believed that the pyramid sizes are in tight connection with Farland ancient calendar), Mr. Archeo needs to know the volume of the pyramids. Unluckily, he has reliable data about their edge lengths only. Please, help him!
Input
The file contains six positive integer numbers not exceeding 1000 separated by spaces, each number is one of the edge lengths of the pyramid ABCD. The order of the edges is the following: AB, AC, AD, BC, BD, CD.
Output
A real number -- the volume printed accurate to four digits after decimal point.
Sample Input
1000 1000 1000 3 4 5
Sample Output
1999.9938
题目链接:http://poj.org/problem?id=2208
题目大意:很简单,给你四面体的6个棱长,计算四面体的体积。
题目思路:给大家一个强力的推导公式,1/6*A*B*C*sqrt(1+2cosa*cosb*cosc-cosa^2-cos b^2-cos c^2),其中A,B,C为侧棱长,a,b,c为侧棱之间的夹角,即三个侧面顶角,至于怎么推,我也不知道,嘿嘿,记住就行啦。
实现代码:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double AB,AC,AD,BC,BD,CD;
double a,b,c,V;
while(cin>>AB>>AC>>AD>>BC>>BD>>CD)
{
a=(AD*AD+BD*BD-AB*AB)/(2*AD*BD);
b=(CD*CD+BD*BD-BC*BC)/(2*CD*BD);
c=(AD*AD+CD*CD-AC*AC)/(2*AD*CD);
V=1/6.0*AD*BD*CD*sqrt(1+2*a*b*c-a*a-b*b-c*c);
printf("%.4lf\n",V);
}
return 0;
}