turf.polygonTangents
What is turf.polygonTangents?
turf.polygonTangents takes an external Point and a Polygon (or MultiPolygon) and returns the two vertices on the polygon's ring where tangent lines from the point touch the shape. The output is a FeatureCollection containing exactly two Point features.
turf.polygonTangents(point, polygon) → FeatureCollection<Point>When would you use turf.polygonTangents?
Use turf.polygonTangents when drawing "field of view" or "shadow" cones from a reference point toward a polygon — useful for visibility analysis, shadow casting, or drawing lines-of-sight from an observer to a footprint. On MapLibre it is a clean way to render sightlines from a selected marker to a building polygon.
It is also useful for computing minimum and maximum bearings from an observer to a polygon, which you can feed into turf.sector to draw a wedge covering the polygon from that viewpoint.
undefinedFAQs
What happens if the point is inside the polygon?
Tangents are undefined for interior points — the function may return vertices but they will not represent a meaningful tangent. Validate with turf.booleanPointInPolygon first if the input source is untrusted.
Does it work on MultiPolygon features?
Yes — the function traverses all rings and returns the global tangent vertices across the entire multipolygon.
How do I install just polygonTangents?
npm install @turf/polygon-tangents. It depends on @turf/invariant, @turf/helpers, and @turf/boolean-point-in-polygon.
Are the tangent points interpolated or vertex-snapped?
They are existing vertices of the polygon ring, not interpolated positions along edges. If you need true tangent lines for smoothly curved shapes, densify the ring with turf.lineChunk first.