Convex hull

View inMAUIUWPWinUIWPFView on GitHub

Create a convex hull for a given set of points. The convex hull is a polygon with shortest perimeter that encloses a set of points. As a visual analogy, consider a set of points as nails in a board. The convex hull of the points would be like a rubber band stretched around the outermost nails.

Image of convex hull

Use case

A convex hull can be useful in collision detection. For example, when charting the position of two yacht fleets (with each vessel represented by a point), if their convex hulls have been precomputed, it is efficient to first check if their convex hulls intersect before computing their proximity point-by-point.

How to use the sample

Tap on the map to add points. Click the "Create Convex Hull" button to generate the convex hull of those points. Click the "Reset" button to start over.

How it works

  1. Create an input geometry such as a Multipoint object.
  2. Use GeometryEngine.ConvexHull(inputGeometry) to create a new Geometry object representing the convex hull of the input points. The returned geometry will either be a Point, Polyline, or Polygon based on the number of input points.

Relevant API

  • Geometry
  • GeometryEngine

Tags

convex hull, geometry, spatial analysis

Sample Code

ConvexHull.xamlConvexHull.xamlConvexHull.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<UserControl
    x:Class="ArcGIS.UWP.Samples.ConvexHull.ConvexHull"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <StackPanel>
                <TextBlock Text="Tap on the map in at least three places, then click 'Create convex hull'."
                           TextWrapping="Wrap" FontWeight="SemiBold" />
                <Button x:Name="ConvexHullButton"
                        Content="Create convex hull"
                        Margin="0,5,0,0"
                        HorizontalAlignment="Stretch"
                        Click="ConvexHullButton_Click" />
                <Button x:Name="ResetButton"
                        Content="Reset"
                        Margin="0,5,0,0"
                        HorizontalAlignment="Stretch"
                        Click="ResetButton_Click" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.