hdu 2036 一個數學的知識

一個求面積問題,用叉乘    ;

  • 如三角形面積       s=1/2*a×b =1/2*|a|*|b|*sinß;    
  • 這裏面有一個線代公式,求面積用的,雖然不知道,轉了這一題,大概會應用了;
  • 即多邊形任意兩點的叉積和的一半;    

/*o爲座標原點,向量OA叉乘向量OB的一半就是三角形OAB的面積
且面積有方向,若向量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);
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章