Spatial reasoning about qualitative shape compositions

Shape composition is a challenge in spatial reasoning. Qualitative Shape Descriptors (QSD) have proven to be rotation and location invariant, which make them useful in spatial reasoning tests. QSD uses qualitative representations for angles and lengths, but their composition operations have not been defined before. In this paper, the Qualitative Model for Angles (QMAngles) and the Qualitative Model for Lengths (QMLengths) are presented in detail by describing their arity, reference systems and operators. Their operators are defined taking the well-known temporal model by Allen (Commun. ACM 26(11), 832–843 (1983). https://doi.org/10.1145/182.358434) as a reference. Moreover, composition tables are built, and the composition relations of qualitative angles and lengths are proved using their geometric counterparts. The correctness of these composition tables is also proved computationally using a logic program implemented using Swi-Prolog.


Introduction
Qualitative modelling [9] concerns the representations and reasoning that people use to understand continuous aspects of the world. Qualitative Spatial and Temporal Representations and Reasoning (QSTR) [3,15,27] models and reasons about time (i.e. coincidence, order, concurrency, overlap, granularity, etc.) and also about properties of space (i.e. topology, location, direction, proximity, geometry, intersection, etc.) and its evolution between continuous neighbouring situations. So maintaining the consistency in space and time are the basics in qualitative reasoning when solving spatial and temporal problems.
Shape composition is a challenge in spatial reasoning. Qualitative Shape Descriptors (QSD) have proven to be rotation and location invariant, have been applied to compute shape similarity [7], and they have also been effective in mosaic building [8]. This paper is a step towards proving that QSD can be used for solving shape composition tasks (e.g. solving Tangram puzzles). Qualitative descriptors of shape include qualitative angles and qualitative lengths that describe the boundary of objects. When juxtaposing two objects, that is, placing them close together, some angles and lengths of the final boundary are transformed. For inferring the resulting angles and lengths of the final shape, composition tables can be built.
The main contribution of this paper is presenting the operations that can be applied to the qualitative model for angles and lengths which are defined taking the well-known Allen's temporal relations [1,2] as a reference. Using these operators, the geometric counterparts of the composition of qualitative angles and lengths are shown. Moreover, the composition relations of angles and lengths needed to solve shape composition challenges (see Section 3) in LogC-QSD [23] are provided and their correctness is proved.
The rest of this paper is organized as follows. Section 2 presents related work in the literature. Section 3 presents the challenge of shape composition in spatial tests. Section 4 provides an outline of the Qualitative Shape Descriptor (QSD) [7] which can be used for describing the objects involved in the spatial reasoning text. Section 5 details the Qualitative Model for describing Lengths (QMLengths), its arity, its reference system and its operators, and it also presents its geometric counterparts. The composition of qualitative angles with respect to these operators is presented and its correctness is also proved. Section 6 details the Qualitative Model for describing Angles (QMAngles), its arity, its reference system and its operators, and it also presents their geometric counterparts. The inverse and composition relations of qualitative angles with respect to the operators is also presented and its correctness is also proved. Section 7 presents a Swi-Prolog implementation of both models QMLengths and QMAngles to prove its correctness computationally. Section 8 shows how both models can be used for shape composition [23] using an example. Section 9 discusses about the nature of the provided composition tables. Finally, conclusions and future work are provided.

Related work
Qualitative calculus and its algebraic properties have been studied in the literature [14,16]. However, there is very few research works dedicated to prove the validity of composition tables used by qualitative calculi: -Wolter [34] analysed the algebraic properties of the following qualitative calculi: Allen's temporal interval algebra [1], the point calculus [28], the qualitative spatial LR calculus [17] and the double cross calculus (DCC) [11]. The computational properties of these calculi were analysed using SparQ [30]. -Ghourabi and Takahashi [12] also proved the validity of the composition table used in the temporal calculus by [1]. -Dylla et al. [5] carried out a detailed survey on algebraic properties of qualitative spatiotemporal calculi which included also proofs for the 9-Intersection calculus of simple 2D regions [6], the cardinal direction calculus [10,13], the calculus for the oriented pointrelation algebra (OPRA) [19,20], the qualitative trajectory calculus (QT C) [31,32], the region connection calculus (RCC-5, RCC-8) [24], etc. However, this survey did not included any proof for demonstrating qualitative angle composition and qualitative lengths composition.
All these works inspired the current paper, whose main aim is to proof the validity of the composition tables used previously by the LogC-QSD approach [23] in shape composition operations. The construction of these tables is presented and discussed here.
As far as the authors are concerned, there is no previous work that prove composition tables relating angles and lengths of a shape. Museros et al. [21] presented composition tables of angles and lengths. However, there is no proof of the validity of these tables, which correspond to a coarse shape descriptor and whose tables are also different from those used by the LogC-QSD approach [23].

The Challenge
Spatial cognition studies have shown that there is a strong link between success in Science, Technology, Engineering and Math (STEM) disciplines and spatial skills [22,29]. Spatial reasoning questions in psychometric tests (i.e. those by [18]) involve object composition questions. An example of a test question is showed in Fig. 1. The instructions provided are the following: Take a look to the presented shapes. Note the letters on the side of each shape. Join these shapes together with the corresponding letters to make the corresponding shape. Look at the given shapes and decide which of the examples matches the final shape built when all the shapes joined together by the corresponding letters. You have 3 minutes to answer 8 questions.
The shapes of the objects showed in Fig. 1 can be qualitatively described by the Qualitative Shape Descriptor (QSD) by [7] and combined with a network of connections and composition operators regarding the angles and lengths, the final composed shape can be inferred [23]. This paper presents and prove the geometric correctness of these composition tables.

The Qualitative Shape Descriptor (QSD * )
Given a two-dimensional object, the Qualitative Shape Description (QSD) [7] abstracts the relevant points of its boundary. Thus a set of relevant points, denoted by P 0 ,P 1 ,...,P N , determines the shape of the object.
Each relevant point P i is described depending on the relation appearing between P i and the previous point, P i−1 , and P i and the following point, P i+1 : Each QSD i is composed by the following features, which are defined as: Using an extended QSD * descriptor, a shape can be expressed as a set of: -logical facts as: QSD * ∀P ∈ Obj ect ∃hasQSDpoint (Object, P , X, Y, qsd(EC Label , AT C Label , C Label , L Label )).
-or lists of strings extracted from these facts, such as: [[EC 1 , A 1 |TC 1 , L 1 , C 1 ],· · · ,[EC n , A n |TC n , L n , C n ]] where n is the total number of relevant points in the object, starting by the closest to the upper-left corner of the object, and the rest of the relevant points are arranged cyclically in a clockwise direction.
For example, the QSD * corresponding to the object in Fig. 2  Note that p 1 is located at coordinate (-1.2,4), it connects two straight lines, it defines an obtuse and convex angle, and its length is medium. The rest of shape determining points are described similarly.
The QSD * can also be represented as a Prolog list: It is important to note that the reference systems that define the qualitative concepts representing the features Angle, Type of Curvature and Compared Length are based on interval values (A I NT , TC I NT and L I NT , respectively). Thus they can be calibrated using different granularities according to the final application and system.

The qualitative model for length
A detailed description for the qualitative length magnitude representation is provided in this section, where its arity, reference system and operators are explained.
Length = L A , L RS , L OP

Length Arity (L A )
The number of entities implied in each relation is defined as the arity. Length is defined geometrically by a straight segment with a starting and ending point a a (Fig. 3). The length magnitude is obtained by operating on those points: a −a . For simplicity, it can be assumed that a = 0, so the length magnitude is determined by a.
Note that QSD * can describe points that connect straight lines but also curves. So, as the length of straight lines has always arity two, that is it is always calculated by two points, the arity corresponding to the length of a curve can be larger, depending on how it is calculated (e.g. a calculation by approximation to straight segments involves that the finer the approximation, the use of more points, so the larger the arity).

Length Reference System (L RS )
A reference system (RS) is defined as the set of relations between the objects and it depends on the level of granularity considered. Formally, this set of relations contains a set of qualitative symbols and a set of structure relations which define the acceptance areas or interval values for each qualitative symbol.
The length is a quantitative continuous magnitude that can be compared and discretised using the following Length Reference System or LRS = {uL, L LAB , L I NT }, where uL or unit of Length refers to the chosen relation for comparing edges; L LAB refers to the set of labels for length; and L I NT refers to the values of uL related to each label. In object composition operators, the length comes from relating an edge from an object with another edge from a different object. And, as all the objects involved in the composition are known, the largest object is taken as a reference and the rest of the edges are compared in relation to it. As Fig. 4 shows, the edges in Tangram pieces are related to each other. Thus,   Fig. 4. These relations are obtained by trigonometry as Table 1 shows. Note that this discretisation of length in L I NT 1 was chosen because it particularly fits the relationships existing among the Tangram pieces as Fig. 4 shows.

Length operators (L OP )
When composing lengths, the operators associated to a representation correspond to the possible actions or situations in which the lengths can take part. So, which are the operations we can carry out with qualitative lengths?  Allen's calculus [1,2], which presents 13 binary relations that define all possible time arrangements between two events -equal, before/after, meets/is met by, overlaps/is overlapped by, starts/is started by, finishes/is finished by, during/includes, see Table 2-can be taken as a reference for studying compared length relations.
Thus, relations between lengths can be defined as Allen defined relations between time intervals. The operations that can be used for length composition regarding the edge of the pieces are the following: The relation meet (m) is shown by Fig. 1 (option A): note that the left edge of the triangle meets the left edge of the square, so they have ending and starting points in common and therefore, the final length of the shape boundary can be calculated by composition.
The relation start (s) is shown by Fig. 1 (option A): note that the down edge of the triangle starts the upper edge of the square, so they have both starting points in common and therefore, the final length of the shape boundary can be calculated by composition.
The relation finish (f) is shown by Fig. 1 (option D): note that the down edge of the pentagon is finished by the upper edge of the triangle, so they have both ending points in common and therefore, the final length of the shape boundary can be calculated by composition.
However, our study case involves object composition and therefore, some restrictions are involved, e.g. overlapping of objects is not allowed. Thus, these are the relations between lengths which do not allow composition: equal, note that if two edges are juxtaposed and they are equal, there is no length feature to describe by the QSD. For example, in Fig. 1 (option A) the down edge of the square and the upper edge of the pentagon, they are equal and therefore, they do not take part in the boundary of the final shape. before/after, note that there is no juxtaposition of lengths in this case.
overlap/is overlapped and during/includes, note that, in this cases, there is not enough known common points, so that the new lengths can be calculated qualitatively by composition. So, for these cases, new quantitative points must be found out.

Composition of qualitative lengths
Let p i , q i be two points described according to the QSD * , . Then, let us name the length of the segments starting at p i and q i as L p , L q , respectively, which are defined as: If L p and L q meet (m), that is, L q starts as L p ends, L pq = L p i q i+1 , then, they can be composed as follows: composition L (L p , L q ) = L pq where L p , L q and L pq are described according to the Length Reference System (LRS). The resulting length L pq is obtained according to the composition table shown in Table 3.
If L p and L q start (s) together, then L pq = L p i+1 q i+1 . And if L p and L q f inish(f ) together, then L pq = L p i q i . Thus a decomposition is required in order to find the final length at the corresponding edge. This decomposition operation can be easily obtained from Table 3 since: For that, the greater length is selected as L pq and the shorter as L p . Thus, L q is calculated by finding all the entries of the table that when combined with L p produce L pq .

Proof of the geometric correctness for the length composition
In this section, the geometric correctness of the composition table showed in Table 3 is proved. In Table 2 it can be observed that the LRS defines qualitative lengths as segments of exact length (e.g. short(s) = a/4) but also as segments with variable length (e.g. larger-long (ll) ∈ (a, ha)). The composition table relates all the different combinations of qualitative lengths, thus four possible cases of compositions need to be distinguished: -composing segments of exact length, -composing segments of variable length, -composing a segment of variable length with a segment of exact length, and -composing a segment of exact length with a segment of variable length.
In the following sections, these compositions are illustrated geometrically and proved using examples taken from the composition table.

Composing segments of exact length
LetS 1 be a segment of exact length defined by a and b, andS 2 another segment of exact length defined by a and b . The composition of qualitative lengths defined byS 1 andS 2 , that is,S 1 •S 2 , is a segment defined by a and b . This can be represented geometrically as follows:  Without loss of generality let us assume that a = a = a = 0. On the other hand, b is obtained from the previous data as follows: And then, in order to calculateS 1 •S 2 it suffices to obtain the qualitative length (L LAB ) and its corresponding interval (L I NT ) where b is included.
Let us exemplify this by composing the following qualitative lengths from LRS: Then, b is first obtained as: At this point the L LAB that fulfills that b ∈L I NT , must be obtained. Thus note that Since sl is the only L LAB whose interval includes b . Therefore the composition s • m is proved to correspond to the qualitative length smaller-long (sl) indicated by the composition table in Table 3: It is worth noting that, ifS 1 andS 2 are exact segments,S 1 •S 2 corresponds to only one concept of qualitative length (i.e. one value in the composition table). That is, there is no uncertainty obtained.
Finally, note that the rest of the cases composing two qualitative lengths L LAB involving two segments of exact lengths are solved following the same procedure.

Composing segments of variable length
LetS 1 be a segment of variable length defined by a, b 1 and b 2 , andS 2 another segment of variable length defined by a , b 1 and b 2 . Then,S 1 •S 2 generates a segment defined by a , b 1 and b 2 . This can be represented geometrically as follows: Without loss of generality let us assume that a = a = a = 0, and henceS 1 •S 2 can be calculated by obtaining b 1 and b 2 from the previous data as follows: Then, the qualitative lengths L LAB must be obtained which correspond to the intervals L I NT that intersect with the interval between b 1 as the lower length value and b 2 as the upper length value.
Thus, the composition lm • ll is proved to correspond to the qualitative length largerthan-longest (llst) indicated by the composition table in Table 3: Observe that llst is the longest interval and it is the result of composing lengths with high magnitude.
As a second example, let us consider the following lower magnitude lengths from LRS: So let us study which L LAB fulfills that (b 1 , b 2 ) intersects L I NT , and obtain that: Hence the composition ss • ss is proved to correspond to the set of qualitative lengths indicated by the composition table in Table 3: Note that, in this case, some uncertainty is obtained by the composition operation since any of the previously indicated results can be obtained.

Composing a segment of variable length with a segment of exact length
LetS 1 be a segment of variable length defined by a, b 1 and b 2 , andS 2 a segment of exact length defined by a and b . ThusS 1 •S 2 generates a segment defined by a , b 1 and b 2 . This can be represented geometrically as follows: Without loss of generality let us assume that a = a = a = 0, and then b 1 and b 2 are obtained from the previous data: Then,S 1 •S 2 can be calculated by finding the L LAB which fulfills that (b 1 , b 2 ) intersects with the corresponding L I NT . Let us exemplify this by composing the following qualitative lengths from LRS: intersects only the interval (a/2, ha/2), that is, the L LAB associated to lm, since a/2 < 0.6a and ha/2 > 0.7a.
Thus the composition ql • ls is proved to correspond to the qualitative length largermedium (lm) indicated by the composition table in Table 3: Note that the rest of the cases composing two qualitative lengths L LAB involving two segments of variable lengths are solved and proved following the same procedure. Without loss of generality let us assume that a = a = a = 0, and b 1 and b 2 are obtained from the previous data as follows

Composing a segment of exact length with a segment of variable length
Again,S 1 •S 2 is calculated by finding the L LAB which fulfills that (b 1 , b 2 ) intersects with the corresponding L I NT . Let us exemplify this by composing the qualitative lengths from LRS of last example. In this way it can be seen that the composition • is in fact a symmetric operation.
Thus the composition ql • ls is proved to correspond to the qualitative length largermedium (lm) indicated by the composition table in Table 3:

The Qualitative Model for Angles
A detailed description for the qualitative angle magnitude representation is provided in this section, where its arity, reference system and operators are explained.

Arity of Angle (A A )
The number of entities implied in each relation is defined as the arity. An angular relation (α) is defined by three points a, b, c. Thus the angular relationship is quaternary: α is defined geometrically wrt the three independent entities acb (Fig. 5).

Angle Reference System (A RS )
A reference system is composed of a set of relations depending on the level of granularity considered which contains a set of qualitative symbols and a set of structure relations which define the acceptance areas or interval values for each qualitative symbol.
Angles  1 have a broader granularity, whereas the A LAB 2 and A I NT 2 use a finer granularity level. The A LAB 2 and A I NT 2 is selected for our scenario since manufactured objects usually use right angles (and its derivatives: half-right, three-quarters of right and plane), so humans recognize them easily. These are also the angles used by pieces in Tangram puzzles, as Fig. 4 shows.
The Convexity feature at c is related to the Angle and the interior and exterior of the shape that QSD is describing. Geometrically, considering the relevant points of the shape ordered clockwise, an oriented line can be built from a to b, and if c is on the left of the segment, then P i+1 is convex; otherwise c is concave. Note that mathematically c cannot be within the oriented line from P i−1 to P i+1 , otherwise P i cannot be a relevant point of the shape. Note also that a convex angle refers to the angle located in the interior of the object, while a concave angle refers to the angle on the exterior of the object. Table 4 presents the geometrical representation of the qualitative angles defined by A LAB 2 and its convexities/concavities.

Angle operators (A OP )
When composing angles, the operators associated to a representation correspond to the possible actions or situations in which the angles can take part. So, which are the operations we can carry out with qualitative angles?
As in the case of the operators for length, Allen's calculus [1,2] is taken as a reference (see Table 2).
The spatial relationships between angles can be defined similarly to Allen's relations between time intervals. Table 5 illustrate geometrically these angular relations: disjoint: two angles (α, α ) are disjoint if they do not share any of a, b, c.
same: two angles (α, α ) are the same if they share a, b, c and its convexity (i.e. its interior) 1 inverse: two angles are inverse if they share a, b, c but its convexity is different, that is, they do not share their interior. As our study case involves shape composition by juxtaposing objects, this excludes overlapping, so the following relations are not suitable for angle composition: same: note that if two angles are the same, that involves overlapping when composing them and the purpose of our study case is building new shapes by juxtaposition, not by overlapping.  Table 5 Spatial relationships between angles in the composition operation: A OP . These are inspired also in Allen's relation in Table 2 disjoint: note that if two angles are disjoint, then there is no composition of angles possible, since they need at least to share two points. overlap/is overlapped and during/includes: note that there is not enough known common points in these cases for the new lengths to be calculated qualitatively by composition. In these cases, new quantitative points must be found out. Other relations that may happen when composing objects are those shown by Fig. 6. Note that, in the following situations, no composition of angles is possible: (1) angles share their centres but they are opposed, so there is not enough information to obtain a new composed qualitative angle. (2) angles do not share their centres, but they share their starting and ending points.
Although they share some features, these features cannot be used to infer a new composed angle according to our operators. In this case, if at least one angle is concave, they may generate a hole. Similarly to the previous situation, although they share features, they cannot generate a composed angle and they also may generate a hole.
Thus, the operators that can be applied for angle composition when building new objects with pieces are the following:

A OP = {inverse(i), meet (m), start (s), f inish(f )}
where: inverse(i) operator involves changing the interior of the angle. Note that Table 5 shows its geometric description and it is described logically in the next section. -meet (m) operator allows composition of convex angles. Note that the geometric description of composing two angles by the operator meet is shown in Table 5. Next, Section 6.5 defines the composition operation formally and Table 7 presents the  obtained composition table. start (s) and f inish(f ) operators allow composition of convex and concave angles.
Note that Table 5 presents their corresponding geometric description. Section 6.5 defines this composition formally and the composition table is given by Table 8.
Note that, for composition, both angles need to share c = c and a pair of the extremes (a, a , b, b ) at least. And these operators ensure this.

Defining the inverse of qualitative angles
The inverse operator is defined as follows. Let p i be a point described according to the QSD * , and let A p i , C p i be its angle and convexity respectively, its inverse is defined as follows: where A p i ∈ A RS and C p i ∈ {cx, cv} as defined in QSD * . Note that Table 6 provides the inverses for all qualitative angles defined by A RS and that Table 4 shows its geometric counterparts. An angle and its inverse complete the space, that is, if they are composed they got 360 • , the f ull qualitative angle.

Defining the composition of qualitative angles
Let p i , q i be two points described according to the QSD * , that is: Let A p i , C p i and A q i , C q i be their angles and their convexities respectively, then the composition of these angles is defined as follows: where A p i , A q i , A pq ∈ ARS and C p i , C q i , C pq ∈ C defined in QSD * . The resulting operator is obtained from the composition table shown in Table 7, if both angles are convex, or from the composition table shown in Table 8, if one of the angles involved is concave. The grey cells in Tables 7 and 8 refer to resulting concave angles whereas white cells refer Note that the angles are abbreviated according to the ARS presented in Section 4 and that grey cells refer to resulting concave angles while white cells refer to resulting convex angles Note that the angles are abbreviated according to the ARS presented in Section 4 and that the full angle is referring to 360 degrees to resulting convex angles. Note that the compositions in these tables take the angles located at p i and q i and that compositions obtaining an angle greater than 360 • are not possible. This composition operator is binary, that is, it takes two angles at a time, but it can be applied as many times as angles occurring at a connection. So, if another angle is involved (i.e. A t ) the result of the previous composition can be composed again with this angle. Thus, let A pq , C pq be the resulting angle and convexity of the previous operator, and let A t , C t be another angle and its convexity, then the composition between them is defined as follows:

composition AC (A pq , C pq , A t , C t ) =< A pqt , C pqt >
where A pqt ∈ ARS and C pqt ∈ C defined in QSD * .
For example, Fig. 1 (option C) shows a shape composition where 3 composition of angles must be calculated: two situations involving 2 angles, and one situation involving 3 angles.

Proof of the geometric correctness for convex angle compositions with the operator meet
In this section, the geometric correctness of the composition table showed in Table 7 is proved. In Table 2 you can observe that the ARS defines qualitative angles of exact amplitude (e.g. hr ≈ 45) but also defines angles with variable amplitude (e.g. acute (a) ∈ [46, 89]). The composition table relates all the qualitative angles, thus four possible cases of compositions need to be distinguished: -composing angles of exact amplitude, -composing angles of variable amplitude, -composing an angle of variable amplitude with an angle of exact amplitude, and -composing an angle of exact amplitude with an angle of variable amplitude.
In the following sections, these compositions are illustrated geometrically and proved using examples taken from the composition table.

Composing angles of exact amplitude
Let A 1 be an angle of exact amplitude defined by a, b and c, and A 2 another angle of exact amplitude defined by a , b and c . Thus the composition of qualitative angles defined by A 1 and A 2 , that is, A 1 • A 2 , is an angle defined by a , b and c . This can be represented geometrically as follows: Note first that, without loss of generality let us assume that a = a = a = 0. Moreover, c = c = c by the meet operator. So it remains to obtain b , which can be calculated from the previous data as follows: Then, to obtain A 1 • A 2 let us find out the qualitative angle (A LAB ) and its corresponding interval (A I NT ) where b is included. Let us exemplify this by composing the following qualitative angles from A RS : Thus b is obtained as indicated previously Hence it is clear that the only qualitative angle whose corresponding interval includes b is 3qr/ cx (i.e. 135). And the composition hr/ cx • r/ cx is proved to correspond to the qualitative angle 3qr indicated by the composition table in Table 7: Note that, if A 1 and A 2 are exact segments, A 1 • A 2 corresponds to only one concept of qualitative length (i.e. one value in the composition table).

Composing angles of variable amplitude
Let A 1 be an angle of variable amplitude defined by a, c, b 1 and b 2 , and A 2 another angle of variable amplitude defined by a , c , b 1 and b 2 . Then, A 1 • A 2 generates an angle defined by a , c , b 1 and b 2 . This can be represented geometrically as follows: Note first that, without loss of generality let us assume that a = a = a = 0. Moreover, c = c = c by the meet operator. So it remains to obtain b 1 and b 2 , which can be calculated from the previous data as follows: Hence A 1 • A 2 is obtained finding those qualitative angles (A LAB ) whose associated intervals (A I NT ) are contained in (b 1 , b 2 ). Let us exemplify this by composing the following qualitative angles from A RS : Taking into account the indications above, we first obtain b 1 , b 2 : Since the only qualitative angles (A LAB ) whose associated intervals (A I NT ) are contained in (90, 180) are o/ cx , 3qr/ cx , vo/ cx , the composition of an angle very-acute and another angle obtuse, both convex, by the operator meet is proved to correspond to the qualitative angles obtuse three-quarters-right and very-obtuse, all convex, as indicated by the composition table in Table 7:

Composing an angle of variable amplitude with an angle of exact amplitude
Let A 1 be an angle of variable amplitude defined by a, c, b 1 and b 2 , and A 2 an angle of exact amplitude defined by a , c , and b . Thus A 1 • A 2 generates an angle defined by a , c , b 1 and b 2 . This can be represented geometrically as follows: Again, without loss of generality let us assume that a = a = a = 0. In addition, c = c = c by the meet operator. So it remains to obtain b 1 and b 2 , which can be calculated from the previous data as follows: Hence A 1 • A 2 is obtained finding those qualitative angles (A LAB ) whose associated intervals (A I NT ) are contained in (b 1 , b 2 ). Let us exemplify this by composing the following qualitative angles from A RS : For that, first let us obtain (b 1 , b 2 ): Note that the only qualitative angle (A LAB ) whose associated interval (A I NT ) is contained in (225, 270) is o/ cx . Thus, the composition of a very-obtuse angle and a right angle (both convex) by the operator meet is proved to correspond to the qualitative angle obtuse, concave, as indicated by the composition table in Table 7:

Composing an angle of exact amplitude with an angle of variable amplitude
Let A 1 be an angle of exact amplitude defined by a, b and c, and A 2 an angle of variable amplitude defined by a , c , b 1 and b 2 . Then, A 1 • A 2 generates an angle defined by a , c , b 1 and b 2 . This can be represented geometrically as follows: Note first that, without loss of generality let us assume that a = a = a = 0. Moreover, c = c = c by the meet operator. So it remains to obtain b 1 and b 2 , which can be calculated from the previous data as follows: Hence A 1 • A 2 is obtained finding those qualitative angles (A LAB ) whose associated intervals (A I NT ) are contained in (b 1 , b 2 ). Again, let us exemplify this by composing the following qualitative angles from A RS : For that, let us obtain (b 1 , b 2 ): Note that, as in the previous case, the only qualitative angle (A LAB ) whose associated interval (A I NT ) is contained in (225, 270) is o/ cx . Thus, the composition of a very-obtuse convex angle and a right convex angle by the operator meet is proved to correspond to the qualitative angle obtuse and concave, as indicated by the composition table in Table 7:

Proof of the Geometric Correctness for Convex-Concave Angle Compositions with the Operator Meet
The composition of convex and concave angles (Table 8) is proved similarly as shown previously in Section 5.5. The only conditions to take into account are that: -the composition of an angle with its inverse (i.e. acute-convex and acute-concave) produces the f ull angle, and -the composition of an angle with a wider angle than its inverse is not possible ( ). Note that analytically this composition produces an angle that is greater than 360 • and that geometrically, this composition involves overlapping, which is not allowed in the study case.

Implementation
The Qualitative Model for Lengths and the Qualitative Model for Angles were implemented in Prolog programming language [26] and Swi-Prolog 2 was the testing platform [33]. The implemented Qualitative Model for Lengths (QMLengths) asks first for the maximum side of the object (i.e. a) to initialise the Length Reference System (LRS). Then it asks for the 2 points in 1D that define segmentĀ (i.e. its starting and ending point) and then it finds out the quantitative value of its length and its corresponding qualitative descriptor according to Table 1. Then, the QMLengths-approach asks for the 2 points that define segmentB, and after finding out its quantitative and qualitative values, it also obtains the relation between both segments,Ā andB, according to those defined in Table  2. If the relation obtained is meet (m), start (s), f inish(f ) or any of their inverses (i.e. met-by(m −1 ), started-by(s −1 ), or f inished-by(f −1 )) then the composition is calculated. The result calculated by the corresponding mathematical operation is shown and the result from the composition table is also obtained for comparison. Next, some examples of the QMLengths-approach are shown.
In the following example, the QMLengths-approach compose a segmentĀ of 2 units, which is labelled as ss by L RS , that is, a label which corresponds to a variable length, with a segmentB of 5 units, which is labelled as m by the L RS (exact length). The relation found is that segmentĀ is met by segmentB orB meetsĀ.
Note that the quantitative composition provides a segment of 7 units, which is labelled as lm by L RS . For the qualitative composition, the knowledge in Table 3 is used, which includes lm as one of the possible results ofĀ •B = {lm, hl, sl}.
Note that, when the exact numerical values of the segments are not known, the qualitative composition is still possible and provides comparable results. Note that, if the exact points defining a segment are not available, a qualitative composition is still possible and then, an uncertain result is still useful in contrast to no result at all.
In the following example, the QMLengths approach compose a segmentĀ of 6 units, which is labelled as sm by L RS (that is, a label which corresponds to a variable length) with a segmentB of 2 units, which is labelled as ss by the L RS (which also corresponds to a variable length). The relation found is that segmentĀ starts segmentB. In this case, the operator starts involves a decomposition operation, that is, we need to find out which length composed with segmentB provides segmentĀ. The quantitative decomposition provides a segment of 2 units, which is labelled as s by L RS . For the qualitative decomposition, the knowledge in Table 3 is used, that is, we need to find out which length combined with ss provides sm.
The results obtained correspond to the caption of the five columns {ss, s, ls, ql, sm} in the composition table shown in Table 3. Note that the numerical example provided corresponds to one of all those that were considered when building the composition table for lengths, since s is obtained as a result, but other results are also possible.
The following example is similar to the previous one since it involves decomposition, but note that the relation found between segmentĀ and segmentB is an inverse relation in Table 5: f inished by. That is,B f inishesĀ orĀ is f inished byB. The decomposition operation is explained as in the previous case.
In the situations where the composition of lengths is not possible due to the relation of the segments or to the lack of extra quantitative information, the QMLengths-program indicates it.
The implemented Qualitative Model for Angles (QMAngles) asks for the 3 coordinates in 2D that define angle A, and then it finds out the quantitative value of the angle in degrees and its corresponding qualitative descriptor according to Table 4. Then, the QMAnglesapproach asks for other 3 coordinates in 2D that define angle B, and after finding out its quantitative and qualitative values, it also obtains the relation between both angles, A and B, according to those defined in Table 5.
If the relation obtained is inverse(i), meet (m), start (s), f inish(f ) or any of their inverses (i.e. met-by, started-by, f inished-by) then the composition is carried out. The result calculated by the mathematical operation and the result obtained from the composition tables are shown.
Next, the QMAngles-approach compose convex angles, A and B, which are defined by qualitative labels which correspond to exact values in the reference system. The relation found out between both angles is that A meet B, so the composition is possible. For calculating the qualitative composition, the knowledge in Table 7 is used, which corresponds to the numerical composition.
In the following situation, the QMAngles-approach compose two angles A and B using the operator A is meet by B or B meets A. The qualitative label for A corresponds to an variable amplitude and B corresponds to a qualitative label with an exact amplitude. For the qualitative composition, the knowledge in Table 7 is used, which corresponds to the numerical composition.
In the next example, the QMAngles-approach compose two convex angles A and B that meet. The qualitative label for A corresponds to an variable amplitude, and angle B corresponds also to a qualitative label with variable amplitude. For the qualitative composition, the knowledge in Table 7 is used, which corresponds to the numerical composition.
Note that, in this case, the qualitative composition introduces some uncertainty. However, its advantage is that it can be carried out even if the exact numerical values of the angles are not known, in contrast to the quantitative composition.
In the next example, the QMAngles-approach compose a convex angle A with a concave angle B. The qualitative label for A corresponds to an variable amplitude and B corresponds to a qualitative label with an exact amplitude. The relation between both angles is: A is started by B, or B starts A. For the qualitative composition, the knowledge in Table 8 is used, which corresponds to the numerical composition.
In the last example, the QMAngles-approach compose a concave angle A with a convex angle B. The qualitative label for A corresponds to an variable amplitude and B corresponds also to a qualitative label with an variable amplitude. The relation between both angles is: A f inishes B. For the qualitative composition, the knowledge in Table 8 is used, which corresponds to the numerical composition. Note that, as in the case for lengths, the qualitative composition introduces some uncertainty. However, its advantage is that this qualitative composition can be calculated even if the exact numerical values of the angles are not known, in contrast to the quantitative composition, where no result can be obtained without the exact values. Thus, in some situations, some uncertainty is preferable to no result at all.
In the situations where the composition of angles is not possible due to the relation between the segments (i.e. overlaps, includes, during, etc.) or to the lack of extra quantitative information, the QMAngles-program indicates it.
More examples of executions of QMLengths and QMAngles programs are available to download together with the codes for further testing at: https://sites.google.com/site/ zfalomir/publications-by-zfalomir.

Application: QSD composition
The composition tables for lengths and angles presented and proved in this paper are applied by LogC-QSD approach [23] where a logical program solves a Dataset of 15 tests on shape composition.
Let us exemplify how the length and angle composition are useful to compose shapes described qualitatively by using the juxtaposition of the objects in Fig. 7.
Note that the triangles T 1 and T 2 are connected by points s 3 and r 2 , and its qualitative shape description is the following: Then, the angles are composed according to the composition tables: And, in this case, the length is taken from the point s 3 . Therefore, the composed QSD of the connection C 1 of objects T 1 -T 2 , that is, at point (s 3 , r 2 ), is [line -line, right, convex, long].
The other connection happening between objects T 1 and T 2 in Fig. 7 is defined by the line g 1 and the point s 1 . The features of g 1 are obtained from its source point, that is, r 2 . The features angles and convexities from s 1 are composed with the plane angle and the lengths are composed, requiring a subtraction/decomposition between r 2 and s 1 . Note that the same composition tables are used for the subtraction/decomposition operation, only changing the order of the variables.
So the composed QSD at the connection C 2 of objects T 1 -T 2 , that is, at point (g 1 , s 1 ) is obtained: [line-line, right, concave, [smaller-long, long, larger-long]].
For a more detailed description of object composition (i.e. more than two juxtaposed objects) please read [23].

Discussion: Qualitative spatial reasoning and weak composition
Relations in (most) qualitative temporal and spatial reasoning models are infinite, that is, their domains are infinite: there are many points or intervals in a line or time line and also infinite regions in a 2D or 3D space. Thus it is not feasible to apply algorithms to enumerate values of the domains. Instead qualitative relations (symbols) are used, and reasoning is carried out by manipulating symbols. This means that the calculus (which deals with extensional relations in the finite case) becomes intensional because it deals with symbols which stand for infinite relations [25]. That is, the fact that relations are infinite involves that there is no feasible way of dealing with them extensionally.
In Allen's model [1], although the domains are infinite, the compositions of the atomic relations are themselves unions of atomic relations. Note that genuine composition could lead to considering an infinite number of relations, whereas the basic idea of qualitative reasoning is to deal with a finite number of relations [25]. In order to overcome this issue, most calculi use weak composition as a way to approximate true composition.
In qualitative spatial and temporal reasoning, we deal with this issue by defining a small finite set A of jointly exhaustive and pairwise disjoint (JEPD) relations, that is, each possible tuple (a, b) ∈ D × D is contained in exactly one relation R ∈ A and the full set of relations is 2 A . And then, we exploit the nature of temporal and spatial domains, where points or intervals are ordered in a line or well-structured in space, so that composition can be computed using formal definitions of relations [14].
In this paper, for the QMLengths and the QMAngles, a composition table is a mapping τ : R × R → β(R), where R is a set of relational symbols. A model of R, τ is a pair U, v , where U is a set and v : R → Rel(U ) is a mapping such that {v(a) : a ∈ R} is a partition of U × U . Then, according to [4], the model is called consistent if c ∈ τ (a, b) ⇔ (v(a) • v(b)) ∩ v(c) = 0, for all a, b, c ∈ R. Then, a weak composition ( ) of two relations a, b is defined as the strongest relation in 2 A which contains a • b, or formally, a b = {c ∈ A | c ∩ (a • b) = 0}. Note that, as [16] mention: "the advantage of weak composition is that we stay within the given set of relations 2 A while applying the algebraic operators since 2 A is by definition closed under weak composition, union, intersection, and converse." So, as in Allen's model, we assume weak composition ( ) since we can use algebraic closure algorithm [16] to prove consistency. Thus Table 3 for QMLengths and Tables 7  and 8 for QMAngles are weak composition tables.
Note that, as [25] mentioned: "it turns out that the most important property of a qualitative calculus is not whether weak composition is equivalent to composition, but whether the relations are closed under constraints."

Conclusion
The Qualitative Model for Lengths and the Qualitative Model for Angles are presented in detail in this paper. For each one, its arity, reference systems and operators are provided. Allen's well-known time relations are taken as a reference for defining the operators applied in the Qualitative Model for Lengths and in the Qualitative Model for Angles. The definition of these operators are one of the main contributions of this paper.
The geometric correctness of the Qualitative Model for Lengths and the Qualitative Model for Angles has been proved in this paper to show that the qualitative results inferred using the composition tables are geometrically and analytically correct. This is the second main contribution in this paper.
Regarding the applicability of these models, note that the relations and compositions of angles and lengths are useful to automatically solve spatial reasoning tests regarding shape composition (e.g. Tangram puzzle). The composition tables for lengths and angles presented and proved in this paper are applied by LogC-QSD approach [23] where a logical program solves a Dataset of 15 tests on shape composition.
As future work, we intend to study in detail the properties of the composition functions presented in this paper (i.e. associative, commutative, etc.).