We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I don't know why everybody here makes this problem too complicated by using Interior Triangle (Convex Hull) or Barycentric Coordinate. Just think about highschool math.
Hint: Calculate the area S of ABC, OAB, OAC and OBC. If O is inside ABC, then S_ABC = S_OAB + S_OAC + S_OBC.
Trick: To avoid numerical errors, use abs(S_ABC - S_OAB - S_OAC - S_OBC) < 1e-9 instead of S_ABC == S_OAB + S_OAC + S_OBC
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #102: Triangle containment
You are viewing a single comment's thread. Return to all comments →
I don't know why everybody here makes this problem too complicated by using Interior Triangle (Convex Hull) or Barycentric Coordinate. Just think about highschool math.
Hint: Calculate the area S of ABC, OAB, OAC and OBC. If O is inside ABC, then S_ABC = S_OAB + S_OAC + S_OBC.
Trick: To avoid numerical errors, use
abs(S_ABC - S_OAB - S_OAC - S_OBC) < 1e-9
instead ofS_ABC == S_OAB + S_OAC + S_OBC