# Detect whether a polyline is falling within or intersecting with a polygon

**URL:** <https://community.cesium.com/t/detect-whether-a-polyline-is-falling-within-or-intersecting-with-a-polygon/22386>\
**Category:** CesiumJS\
**Created:** [February 15, 2023, 12:01pm UTC](https://community.cesium.com/t/detect-whether-a-polyline-is-falling-within-or-intersecting-with-a-polygon/22386 "2023-02-15T12:01:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [April 6, 2023, 2:45pm UTC](https://community.cesium.com/t/detect-whether-a-polyline-is-falling-within-or-intersecting-with-a-polygon/22386/2 "2023-04-06T14:45:55Z")

</div>

Whether or not a line intersects a polygon depends (in this case) on the _triangulation_ of the polygon.

Take a look at this example:

![Cesium Line Polygon](https://global.discourse-cdn.com/cesium/original/2X/7/73811c9706acf5e061c0903bc7c00189001106d8.png)

The green and the blue polygon consist of the same vertices, but are displayed at different places, and they are _triangulated_ differently, because the vertices are given in a different order. The red line intersects the green polygon. But it does not intersect the blue polygon.

Therefore, the only real “intersection test” that one can do is to intersect a line or line segment with a single _triangle_. This is offered in [`IntersectionTests.lineSegmentTriangle`](https://cesium.com/learn/cesiumjs/ref-doc/IntersectionTests.html#.lineSegmentTriangle).

(As far as I know, there is no “public” way of obtaining the triangles that are actually _rendered_ when rendering a polygon, though - related: [Getting polygons' rendered triangles' - #2 by sam.rothstein](https://community.cesium.com/t/getting-polygons-rendered-triangles/17258/2) )

* * *

A sandcastle that shows what’s also shown in the screenshot:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/#c=pVRdT9swFP0rVp9SKXWShg7ISrVSqu0BlQnYXggPdnJprDl2ZLutAuK/z/loxUqBiEVK5I9z7j0+J0kihTZozWADCp0hARs0A81WOf5drzlxL6nnMykMYQJU3Ot/jUUskppJfMtqGTOijB0REeIHJfMLWCoA7QxOfRcdBS4K/eqq2C03+Jh7MrLc0EVf9rnDjn1HB/qGHbiv+m7ZheTlUoqprdHYhkEYZhhoTNLUeYoF2mIiVM8QyhgoopKsjNAdsaqIdYMM7R3euw2iAPVTaltGih/AlpmJkFEraHdzYkAxwqOdbMmlwt+v5/MF3jCTTXmREcfHo37NeLbP55eiaYeYTt6IiXaI6fiNmOiwY98DMdHwM6/HXkznn42JWlXUVqY2Jhr8V0znl7/mnVLi9vv6SG+F2QkuWi06et+oqVKkbARr567hIjQ4rpy35zuq7XPRIPD/XWmQ9/12sGGpySIUbDesV7dlAbvm02aOF1eL+fuWXM8v9i1oT/0oZX4rnT0PGkjP7Y21KTlMtkf4xvJCKoNWijsYewbygtuO2qOr5A8YnOiaWkHH3kvqOGVrxNKzA783lHCitd15WHF+wx4h7k3GnsW/onJJUiaWV2tQnJQVLAsml80ixnjs2elhppGSU6L2Kv8F)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

---

_[View the full topic](https://community.cesium.com/t/detect-whether-a-polyline-is-falling-within-or-intersecting-with-a-polygon/22386)._
