Differences From Artifact [959cda21c7e42a70]:
- File
_lib/geo/area.cpp
- 2011-02-23 09:21:16 - part of checkin [4fd800b3a8] on branch trunk - Copied from private svn repository. (user: kinaba) [annotate]
- File
lib/geo/area.cpp
- 2011-02-23 11:18:09 - part of checkin [23dfcca431] on branch trunk - renamed _lib to lib (user: kinaba) [annotate]
To Artifact [a5ea821173c9c755]:
- File
lib/geo/area.cpp
- 2013-06-30 08:35:05 - part of checkin [07ad2e1283] on branch trunk - Geocon library update. (user: kinaba) [annotate]
3 // O(N) 3 // O(N)
4 // 4 //
5 // Verified by 5 // Verified by
6 // - SRM 337 Div1 LV3 6 // - SRM 337 Div1 LV3
7 // - SRM 486 Div1 LV3 7 // - SRM 486 Div1 LV3
8 //------------------------------------------------------------- 8 //-------------------------------------------------------------
9 9
10 double outer_prod( pt a, pt b ) | 10 double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); }
11 { <
12 return (a.real()*b.imag() - b.real()*a.imag())/2; <
13 } <
14 11
15 double area( const vector<pt>& q ) 12 double area( const vector<pt>& q )
16 { 13 {
17 double a = 0.0; 14 double a = 0.0;
18 15
19 pt o = q[0]; 16 pt o = q[0];
20 for(int i=1; i+1<q.size(); ++i) 17 for(int i=1; i+1<q.size(); ++i)
21 a += outer_prod(q[i]-o, q[i+1]-o); 18 a += outer_prod(q[i]-o, q[i+1]-o);
22 return abs(a) / 2; 19 return abs(a) / 2;
23 } 20 }