# Efficient Algorithms to Test Digital Convexity

A set S ⊂Z^d is digital convex if conv(S) ∩Z^d = S, where conv(S) denotes the convex hull of S. In this paper, we consider the algorithmic problem of testing whether a given set S of n lattice points is digital convex. Although convex hull computation requires Ω(n n) time even for dimension d = 2, we provide an algorithm for testing the digital convexity of S⊂Z^2 in O(n + h r) time, where h is the number of edges of the convex hull and r is the diameter of S. This main result is obtained by proving that if S is digital convex, then the well-known quickhull algorithm computes the convex hull of S in linear time. In fixed dimension d, we present the first polynomial algorithm to test digital convexity, as well as a simpler and more practical algorithm whose running time may not be polynomial in n for certain inputs.

## Authors

• 5 publications
• 7 publications
• 5 publications
12/13/2018

### Peeling Digital Potatoes

The potato-peeling problem (also known as convex skull) is a fundamental...
04/15/2020

### Efficient Algorithms for Battleship

We consider an algorithmic problem inspired by the Battleship game. In t...
08/20/2018

### Asymmetric Convex Intersection Testing

We consider asymmetric convex intersection testing (ACIT). Let P ⊂R^d ...
03/08/2021

### Digital Convex + Unimodular Mapping =8-Connected (All Points but One 4-Connected)

In two dimensional digital geometry, two lattice points are 4-connected ...
05/10/2021

### Learning Weakly Convex Sets in Metric Spaces

We introduce the notion of weak convexity in metric spaces, a generaliza...
11/01/2017

### Finding all Maximal Area Parallelograms in a Convex Polygon

We consider the problem of finding the maximum area parallelogram (MAP) ...
10/18/2018

### On estimation of biconvex sets

A set in the Euclidean plane is said to be θ-biconvex, for some θ∈[0,π/2...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Digital geometry is the field of mathematics that studies the geometry of points with integer coordinates, also known as lattice points [KlR04]. Convexity is a fundamental concept in digital geometry, as well as in continuous geometry [Ro89]. From a historical perspective, the study of digital convexity dates back to the works of Minkowski [Min10] and it is the main subject of the mathematical field of geometry of numbers.

While convexity has a unique well stated definition in any linear space, different definitions have been investigated in and  [KR82, KR82-2, Cha83, Ki96, ChR1998]. In two dimensions, we encounter at least five different approaches, called respectively digital line, triangle, line [KR82], HV (for Horizontal and Vertical [BDNP96]), and Q (for Quadrant [Da01]) convexities. These definitions were created in order to guarantee that a digital convex set is connected (in terms of the induced grid subgraph), which simplifies several algorithmic problems.

The original definition of digital convexity in the geometry of number does not guarantee connectivity of the grid subgraph, but provides several other important mathematical properties, such as being preserved under certain affine transformations (Fig. 1). The definition is the following. A set of lattice points is digital convex if , where denotes the convex hull of .

Herein, we consider the fundamental problem of verifying whether a given set of lattice points is digital convex.

Problem TestConvexity
Input: Set of lattice points given by their coordinates.
Output: Determine whether is digital convex or not.

The input of TestConvexity is an unstructured finite lattice set (without repeating elements). Related work considered more structured data in dimension , in which is assumed to be connected. The contour of a connected set of lattice points is the ordered list of the points of having a grid neighbor outside . When is connected, it is possible to represent by its contour, either directly as in [DRR2003] or encoded as binary word [BLP2009]. The algorithms presented in [DRR2003, BLP2009] test digital convexity in linear time on the respective input representations.

Our work, however, does not make any assumption on being connected, or any particular ordering of the input. In this setting, a naive approach to test the digital convexity is:

1. Compute the convex hull of the lattice points of .

2. Compute the number of lattice points inside the convex hull of .

3. If , then is convex. Otherwise, it is not.

Step 1 consists of computing the convex hull of points. The field of computational geometry provides a plethora of algorithms to compute the convex hull of a finite set of points [BCK08]. The fastest algorithms for dimensions and take time [Yao81]

, which matches the lower bound in the algebraic decision tree model of computation

[PrH77]. In dimension , if we also take into consideration the output size , i.e. the number of vertices of the convex hull, the fastest algorithms take time [KiS86, Cha96]. Some polytopes with vertices (e.g., the cyclic polytope) have facets. Therefore, any algorithm that outputs this facet description of the convex hull requires time. Optimal algorithms to compute the convex hull in dimension match this lower bound [ChB93].

Step 2 consists of computing the number of lattice points inside a polytope (represented by its vertices), which is a well studied problem. In dimension , it can be solved using Pick’s formula [Pic1899]. The question has been widely investigated in the framework of the geometry of numbers, from Ehrhart theory [Ehr62] to Barvinok’s algorithm [Bar94]. Currently best known algorithms have a complexity of for fixed dimension  [Bar94-2]. As conclusion, the time complexity of this naive approach is at least the one of the computation of the convex hull.

### 1.1 Results

In Section 2, we consider the 2-dimensional version of the problem and show that the convex hull of digital convex sets can be computed in linear time. Our main result is an algorithm for dimension to solve TestConvexity in time, where is the number of edges of the convex hull and is the diameter of .

In Section 3, we consider the problem in fixed dimension . We present the first polynomial-time algorithm to test digital convexity, as well as a simpler and more practical algorithm whose running time may not be polynomial in for certain inputs.

## 2 Digital Convexity in 2 Dimensions

The purpose of this section is to provide an algorithm to test the convexity of a finite lattice in linear time in . To this endeavour, we show that the convex hull of a digital convex set can be computed in linear time. In fact, we show that this linear running time is achieved by the well-known quickhull algorithm [BBD96].

Quickhull is one the many early algorithms to compute the convex hull in dimension . Its worst case time is , which makes it generally less attractive than the algorithm. However for certain inputs and variations of the algorithm, the average time complexity is reduced to or  [BCK08, Gre90].

The quickhull algorithm starts by initializing a convex polygon in the following manner. First it computes the top-most and bottom-most points of the set. Then it computes the two extreme points in the normal direction of the line supported by the top-most and bottom-most points. Those four points describe a convex polygon that we call a partial hull, which is contained inside the convex hull of . The points contained in the interior of the partial hull are discarded. Furthermore, horizontal lines and lines parallel to the top-most to bottom-most line passing through these points describe an outlying bounding box in which the convex hull lies (Fig. 2).

The algorithm adds vertices to the partial hull until it obtains the actual convex hull. This is done by inserting new vertices in the partial hull one by one. Given an edge of the partial hull, let

denote its outwards normal vector. The algorithm searches for the extreme point in direction

. If this point is already an edge point, then the edge is part of the convex hull. Otherwise, we insert the farthest point found between the two edge vertices, discarding the points that are inside the new partial hull. Throughout this paper, we call a step of the quickhull algorithm the computation of the farthest point of every edge for a given partial hull. When adding new vertices to the partial hull, the region inside the partial hull expands. Points inside that expansion are discarded by quickhull and herein we name this region discarded region. The points that still lie outside the partial hull are preserved, and we call the region within which points might still lies preserved region (Fig. 3).

We show that quickhull steps takes linear time and that at each step half of the remaining input points of the convex hull is discarded. Therefore, as in standard decimation algorithms, the total running time remains linear. In Section 2.2, we explain how to use this algorithm to test the digital convexity of any lattice set in linear time in .

###### Theorem 1.

If the input is a digital convex set of points, then QuickHull has time and space complexities.

### 2.1 Proof of Theorem 1

We prove Theorem 1 with the help of the following lemma.

###### Lemma 2.

The area of the discarded region is larger than the area of the preserved region.

###### Proof.

Consider one step of the algorithm: Let be the edge associated to the step. When was added to the hull, it was as the farthest point in a given direction. Hence, there is no point behind the line orthogonal to this direction going through . (Fig. 3b). The same can be said for . Let be the intersection point of those two lines. Every point that lies within will be fed to the following steps. At this step, we are looking for the point that is the farthest from the supporting line of and outside the partial hull (let that point be ) (Fig. 4). Let and be the intersections between the line parallel to going through , and respectively and . There are no points from inside the triangle . Adding to the partial hull creates two other edges to further be treated: one with as an edge that will be fed the points inside and one with as the edge that will be fed the points inside . The triangle lies within the partial hull, therefore is the region in which points are discarded. (Fig. 4)

We established that the preserved lattice points are the lattice points within and . Also the discarded lattice points are those within . Let be the middle of and be the middle of . As shown in Fig. 4, the symmetrical of and through respectively and both lie inside and do not intersect each other. Hence is larger in terms of area than . ∎

###### Remark 1.

Pick’s formula does not apply here since all vertices of the triangle (namely in Fig. 4) are not necessarily lattice points.

###### Remark 2.

As there is no direct relation between the area of a triangle and the number of lattice points inside it, this result is not sufficient to conclude that a constant proportion of points are discarded at each step.

###### Corollary 3.

The reflection of lattice points inside and across respectively and are lattice points.

###### Proof.

The points are lattice points so and (middle of respectively and ) have their coordinates in multiple of half integers. Hence the reflection of a lattice point across or is a lattice point. Therefore, every lattice point within has a lattice point reflection across within and every lattice point within has a lattice point reflection across within .

###### Remark 3.

This previous result would prove that half the points are discarded at each step if it were not for the lattice points on the diagonals and .

We will now show that quickhull discards at least half of the remaining points at each step, hence proving theorem 1

###### Proof.

We established in Corollary 3 that lattice points inside the search regions ( and ) have symmetrical counterparts inside the discarded region (more precisely inside and ) (Fig. 4). By preserving each points inside and at each step, we do not have a discarded symmetrical counterpart for the lattice points lying on and . But we do not need to preserve those points, since and are at this step edges of the partial hull. Removing lattice points from and implies that in the following step there will be no lattice points on , leaving lattice points on without a discarded symmetrical counterparts (Fig. 5).

Let actually discard every points on , since they all are equally farthest from in the outer direction, they all belong to the hull. Hence we can add the first and last lattice point on to the partial hull (Fig. 5). Note that this only takes linear time and does not change the time complexity of each individual step. Hence, at each step of quickhull, for every preserved points there is at least a discarded point. Consequently, the number of operations is proportional to and quickhull takes linear time for digital convex sets. ∎

### 2.2 Determining the digital convexity of a set

We showed in Theorem 1 that the quickhull algorithm computes the convex hull of digital convex sets in linear time thanks to the fact that at each step quickhull discards at least half of the remaining points. By running quickhull on any given set , and stopping the computation if any step of the algorithm discards less than half of the remaining points, we ensure both that the running time is linear, and that if is digital convex, quickhull finishes and we get the convex hull of . If the computation finishes for , we still need to test its digital convexity. To do so, we use the previously computed convex hull and compute using Pick’s formula [Pic1899]. The set is digital convex if . Hence the resulting Algorithm 1.

###### Theorem 4.

Algorithm 1 tests digital convexity of any 2 dimensional set , and runs in time, where is the number of edges of and is the diameter of .

###### Proof.

As Algorithm 1 runs quickhull, but stops as soon as less than half the remaining points have been removed, the running time of the quickhull part is bounded by the series , and is hence linear. Thanks to Theorem 1 we know that the computation of quickhull will not stop for any digital convex sets. Computing using Pick’s formula requires the computation of the area of and of the number of lattice points lying on its boundary, which requires the computation of a greatest common divisor. Hence this takes time where is the number of edge of and is the diameter of . As is digital convex if and only if , Algorithm 1 effectively tests the digital convexity of a 2 dimensional set in time. ∎

## 3 Test Digital Convexity in Dimension d

We provide two algorithms for verifying the digital convexity in any fixed dimension.

### 3.1 Naive algorithm

The naive algorithm mentioned in the Introduction is based on the following equivalence: the set is digital convex if and only if its cardinality is equal to the cardinality of . In Step 1, we compute the convex hull of (in time [ChB93]). In Step 2, we need to count the number of integer points inside . The classical algorithm to achieve this goal is known as Barvinok algorithm [Bar94]. This approach determines only the number of missing points. If we want to enumerate the points, it is possible to do so through a formal computation of the generating functions used in Barvinok algorithm.

###### Theorem 5.

The naive algorithm tests digital convexity in any fixed dimension and runs in polynomial time.

###### Proof.

Computing the convex hull of any set can be done in time [ChB93]). Counting lattice points inside a convex lattice polytope can be done in polynomial time [Bar94-2]. A direct consequence of the digital convexity definition is that a set is digital convex if and only if , hence the naive algorithm tests digital convexity in any fixed dimension and runs in polynomial time.

### 3.2 Alternative algorithm

This new algorithm computes all integer points in the convex hull of with a more direct approach. Its principle is to enumerate the points of a finite lattice set surrounding (). In a first variant, we count the number of points of belonging to . At the end, the set is convex if and only if is equal to the cardinality of . In a second variant, for each point of , we test whether it belongs to and in the negative case, we test whether it belongs to the convex hull of . If a point of is found, then is not convex.

We define the set as the set of points such that the cube has a nonempty intersection with the convex hull of , where denotes the Minkowski sum. It can be easily proved that is -connected (the neighbors of a lattice point are the integer points at Euclidean distance ) and by construction, it contains . The graph structure induced by the -connectivity on allows to visit all the points of efficiently: for each point , we consider its neighbors and test whether they belong to . If they do, we add them to the stack of the remaining points of . The goal is to test whether a point of is in the convex hull of .

Then the algorithm has two main routines:

• tests whether a given point belongs to the convex hull of

. It is equivalent with testing whether there exists a hyperplane separating

from the points of

. It can be done by linear programming with a worst-case time complexity of

for fixed dimension  [BCK08].

• tests whether a given point belongs to the convex hull of . It follows the same principle as with points. The time complexity remains linear in fixed dimension. This routine is used to test whether an integer point belongs to .

The algorithm is the following. First, we create a stack of the points of to visit and initialize it with the set . For each point in , we remove it from the stack and label it as already visited. Then, we consider its neighbors . If belongs to and has not been visited previously, we add it in the stack . We test whether belongs to and increment the cardinality of accordingly (variant 1) or test whether is in and and return not convex if (variant 2).

The running time is strongly dependent on the cardinality of . It is . If the size of is of the same magnitude as the initial set, the algorithm runs in time. It is unfortunately not possible to bound as a function of . The ratio can go to infinity. It is easy to build such an example with a set consisting of only two lattice points, for instance for any the set induces

. A direction of improvement could be to consider a linear transformation of the lattice

in order to obtain a more compact lattice set and then a lower ratio . LLL algorithm [LLL82] could be useful to achieve this goal in future work.

As in the naive algorithm, a variant of this approach can be easily developed in order to enumerate the missing points.

## 4 Perspectives

In this paper, we presented an algorithm to test digital convexity in time linear in for dimension . In higher dimensions, our running time depends on the complexity of general convex hull algorithms. The questions of whether digital convexity can be tested in linear time in dimensions, or faster than convex hull computation in arbitrary dimensions remain open. A tentative approach consists of changing the lattice base, in order to obtain certain connectivity properties.

We showed that the convex hull of a digital convex set in dimension 2 can be computed in linear time. Can the convex hull of digital convex sets be computed in linear time in dimension 3, or more generally, what is the complexity of convex hull computation of a digital convex set in any fixed dimension? We note that the number of faces of any digital convex set in dimensions is , where is the volume of the polytope [And63, Bar08]. Therefore, the lower bound of for the complexity of the convex hull of arbitrary polytopes does not hold for digital convex sets.

#### 4.0.1 Acknowledgement

This work has been sponsored by the French government research program “Investissements d’Avenir” through the IDEX-ISITE initiative 16-IDEX-0001 (CAP 20-25).