Computational Geometry - Maple Programming Help

 Computational Geometry

Maple 2018 contains a new Computational Geometry package, based on Qhull (http://www.qhull.org). It contains functionality for programmers who intend to apply computational methods to polygons and clouds of points.

$\mathrm{with}\left(\mathrm{ComputationalGeometry}\right)$

 $\left[{\mathrm{ConvexHull}}{,}{\mathrm{DelaunayTriangulation}}{,}{\mathrm{PolygonTriangulation}}{,}{\mathrm{VoronoiDiagram}}\right]$ (1)

The VoronoiDiagram command computes and plots the Voronoi diagram of a set of input points.

$m≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(40,2\right):\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}$

The ConvexHull command can also compute with sets of points in higher dimensions. Here we pick some random points in 3-D, where the x-coordinates, y-coordinates, and z-coordinates are chosen according to different probability distributions: the x-coordinates are the absolute values of samples from Student's t-distribution; the y-coordinates are sampled from a standard normal distribution; and the z-coordinates come from a geometric distribution.

 ${\mathrm{points}}{≔}\left[\begin{array}{c}{\mathrm{500 x 3}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (2)

The following example uses polygon data from a section of the built-in world map. This finds all land areas that intersect with the given viewport.

$\mathrm{numelems}\left(\mathrm{polygons}\right);$

 ${41}$ (3)

There are 41 polygons representing various elements of this map. Such polygons will be displayed throughout this example, using the procedure in the Code Edit Region below, along with additional code to help with colors.



Remove the polygon representing the background (and the oceans).

$\mathrm{numelems}\left(\mathrm{polygons}\right);$

 ${40}$ (4)

In this example, every other polygon has more than four vertices, so that is an easy criterion.

This first demonstration uses the ConvexHull command.

$\mathrm{ConvexHull}\left(\mathrm{polygons}\left[1\right]\right);$

 $\left[{192}{,}{147}{,}{146}{,}{115}{,}{112}{,}{111}{,}{86}{,}{85}{,}{84}{,}{82}{,}{74}{,}{12}{,}{11}{,}{268}{,}{267}{,}{228}{,}{217}{,}{216}{,}{215}{,}{195}\right]$ (5)

It returns the indices of the points occurring in a convex hull. You can easily show these convex hulls as follows:

For the rest of this document, you will work with a single polygon. Use the one for which the area of the convex hull is largest:

 ${\mathrm{mainlandCanada}}{≔}\left[\begin{array}{c}{\mathrm{272 x 2}}{\mathrm{Matrix}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (6)

The DelaunayTriangulation of a set of points subdivides the convex hull of these points into triangles in a way that avoids long and thin triangles as much as possible.

This overlay shows that some of the triangles fall inside the given polygon, and some fall outside. This is because the input is interpreted as a point cloud, not an ordered polygon.

A VoronoiDiagram is a diagram that shows the dual of a Delaunay triangulation.

The PolygonTriangulation command interprets its argument as a polygon, that is, an ordered sequence of points, in contrast with the other commands mentioned so far, which each interprets its argument as an unordered set of points. It subdivides this polygon into triangles, trying to avoid triangles that are long and narrow.