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.
Alternatively, for the square part, one can rotate the coordinate system so as to have the square aligned with the horizontal and vertical directions. Then it is enough to check each coordinate separately i.e. given a point (x, y) whether x is between x1 and x3 (all values after rotation), and similarly for y. In this case we operate with floating point numbers, and need to be careful with precision errors (use small epsilon when comparing numbers).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
A Circle and a Square
You are viewing a single comment's thread. Return to all comments →
Alternatively, for the square part, one can rotate the coordinate system so as to have the square aligned with the horizontal and vertical directions. Then it is enough to check each coordinate separately i.e. given a point (x, y) whether x is between x1 and x3 (all values after rotation), and similarly for y. In this case we operate with floating point numbers, and need to be careful with precision errors (use small epsilon when comparing numbers).