一個求面積問題,用叉乘 ;
- 如三角形面積 s=1/2*a×b =1/2*|a|*|b|*sinß;
- 這裏面有一個線代公式,求面積用的,雖然不知道,轉了這一題,大概會應用了;
- 即多邊形任意兩點的叉積和的一半;
且面積有方向,若向量OB在向量OA的順時針方向,面積爲負,逆時針方向
則爲正。將所有以原點爲起點的向量依次叉乘,即能將非多邊形部分的面積抵消*/
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main()
{
int n;
int a[110],b[110];
while(cin>>n && n!=0)
{
for (int i=0;i<n;i++)
cin>>a[i]>>b[i];
a[n]=a[0];
b[n]=b[0];
double ans=0;
for (int j=0;j<n;j++)
ans += a[j]*b[j+1] - b[j]*a[j+1];
if (ans<0)
ans *= -1;
printf("%.1lf\n",ans/2);
}
}