 # Polygon Matching and Indexing Under Affine Transformations

Given a collection {Z_1,Z_2,...,Z_m} of n-sided polygons in the plane and a query polygon W we give algorithms to find all Z_ℓ such that W=f(Z_ℓ) with f an unknown similarity transformation in time independent of the size of the collection. If f is a known affine transformation, we show how to find all Z_ℓ such that W=f(Z_ℓ) in O(n+(m)) time. For a pair W,W^' of polygons we can find all the pairs Z_ℓ,Z_ℓ^' such that W=f(Z_ℓ) and W^'=f(Z_ℓ^') for an unknown affine transformation f in O(m+n) time. For the case of triangles we also give bounds for the problem of matching triangles with variable vertices, which is equivalent to affine matching triangles in noisy conditions.

## Authors

##### 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

The problem of matching point sets under similarities and affine transformations has been addressed by matching sets of triangles, extracted in a consisting way, from the point sets . In this work we propose a technique to matching arbitrary polygons under affine transforms, and as a particular case triangles in noisy conditions.

We will identify points in the plane with the corresponding complex numbers . A polygon in the plane will be an ordered set of points, or complex numbers. Since the set is arbitrary, self intersection and crossings are allowed.

An affine transformation can be (uniquely) written as

 f(z)=αz+β¯¯¯z+γ

where and . Here stands for the complex conjugated of .

Given polygons and with and complex numbers, the problem consist in determining if there exists an affine transformation such that . Since the affine transformation have three complex parameters, it is enough to find two corresponding triples of consecutive points in both polygons. A naïve procedure will be to fix a triple in and try all the shifts in to find the correspondence. This takes operations.

Now assume we have a given collection of polygons and a query polygon , and want to know which of the are affine images of . Using a sequential approach and the simple procedure above the solution can be found in operations. In general, without an index, the complexity will depend linearly on the number of polygons in the collection; multiplied by the complexity of an individual match. We will show how to improve this complexity using invariants.

## 2 Invariants

We split the invariant in two cases because similarity transformations (rotations, translations, scaling and compositions between them) have relevance per se.

### 2.1 A Similarity Invariant for Polygons

Let and be integers, with , and let be a permutation. Consider functions given by

 φp(z1,…,zn)=∑nk=1λp(k)nzk∑nk=1λ−p(k)nzk,φn,j(z1,…,zn)=∑nk=1λjknzk∑nk=1λ−jknzk

where .

The function is well-defined except on

 N={(z1,…,zn)∈Cn:n∑k=1λp(k)nzk=0=n∑k=1λ−p(k)nzk},

but is a

dimensional vector subspace with null measure in

. Similarly, is well-defined except on a dimensional vector subspace.

Notice that is invariant under the action of similarity transformations on polygons with vertices:

 φp(αz1+β,αz2+β,…,αzn+β)=∑nk=1λp(k)n(αzk+β)∑nk=1λ−p(k)n(αzk+β)=α∑nk=1λp(k)nzk+β∑nk=1λp(k)nα∑pk=1λ−p(k)nzk+β∑nk=1λ−p(k)n=φp(z1,z2,…,zn).

It is also clear that is invariant under the action of similarity transformations:

 φn,j(αz1+β,αz2+β,…,αzn+β)=φn,j(z1,z2,…,zn).

### 2.2 An Affine Invariant for Polygons

In this section, denotes either or . Let and , where is an affine transformation. By making and if , or by making and if , we obtain

 |ξ−ζ||1−¯¯¯ζξ|=∣∣∣αx+β¯¯¯yαy+β¯¯¯x−xy∣∣∣∣∣∣1−¯¯¯x¯¯¯yαx+β¯¯¯yαy+β¯¯¯x∣∣∣=∣∣∣βα∣∣∣. (2.1)

That is, the number does not depend neither on the -agon nor on the numbers and , nor on the permutation ; it just depends on .

Please notice that similarity invariance in section 2.1 can be obtained from the above taking .

###### Remark 2.1.

The numerator and denominator involved in the definition of are coefficients of the polygon appearing when it has expressed in certain basis of , namely the basis of star-shaped polygons (see , [4, proof of Proposition 3]).

###### Remark 2.2.

Equality (2.1) is analogous to a well-known result from Teichmüller theory: if we deform the complex structure of a torus by an affine transformation , then the Teichmüller distance between and does not depend of , it just depends on (see [3, chapter V.6] for instance).

### 2.3 Shifts

A polygon can be enumerated in different cyclic ways or shifts. Notice that , hence we have the equality of potencies

 φn,j(z1,z2,…,zn)n=φn,j(zℓ,zℓ+1,…,zℓ+n−1,zℓ+n)n (2.2)

for any , where the subscripts are taken mod .

###### Remark 2.3.

In what follows we use functions of the form because does not satisfies an identity of the form (2.2) for a general permutation . Each one of the instances of , where ranges in , can be used in the below algorithms for matching polygons. Since they will be used as hashing functions, collisions can be avoided by using multiple instances.

### 2.4 An Index for Matching Polygons

Assume that a collection of different polygons of edges is given. By a preprocessing step we compute pairs . Assume that a query polygon is given and that the objective is to find all the polygons in the collection such that for some unknown similarity transformation . Using the result from section 2.3, this corresponds to all the polygons such that , assume there are of them. They can be found in operations. Please notice that this search can be implemented using hashing in time independent of the size of the collection.

If the parameters of the affine transformation are known, then all the matching polygons such that can be easily found. Using the result from section 2.2 we compute . If the polygons match, then , where . We can retrieve candidate objects in sublinear time using a spatial access method (e.g. kd-trees), or a metric index . The corresponding candidate objects in the complex plane will be arranged as a circle surrounding the query polygon . Using an index, e.g. kd-trees, the complexity bound of the search will be with the number of edges of the polygon, and the number of polygons in the collection and the cost of checking the matching between a pair of polygons.

### 2.5 An Index for Matching Pairs of Polygons

If the affine transformation is unknown, the search space cannot be bounded using invariant 2.2. However, the problem can be solved if we have a pair of polygons. Let and be two -sided query polygons, we want to obtain all polygons such that and for some unknown affine transformation . We compute and . Let and with . Abusing the notation, let and . Using the result from section 2.2, what we need is the intersection of the two sets above . The polygons in the intersection are candidates for matching. The algorithm above needs operations. To finish the procedure, match verifications of the polygons in the intersection are needed.

### 2.6 Collisions

For two unrelated polygons it is possible that they collide, i.e. without being an affine related. This increase the candidate objects to be reviewed in algorithms above. To decrease the number of candidates we can use multiple instances of . Let be the collection of instances of the affine invariant functions, and the respective lists of candidates. The true matches should be in the intersection. Notice that it is not necessary to use all the functions, only a subset of them.

## 3 Noisy Polygons

A slightly more general setup is when there is an unknown noise function in the matching. The image of the query polygon is an affine transformation plus noise, namely . We have bounded the difference for the case of triangles, this is explained below. We were not able to give a tight bound for general polygons. To simplify notation, and will be denoted respectively by and in what follows.

### 3.1 Triangles with Variable Vertex

For the similarity class of a triangle we can choose a representative of the form . The complex number is determined as . Let us define . This is the unique conformal biyection such that

 φ(z1,z2,z3)=M(τ(z1,z2,z3)). (3.1)

The order 3 ‘rotation’ of , with fixed point , corresponds to cyclic relabelling of the vertices of a triangle, because the triangles , and are similar. We use the term ‘rotation’ because is a rotation by angle .

We shall proof an estimation for perturbations of an equilateral triangle. For a real number

we consider the polydisc

 Ur={(z1,z2,z3)∈C3:|z1−λ|

Triangles can be seen as perturbations of the equilateral triangle .

###### Lemma 3.1.
 |φ(z1,z2,z3)|≤ ⎷9−4√3r+12r2−(3+2√3r)√9−20√3r+12r29−4√3r+12r2+(3+2√3r)√9−20√3r+12r2=89√3r+3227r2+O(r3)

for any .

Here stands for the product of and a convergent power series in .

###### Proof.

First we claim that if we see triangles as triangles in the form , then lies in the non-shaded region showed in fig. 2, which will be described below. To proof the claim, note that the length of the longest edge of a triangle with vertices in is at most , and the length of the shortest edge is at least . It follows that

 √3−2r√3+2r<|zj−zk||zj−zl|<√3+2r√3−2r (3.3)

with . Apollonius’ theorem says that if , then the locus is an euclidean circle centered at the real axis. Since is a positive oriented triangle, we have that the imaginary part of is positive. Inequalities (3.3) imply that can not lay in the shaded regions of fig. 1, and can not lay in the rotations by and of the shaded regions. Hence should lay in a curvilinear hexagon ‘centered’ at (see fig. 2). The claim is proved. Figure 1: The Apollonian circles CK1 and CK2, where K1=(√3−2r)/(√3+2r) and K2=1/K1, which have respectively diameter x1x2 and x3x4 with x1=2r−√34r,x2=√3−2r2√3,x3=√3+2r2√3,x4=√3+2r4r. Figure 2: Curvilinear hexagon centered at −λ2 with a symmetry group {I,R,R2}.

To conclude the proof of the lemma, consider the vertex

 ζ=12+i√9−20√3r+12r22(√3+2r)

showed in fig. 2. The points are also vertices of the curvilinear hexagon. The transformationation maps the circle through onto a circle of radius

 ∣∣M(ζ)∣∣= ⎷9−4√3r+12r2−(3+2√3r)√9−20√3r+12r29−4√3r+12r2+(3+2√3r)√9−20√3r+12r2

centered at the origin.

We have , and with is a degenerated triangle.

The first two coefficients of the Taylor series result from a straightforward calculation. ∎

Now we deal with perturbations of a general triangle .

Notice that the unique affine transformation that takes the equilateral triangle to a non-degenerated triangle is

 λ2z1+λz2+z33z+λz1+λ2z2+z33¯¯¯z+z1+z2+z33. (3.4)

In order to give a geometric interpretation to the affine transformation , we set , and . Then is equal to

 rei(ϕ1+ϕ2)/2[(|α|+|β|)cos(ϕ1−ϕ22+θ)+i(|α|−|β|)sin(ϕ1−ϕ22+θ)]+γ.

Therefore maps a circle of radius onto an ellipse with major axis of length inclined at angle with the real axis, and minor axis of length . It is convenient introduce to denotes the open (i.e. without boundary) ellipse with major axis of length inclined at angle with the real axis, minor axis of length , and centered at the point . The proof of the next result is immediate from the above geometric interpretation for affine transformations.

###### Lemma 3.2.

Given and a non-degenerated triangle, we set

 aeiϕ1=λ2z1+λz2+z33,beiϕ2=λz1+λ2z2+z33,

with . Let where . Then the affine transformation such that takes to maps triangles with vertices in (see eq. (3.2)) onto triangles with vertices in .

By the proof of lemma 3.1, triangles are similarity equivalent to triangles with in a region inside the circle through , where

 ζ=12+i√9−20√3r+12r22(√3+2r),

and this circle is mapped by to a circle centered at the origin. Circles centered at the origin are preserved under multiplication by , therefore is preserved under . Hence is a circle with diameter between and

 ξ=M−1(−M(ζ))=12+i3(√3+2r)2√9−20√3r+12r2.

The hypothesis in the next result are the same as in the previous lemma.

###### Theorem 3.3.

Given and a non-degenerated positively oriented triangle , we set

 aeiϕ1=λ2z1+λz2+z33,beiϕ2=λz1+λ2z2+z33,

with . Let where . Then the triangles with vertices in are similar to triangles with in a region inside of the ellipse

 Ew(2√3ρ(a+b)|z2−z1|,2√3ρ|a−b||z2−z1|,ϕ1+ϕ22−arg(z2−z1))

where

 w=12−√3(z1+z2−2z3)(9+12r2−4√3r)6(z2−z1)(√3+2r)√9−20√3r+12r2,ρ=8√3r(√3+2r)√9−20√3r+12r2.
###### Proof.

We saw above that triangles are similar to triangles with inside the circle of radius

 ρ=|ξ−ζ|2=8√3r(√3+2r)√9−20√3r+12r2

centered at ; but now we are concerned with triangles with vertices in .

Let be an affine transformation of the form on . We have , which is similar to . That is, the affine transformation , acting on the three vertices of the triangles, translates to the affine transformation acting on the vertex of . We apply this remark to the transformation where and are the affine transformations which maps respectively to and to . For this , the corresponding is

 h(τ)=(λ−1)aeiϕ1z2−z1τ+(λ2−1)beiϕ2z2−z1¯¯¯τ.

Finally, the circle is mapped by to the ellipse

 Ew(2√3ρ(a+b)|z2−z1|,2√3ρ|a−b||z2−z1|,ϕ1+ϕ22−arg(z2−z1))

where

###### Remark 3.4.

To obtain a bound for the image under of triangles with vertices in , it is sufficient apply the transformation (see equation (3.1)) to the ellipse

 Ew(2√3ρ(a+b)|z2−z1|,2√3ρ|a−b||z2−z1|,ϕ1+ϕ22−arg(z2−z1))

of theorem 3.3.

## References

•  E. Chávez, G. Navarro, R. Baeza-Yates, and J.L. Marroquin, Searching in metric spaces, ACM Computing Surveys 33 (2001), no. 3, 273–321.
•  J. Chris Ficher, D. Ruoff, and J. Shilleto, Perpendicular polygons, Amer. Math. Monthly 92 (1985), no. 1, 23–37.
•  Olli Lehto, Univalent functions and teichmüller spaces, Graduate Text in Mathematics, vol. 109, Springer-Verlag, 1987.
•  Jorge L. López-López, The area as a natural pseudo-Hermitian structure on the spaces of plane polygons and curves, Diff. Geom. Appl. 28 (2010), no. 5, 582–592.
•  Barbara Zitová and Jan Flusser, Image registration methods: a survey, Image and Vision Computing (2003), no. 21, 977–1000.