1 Introduction

Digital geometry is an important theoretical part of digital image processing. Discrete, digital spaces have different properties than the Euclidean space, e.g., neighborhood of points play important role. Consequently, digital (path based) distance functions have various advantages, see, e.g., [4]. Various digital distance functions are developed since the 1960’s, where the two basic digital distances based on the two usual neighborhood on the square grid were investigated [16]. Various grids have various properties and various advantages and disadvantages in applications. E.g., the square grid is easy to use, it has hardware and software support, other grids have more symmetries, may provide better topological properties. Digital geometry and distance functions are developed for various traditional and non traditional grids, both in 2D and in higher dimensions. To move some of the results from a point lattice to other point lattice may not be trivial. In case of at least one of the grids is not a point lattice, we need to find newer and newer approaches, the translation of the results cannot go automatically. Even some results seem to be similar, the details could be very different. A nice symmetric coordinate frame for the hexagonal grid was presented in [3], while the simplest digital distances are investigated in [7] for that grid. The triangular grid was also described by symmetric coordinate system with integer triplets, see, e.g., [9, 11]. The hexagonal and triangular grids can be seen as one and two parallel oblique planes of the cubic grid [10], and with three such planes another ‘triangular grid’ can be obtained [12]. This grid is called trihexagonal grid in this paper since it is mixing the properties of the hexagonal and triangular grids (see Fig. 1). Each node has the same rank and each node is surrounded by the same set of regular polygons in the same order. By its symmetric properties this grid is denoted by T(6, 3, 6, 3) in [15], where 4 is the nodal rank and 6 or 3 is the number of edges of the i-th polygon.

Chamfer (or weighted) distances are providing a relatively good approximation of the Euclidean distance with good algorithmic properties [1]. The concept was also investigated on some non-traditional 2D grids including the triangular grid [13], Khalimsky grid [5, 6]; and various 3D grids [17, 18]. In this paper chamfer distances on the 2D trihexagonal grid are investigated; our main motivation is to show the basic properties.

2 Description of Trihexagonal Tiling (6, 3, 6, 3)

Figure 1 shows a usual representation of the trihexagonal tiling. The grid is T(6, 3, 6, 3) if dual notation is used, see, e.g., [15]. In this representation hexagons represent the points for which 6-neighborhood is used and triangles the points for which 3-neighborhood is used.

Each pixel of the trihexagonal grid (6, 3, 6, 3) is a hexagon or a triangle, we also call it as a point of the grid. A hexagon has 6 neighbors with common sides (6 triangles). A triangle has 3 neighbors with common sides (3 hexagons).

Similarly to the hexagonal grid or to the triangular grid, each pixel of the trihexagonal grid (6, 3, 6, 3) can also be described by a unique coordinate-triplet.

Fig. 1.
figure 1

Coordinate axes and coordinate values assigned to cells of a segment of the trihexagonal grid. The yellow hexagon and the orange triangles are neighbors (\(\alpha \)), the pink hexagons are semi-neighbors (\(\beta \)), the blue triangles are semi-neighbors (\(\gamma \)). (Color figure online)

There is a triangle having coordinate triplet (0, 0, 0), and the directions of the axes can be seen on the Fig. 1. At every time when we step from a triangle to a hexagon (or from a hexagon to a triangle) crossing their common side, the step is done parallel to one of the axes. If the step is in the direction of an axis, then the respective coordinate value is increased by 1, while in case the step is in opposite direction to an axis, the respective coordinate value is decreased by 1.

In this way every point gets a unique coordinate triplet with integer values. However the three values are not independent (we are in a two dimensional space, i.e., plane). Their sum is either 0, 1 or 2. There are two orientations of the used triangles: there are triangles of shape \(\bigtriangleup \) and there are triangles of shape \(\bigtriangledown \). The sum of the coordinate values that address a triangle is 0 or 2 depending the orientation (shape) of the triangle. The sum of the coordinate values of a hexagon is 1.

There are two types of (commonly used) neighborhood on this grid. Two pixels are neighbors if they share a side. Two pixels are semi-neighbors if they share at least a point on their boundaries (e.g., a corner point). Using the coordinate triplets one can give the neighborhood relations in the following formal form. The hexagon p(p(1), p(2), p(3)) and the triangle q(q(1), q(2), q(3)) are neighbors if \(|p(1) - q(1)| + |p(2) - q(2)| + |p(3) - q(3)| = 1\). (See also Fig. 1.)

There are no triangles with common side, but every triangle p has 3 semi-neighbor triangle, for example q, for which \(|p(1) - q(1)| + |p(2) - q(2)| + |p(3) - q(3)| = 2\).

There are no hexagons with common side, but every hexagon p has 6 semi-neighbor hexagon, for example q, for which \(|p(1) - q(1)| + |p(2) - q(2)| + |p(3) - q(3)| = 2\).

3 Definition of Weighted Distances

Let \(\alpha ,\beta ,\gamma \in \mathbb R^+\) be positive real weights. The simplest weighted distances allow to step to a neighbor (from a triangle to a hexagon and vice versa) by changing only one coordinate value by \(\pm 1\) with weight \(\alpha \). Let the weight of a step from a hexagon to a semi-neighbor hexagon be \(\beta \). This step changes two coordinates, one by \(+1\), and another one by \(-1\). Let the weight of a step from a triangle to a semi-neighbor triangle be \(\gamma \). This step changes two coordinates, both by \(+1\), or both by \(-1\). (See also Fig. 1.)

We can define the weighted distance of any two points (hexagons or triangles) of the grid. Let p and q be two points of the grid. A finite point sequence of points of the form \(p=p_0,p_1,\dots ,p_m=q\), where \(p_{i-1},p_i\) are neighbors or semi-neighbors for \(1\le i \le m\), is called a path from p to q. A path can be seen as consecutive steps to neighbors or semi-neighbors. Then the cost of the path is the sum of the weights of its steps.

Finally, let the weighted distance \(d(p,q;\alpha ,\beta ,\gamma )\) of p and q by the weights \(\alpha , \beta , \gamma \) be the cost of the minimal (basic) weighted paths between p and q.

Usually, there can be several shortest paths from a point to another. The order of steps can be varied, e.g., if a shortest path from (0, 0, 1) to \((2,-1,0)\) contains two \(\beta \) steps containing the point (1, 0, 0), then the path having two \(\beta \) steps through \((1,-1,1)\) is also a shortest path. However, since we are not on a lattice, we are not free to use any order of the steps. One need to take care about the following conditions:

  • \(\alpha \) steps are allowed on any point, and a point of the opposite type is reached by the step (where hexagon and triangle are the types).

  • \(\beta \) step can only be used from a hexagon (the sum of coordinates is equal to 1), and it goes to a hexagon.

  • \(\gamma \) steps are valid only from a triangle (the sum of the coordinates is equal to 0, or 2), and another triangle is reached (but the sum of the coordinates of the new triangle is different from the original one: the triangles have opposite orientation).

A technical definition is used through the paper. The difference \(w_{p,q}=(w(1),w(2),w(3))\) of two points p and q is defined by \(w(i)=q(i)-p(i)\), where \(i\in \{1,2,3\}\).

4 Minimal Weighted Paths

There are various paths with various sums of weights that can be found between any two points. When the weights \(\alpha \), \(\beta \) and \(\gamma \) are known the optimal search (the Dijkstra algorithm) can be used. However depending on the actual ratios and values of the weights \(\alpha , \beta , \gamma \), one can compute a minimum weighted paths in a more direct way. Using a combinatorial approach, we give methods for these computations for each possible case.

We use the natural condition \(0\le \alpha \le \beta , \gamma \) for the used weight values. We know that with a neighbor step (by weight \(\alpha \)) only 1 of the coordinates changes by \(\pm 1\); with a semi-neighbor step (by weight \(\beta \) or \(\gamma \)) exactly 2 of the coordinates change by 1 and/or \(-1\), respectively. Therefore it is important to measure the relative weight of a step, that is the cost of the change of a coordinate value by \(\pm 1\). These relative weights give the separation of the possible cases.

4.1 Case \(2\alpha \le \beta \) and \(2\alpha \le \gamma \)

Lemma 1

If \(2\alpha \le \beta \) and \(2\alpha \le \gamma \), then the length of the minimal path between the points p and q is

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\alpha (|w(1)|+|w(2)|+|w(3)|). \end{aligned}$$
(1)

Proof

In this case the use of \(\beta \) steps and \(\gamma \) steps is not efficient (their usage do not lead to shorter paths than we have without them). A minimal path can be constructed only by \(\alpha \) steps. In every step the absolute value of a coordinate difference is decreasing by 1 implying the formula.    \(\square \)

For example the distance of the triangle (0, 0, 0) and the hexagon (1, \(-1\), 1) is \(3\alpha \).

4.2 Case \(\gamma \le 2\alpha \le \beta \)

Lemma 2

If \(\alpha \le \gamma \le 2\alpha \le \beta \), then the length of the minimal path between the points p and q is

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}+ \alpha \cdot \left( \sum _{i=1}^3 |w(i)| - 2\cdot \min \{|w(i)|\}\right) , \end{aligned}$$
(2)

but if \(w_{p,q}\) contains one 0 and two 1 values, or one 0 and two \(-1\) values, then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\gamma . \end{aligned}$$
(3)

Proof

The value of the sum of coordinate differences \(\sum \limits _{i=1}^3 w(i)\) is equal to 0, ±1 or ±2. (Moreover it is ±2 only if the two points are different shaped triangles.)

Clearly, in this case \(\beta \) steps cannot appear (when \(2\alpha \le \beta \)) in any shortest path or substituting them by two \(\alpha \) steps a path with same weight is obtained, we deal with paths containing only \(\alpha \) and \(\gamma \) steps. It follows from Lemma 1 there is always a path between p and q consisting of \(\alpha \) steps only and their number is \(|w(1)|+|w(2)|+|w(3)|\). Obviously, a path with this property has the minimal length among all paths using only \(\alpha \) steps as each such step changes the absolute values of differences of the coordinates by 1. If there are two coordinates where the difference has the same sign, then it is possible to make a \(\gamma \) step at the beginning.

If \(\min \{|w(i)|\}>0\), then the signs of two differences (from three) are the same, and one of them has the smallest absolute value, because the sum of differences is between \(-2\) and 2. It means that we are able to use \(\gamma \) steps \(\min \{|w(i)|\}\) times instead of twice many \(\alpha \) steps, but no more. The path can be constructed that between two \(\gamma \) steps come two \(\alpha \) steps (for example between two (1, 1, 0) steps come two \((0, 0, -1)\) steps).

If \(\min \{|w(i)|\}=0\) and the sign of the other two differences are different, then the use of a \(\gamma \) step does not decrease the sum of the absolute values of the coordinate differences, i.e. the use of \(\gamma \) step is not efficient (there is a shortest path without it).

If \(\min \{|w(i)|\}=0\), then the signs of the other two differences are the same only if both values are equal to 1 or both values are equal to −1, for example (1, 1, 0). In this case the distance is \(\gamma \).    \(\square \)

For example the distance of the triangle (0, 0, 0) and the hexagon \((1, -1, 1)\) is \(\gamma +\alpha \), the distance of the triangles (0, 0, 0) and \((2, 0, -2)\) is \(4\alpha \), but the distance of the triangles (0, 0, 0) and (1, 0, 1) is \(\gamma \) with the given conditions on the weights.

4.3 Case \(\beta \le 2\alpha \le \gamma \)

The use of \(\gamma \) steps instead of \(\alpha \) steps is not efficient, but one \(\beta \) step can be better than two \(\alpha \) steps.

Lemma 3

If \(\beta \le 2\alpha \le \gamma \), then the length of the minimal path between the hexagons p and q is

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|}{2}. \end{aligned}$$
(4)

Proof

If p and q are hexagons, then the sum of the coordinate differences is 0, and every \(\beta \) step is a 0-sum step. In this case a minimal path can be constructed only by \(\beta \) steps. In every step the sum of the absolute values of the coordinate differences is decreasing by 2, and this is better than the use of two \(\alpha \) steps.    \(\square \)

For example the distance of the hexagons (0, 0, 1) and (2, \(-1\), 0) is \(2\beta \).

If every point of a path is a hexagon, then it is called a hexagonal path in the following. The next lemmas can be proven in similar manner as Lemma 3.

Lemma 4

If \(\beta \le 2\alpha \le \gamma \), and p and q are a triangle and a hexagon, then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3|w(i)|-1}{2}+\alpha . \end{aligned}$$
(5)

Lemma 5

If \(\beta \le 2\alpha \le \gamma \), and p and q are triangles, then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3|w(i)|-2}{2}+2\alpha . \end{aligned}$$
(6)

For example the distance of the triangle (0, 0, 0) and the hexagon \((1, -1, 1)\) is \(\beta +\alpha \), and the distance of the triangles (0, 0, 0) and \((2, 0, -2)\) is \(\beta +2\alpha \).

4.4 Case \(\beta \le \gamma \le 2\alpha \)

Lemma 6

If \(\beta \le \gamma \le 2\alpha \), then the length of the minimal path between p and q is given in (4), (5) and (6), but if p and q are adjacent triangles, then \(d(p,q;\alpha ,\beta ,\gamma )=\gamma \).

Proof

In every \(\beta \) step and \(\gamma \) step the sum of the absolute values of the coordinate differences is decreasing by 2. But \(\beta \le \gamma \) means that the use of \(\gamma \) steps is not efficient if one of the points is a hexagon. Then this case is the same as the previous case.

But if p and q are triangles and in the minimal path of the above case the \(\alpha \) steps are consecutive steps, then it is feasible and efficient to change them with a \(\gamma \) step. The \(\alpha \) steps are consecutive only if there are no \(\beta \) steps, and the triangles are semi-neighbors.    \(\square \)

For example the distance of the triangles (0, 0, 0) and \((2, 0, -2 )\) is \(\beta +2\alpha \), but the distance of the triangles (0, 0, 0) and (1, 0, 1) is \(\gamma \).

4.5 Case \(\gamma \le \beta \le 2\alpha \)

Subcase p and q are Hexagons

Lemma 7

If \(\alpha \le \gamma \le \beta \le 2\alpha \) and p, q are hexagons, then the minimal path contains at least one \(\gamma \) step if and only if \(w_{p,q}\) has two coordinates with the same sign and \(\gamma +2\alpha \le 2\beta \).

Proof

Of course we cannot use a \(\gamma \) step instead of a \(\beta \) step, or two \(\gamma \) steps instead of two \(\beta \) steps. But we can use a \(\gamma \) step and two \(\alpha \) steps instead of two appropriate \(\beta \) steps.

If p and q are hexagons, then the sum of coordinate differences is equal to 0. In this case \(\min \{|w(i)\}=0\) if and only if the sign of the other two differences are different. Then the use of a \(\gamma \) step does not decrease the sum of the absolute values of the coordinate differences, thus the use of \(\gamma \) step is not efficient. The minimal path is the hexagonal path between the two hexagons, which uses only \(\beta \) steps. \(\min \{|w(i)\}>0\) if and only if \(w_{pq}\) has two coordinates with the same sign. The hexagonal path is minimal only if \(2\beta <\gamma +2\alpha \), when the use of \(\gamma \) step is not efficient. But if \(2\beta \ge \gamma +2\alpha \), then the minimal path uses \(\gamma \) step: we can begin the minimal path with \(\alpha \), \(\gamma \), \(\alpha \) steps, and the sum of the absolute value of the coordinate differences is decreased by 4.    \(\square \)

Lemma 8

If \(\alpha \le \gamma \le \beta \le 2\alpha \) and p, q are hexagons, then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum _{i=1}^3 |w(i)|}{2} \end{aligned}$$
(7)

if \(2\beta \le \gamma +2\alpha \), and

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma ) = \gamma \cdot \min \{|w(i)|\}+2\alpha \cdot \min \{|w(i)|\}+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}}{2} \end{aligned}$$
(8)

if \(\gamma +2\alpha \le 2\beta \).

Proof

If p and q are hexagons, then the sum of the coordinate differences is 0.

If \(\min \{|w(i)|\}=0\), then the signs of the other two differences are different. It means that the use of \(\gamma \) steps is not efficient.

But if \(\min \{|w(i)|\}>0\), then \(w_{p,q}\) has two coordinates with the same sign, for example positive coordinates: the first and the second one. There exists a \(\beta \)-path between the two hexagons, which first \(2\min \{|w(i)|\}\) steps are the alternate \(\beta \) steps \((1, 0, -1)\) and \((0, 1, -1)\). Changing two appropriate \(\beta \) steps to one \(\gamma \) step and two \(\alpha \)-steps may be efficient \(\min \{|w(i)|\}\) times if \(\gamma +2\alpha \le 2\beta \).

Of course \(4\min \{|w(i)|\}\le \sum \limits _{i=1}^3 |w(i)|\) holds, because of \(\sum \limits _{i=1}^3 w(i)=0\).    \(\square \)

For example the distance of the hexagons (0, 0, 1) and \((2, -1, 0)\) is \(2\beta \) or \(2\alpha +\gamma \).

Subcase p and q are a Hexagon and a Triangle. If p and q are a hexagon and a triangle, then there exists the above mentioned minimal path between the hexagon and another hexagon, which is the closest hexagon neighbor of the triangle, and there is a final \(\alpha \) step between the closest hexagon and the triangle. If the final step of the path between the two hexagons is a \(\beta \) step, then it can be efficient to change the final \(\beta \) and \(\alpha \) steps to an \(\alpha \) step and a \(\gamma \) step. This way we can increase the number of \(\gamma \) steps by 1. For example we can change the steps \((0, 1, -1)\) and (1, 0, 0) to \((0, 0, -1)\) and (1, 1, 0). When are we able to do this substitution?

In this case the sum of the coordinate differences is ±1.

Lemma 9

If \(\alpha \le \gamma \le \beta \le 2\alpha \), p and q are a hexagon and a triangle, and \(w_{p,q}\) contains only one coordinate with the sign of \(\sum \limits _{i=1}^3 w(i)\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-1}{2}+\alpha \end{aligned}$$
(9)

if \(2\beta \le \gamma +2\alpha \), and

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}$$
$$\begin{aligned} +\,\alpha \cdot (2\min \{|w(i)|\}+1)+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}-1}{2} \end{aligned}$$
(10)

if \(\gamma +2\alpha \le 2\beta \).

Proof

Let us assume, that \(\sum \limits _{i=1}^3 w(i)=1\) and p is a hexagon and q is a triangle. (The proof of the case \(-1\), or the case of a triangle and a hexagon are similar.) In this case \(w_{p,q}\) contains only one positive coordinate, for example the first one, then the final \(\alpha \) step of the above mentioned path (based on the closest neighbor hexagon of the triangle) is (1, 0, 0). (For example if the starting hexagon is (1, 0, 0) and the triangle is \((7, -3, -2)\), then the closest neighbor hexagon of the triangle is \((6, -3, -2)\) and not \((7, -4, -2)\) or \((7, -3, -3)\), because the sum of the absolute value of the coordinate differences are here 10, 12 and 12.)

The use of a \(\gamma \) step, which first coordinate is \(+1\) is not efficient, because this \(\gamma \) step does not decrease the sum of the absolute values of the coordinate differences. Thus the use of the above mentioned substitution is not efficient, i.e. the number of \(\gamma \) steps is equal to the number of \(\gamma \) steps of the path based on the closest neighbor hexagon (in the previous lemma).

If this path uses an \(\alpha \) step, then it’s coordinates are (1, 0, 0). These are the same as the coordinates of the final \(\alpha \) step. Thus we are not able to increase the number of \(\beta \) steps.    \(\square \)

For example the distance of the triangle (0, 0, 0) and the hexagon \((3, -1, -1)\) is \(2\beta +\alpha \) or \(3\alpha +\gamma \).

In a similar manner one can also prove the following lemma.

Lemma 10

If \(\alpha \le \gamma \le \beta \le 2\alpha \), p and q are a hexagon and a triangle, and \(w_{p,q}\) contains two coordinates with the sign of \(\sum \limits _{i=1}^3 w(i)\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-3}{2}+\alpha +\gamma \end{aligned}$$
(11)

if \(2\beta \le \gamma +2\alpha \), and

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}$$
$$\begin{aligned} +\,\alpha \cdot (2\min \{|w(i)|\}-1)+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}+1}{2} \end{aligned}$$
(12)

if \(\gamma +2\alpha \le 2\beta \).

For example the distance of the triangle (0, 0, 0) and the hexagon \((2, 1, -2)\) is \(\beta +\alpha +\gamma \) in both cases.

Subcase p and q are Triangles. If p and q are triangles, then there exists the above mentioned minimal path between the closest hexagon neighbors of the triangles, and there are starting and final \(\alpha \) steps between the closest hexagons and the triangles. This case is similar to the previous one, but sometimes we are able to do the above mentioned changes (at the end of the path) two times (at the beginning, too).

Lemma 11

If \(\alpha \le \gamma \le \beta \le 2\alpha \), p and q are triangles, \(\sum \limits _{i=1}^3 w(i)\ne 0\), and \(w_{p,q}\) contains only one coordinate with the sign of \(\sum \limits _{i=1}^3 w(i)\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-2}{2}+2\alpha \end{aligned}$$
(13)

if \(2\beta \le \gamma +2\alpha \), and

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}$$
$$\begin{aligned} +\,\alpha \cdot (2\min \{|w(i)|\}+2)+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}-2}{2} \end{aligned}$$
(14)

if \(\gamma +2\alpha \le 2\beta \).

The proof of this lemma is similar to the proof of Lemma 9.

For example the distance of the triangles (0, 0, 0) and \((3,-1,0)\) is \(2\alpha +\beta \) in both cases.

Lemma 12

If \(\alpha \le \gamma \le \beta \le 2\alpha \), p and q are triangles, \(\sum \limits _{i=1}^3 w(i)\ne 0\) and \(w_{p,q}\) contains two coordinates with the sign of \(\sum \limits _{i=1}^3 w(i)\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-6}{2}+2\alpha +2\gamma \end{aligned}$$
(15)

if \(2\beta \le \gamma +2\alpha \), and

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}$$
$$\begin{aligned} +\,\alpha \cdot (2\min \{|w(i)|\}-2)+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}+2}{2} \end{aligned}$$
(16)

if \(\gamma +2\alpha \le 2\beta \). But if moreover \(\sum \limits _{i=1}^3 |w(i)|=2\), then \(d(p,q;\alpha ,\beta ,\gamma )=\gamma \), and if \(\sum \limits _{i=1}^3 |w(i)|=4\), then \(d(p,q;\alpha ,\beta ,\gamma )=\gamma +2\alpha \).

The proof of this lemma is similar to the proof of Lemma 10.

For example the distance of the triangles (0, 0, 0) and \((2,2,-2)\) is \(2\alpha +2\gamma \) in both cases.

Lemma 13

If \(\alpha \le \gamma \le \beta \le 2\alpha \), p and q are triangles, and \(\sum \limits _{i=1}^3 w(i)=0\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-2}{2}+2\alpha \end{aligned}$$
(17)

if \(2\beta \le \gamma +2\alpha \) or \(\min \{|w(i)|\}=0\) and

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot \min \{|w(i)|\}$$
$$\begin{aligned} +\,\alpha \cdot \min \{|w(i)|\}+\beta \cdot \frac{\sum \limits _{i=1}^3 |w(i)|-4\min \{|w(i)|\}}{2} \end{aligned}$$
(18)

if \(\gamma +2\alpha \le 2\beta \) and \(\min \{|w(i)|\}>0\).

The proof of this lemma is similar to the proof of Lemma 10.

For example the distance of the triangles (0, 0, 0) and \((0,2,-2)\) is \(2\alpha +\beta \).

5 Properties of Distances

Minimal weighted paths can be obviously computed by Dijkstra algorithm [2]. However, based on the regular structure of the grid and by the help of an appropriate coordinate system direct formulae are provided to compute them. There are various cases depending on the relation of the used weights; a summary of the results is shown in Table 1.

Table 1. Value of \(d(p,q;\alpha ,\beta ,\gamma )\) depending on the cases of respective relations of the weights

For the sake of completeness, we recall the definition of metricity for digital distances. A distance function \(d(\cdot , \cdot )\) is a metric if the three properties, the positive definiteness, the symmetry and the triangular inequality, are fulfilled for any points p, q, r of a space, that is, in this paper the trihexagonal grid (6, 3, 6, 3). There are some non-metrical digital distances, e.g., distances based on neighborhood sequences [9], weight sequences [14]. However, in some applications it is important to use metric distances, therefore, it is important to note that, as usual at weighted distances, for any values of \(\alpha ,\beta ,\gamma \in \mathbb R^+\), the distance function \(d(\cdot ,\cdot ; \alpha ,\beta ,\gamma )\) is a metric.

One can also prove the following about the translation invariance of our distance functions.

Theorem 1

Let \(t=(x,y,z)\) be a grid vector, i.e., the difference of the coordinates of two points of the grid. Then, the distance \(d(p,q;\alpha ,\beta ,\gamma ) = d(p+t,q+t;\alpha ,\beta , \gamma )\) for all pairs of points pq of the grid and for any \(\alpha ,\beta , \gamma \in \mathbb R^+\) if and only if t is an integer triplet with 0-sum.

We can conclude that we have done the first steps to include the trihexagonal grid in digital geometry, namely we have studied chamfer distances. Digital or path-based distance functions are well known and widely used. However, the properties of these functions depend highly on the underlying grid: while chamfer polygons on the square grid are well known any relatively easy to describe, it is not the case on the triangular grid (based on the three classical neighborhood, e.g., 63-gons can also be obtained [8]). Future works and possible applications include cases when, e.g., \(\gamma <\alpha \), distance transforms, and also studies about the digital disks (chamfer polygons) and their interesting phenomena: conditions for concavities, holes and islands (somewhat similarly to [6]).