| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用点积求两线段的夹角,精度误差导致调用acos时的参数略小于-1.0,返回了nan,大家引以为鉴QAQ(因为求凸包时允许了三点共线的存在,所以有-1.0)
angle = acos(((a.x-b.x)*(c.x-b.x) + (a.y-b.y)*(c.y-b.y)) / dist(a, b) / dist(b, c));
((a.x-b.x)*(c.x-b.x) + (a.y-b.y)*(c.y-b.y)) / dist(a, b) / dist(b, c) 略小于-1.0
之后改成了
db angle(pii a, pii b, pii c){
db tmp = ((a.x-b.x)*(c.x-b.x) + (a.y-b.y)*(c.y-b.y)) / dist(a, b) / dist(b, c);
if(tmp < -1.0) tmp = -1.0;
if(tmp > 1.0) tmp = 1.0;
return acos(tmp);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator