In one of the last stages of the 3rd Universal Cup, there was a not-so-nice problem (it required using fractions) that involved an algorithm for which I hadn't found a tutorial or much information on popular blogs. This approach was developed by me, and I appreciate any feedback on it or its implementation.
Parameters
- The polygon is convex
- The point is not strictly inside
What are the tangents to a polygon from a point?
The tangents of a polygon with respect to a point are the lines that pass through the point outside the polygon and touch the polygon at exactly one vertex or along one side, without crossing its interior.
Why are these useful?
- Solve difficult problems
- Solve problems related to visibility or trajectory where the polygon cannot be crossed.
Algorithm
To describe the algorithm, only the left tangent will be specified. At the end, it will be indicated what changes with respect to the right tangent.
The left tangent can be described using the cross product. For a point $$$P_i$$$ and the point $$$p$$$ (for which the tangents are computed), it can be considered the tangent if the cross product with respect to points $$$P_{i+1}$$$ and $$$P_{i-1}$$$ is less than or equal to zero: