Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用点积求两线段的夹角,精度误差导致调用acos时的参数略小于-1.0,返回了nan,大家引以为鉴QAQ

Posted by Leefir at 2017-06-10 19:23:42 on Problem 1113 and last updated at 2017-06-10 19:30:45
(因为求凸包时允许了三点共线的存在,所以有-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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator