I am trying to find the tangent lines from a given point outside a closed curve (not on the curve). The curve is defined as 2D x and y coordinates of points,shaped like an irregular ellipse for example.
If given a point by the user: (x0,y0) = (-30,80), how can I know the tangent points (obviously closest point among discrete points from the smooth curve) on curve (i.e. tangent lines from (x0,y0) to curve)?
One possibility is to use numerical differentiation to find the tangent line at every point, and decide whether it passes "close enough" to the given point. However, one has to think hard about "close enough" to avoid getting either no matches or too many.
Here is another approach: consider the unit vectors pointing from the given point (x0,y0) to the points on the curve. Find the largest gap between them (the command convhull helps here). The vectors on both sides of the gap determine tangent lines.
In general this will find only two tangent lines, not all of them. But if the curve is convex, there are only two tangent lines anyway.
Here is an example of the tricky situations where the given point is within the convex hull of the curve.
The code that produced the above picture:
Another approach, which works fine if (x0,y0) is not within the convex hull of the curve.
Use
convhull
to find the convex hull of the union of the curve and of the given points(x0,y0)
. The two edges of the convex hull that are incident to(x0,y0)
are tangent to the curve:The code that produced the above picture: