of W
2
in Figure 4b are also neighbors of W
1
because,
due to wrapping, W
1
and W
2
are identified as the same
point. However, k-d tree methods for sorting and re-
trieving points do not work with wrapped angular co-
ordinates, and would fail to identify the neighbors to
the right of W
2
as neighbors of W
1
also.
To avoid this wrapping of angular coordinates,
Peidr
´
o et al. (2018) proposed using the sines s
j
and
cosines c
j
of angles as the variables of the problem,
instead of working with the angles j directly, impos-
ing the additional constraint: s
2
j
+c
2
j
= 1. This indeed
avoids the problem of wrapping and permits using k-
d trees to sort and search points, since the sines and
cosines do not wrap as their angles, but it also has the
drawback of doubling the dimension of the problem,
which increases computational time: each original an-
gular variable j is substituted by two variables (the
sine and cosine of j). In this paper, we propose an al-
ternative method for searching points using k-d trees
when these points have angular coordinates that wrap
along the axes of the ambient space, without having
to double the dimension of such a space by unfolding
each angle into its sine and cosine.
The alternative method is as follows: in line 3 of
Algorithm 1, when using k-d trees to retrieve the set
N of neighboring points inside a box B centered at p
i
,
one must “replicate” this box if it intersects any of the
wrapping lines α = ±π or β = ±π, defining “replica
boxes” whose centers are translated a distance of 2π
along the wrapped axes. More formally, let us define
an auxiliary variable σ
α
as follows:
σ
α
=
+1 if B intersects the line α = +π
−1 if B intersects the line α = −π
0 otherwise
(37)
In (37), it is assumed that B will not intersect simul-
taneously both lines α = π and α = −π since this box
should be small, as in Figure 4b. Let us define an anal-
ogous variable σ
β
, by substituting every α in (37) for
β. After defining σ
α
and σ
β
, one only has to change
B in Eq. (35) for B, which is defined as follows:
B
p
i
,r
α
,r
β
=
|σ
α
|
[
u=0
|σ
β
|
[
v=0
B
uv
(p
i
,r
α
,r
β
,σ
α
,σ
β
) (38)
where:
B
uv
(p
i
,r
α
,r
β
,σ
α
,σ
β
) = B
p
i
− 2π(uσ
α
,vσ
β
),r
α
,r
β
(39)
and where B is defined as in Eq. (36). Equation (38)
effectively defines the union of 2
|σ
α
|+|σ
β
|
wrapped
copies or replicas of box B, with each copy being
translated a distance of 2π along each axis in or-
der to cover all the wrapped regions intersected with
the original box B
00
. For example, Figure 4b shows
two boxes B
1
00
and B
2
00
, which intersect the wrapping
lines α = ±π or β = ±π, and their wrapped repli-
cas {B
1
00
,B
1
01
} and {B
2
00
,B
2
01
,B
2
10
,B
2
11
}, whose cen-
ters are translated as indicated by Eq. (39).
Then, in order to retrieve the wrapped neighbors
of p
i
using k-d trees, one has to perform a search for
all points in k-d tree T whose coordinates fall in the
intervals defined by each box B
uv
separately.
Continuing with Algorithm 1, after retrieving all
neighbors p
j
of current point p
i
(including possible
wrapped neighbors), then the sign of e
3i
for the cur-
rent point p
i
is compared to the sign of e
3 j
for each
neighbor. If e
3
changes sign between p
i
and any p
j
of its neighbors, a solution exists between them, and
this solution is approximated by a linear interpolation
between p
i
and p
j
, by enforcing e
3
= 0. This linear
interpolation is performed between lines 6-9 of Algo-
rithm 1. Note that not only the coordinates (α,β) are
interpolated, but also z (line 8). Recall that the values
of z and e
3
are stored in each companion point ˜p
i
of
p
i
computed during the first step of the method. Note
also that, in case of wrapping, when interpolating α
and β in lines 6-7, the values of (α
i
,β
i
) must be those
of point p
i
translated by the displacement of Eq. (39).
After this linear interpolation, an approximate so-
lution s
∗
is obtained (line 9 of Algorithm 1). This
solution is compared to all other solutions stored in S
so far (line 10), and if this solution is not similar to the
previously stored solutions (i.e., if it does not belong
to small boxes centered at other solutions, line 10),
then it is regarded as a new solution and it is stored
in S (line 15). Before storing a new solution, how-
ever, it is refined through Newton-Raphson method
for nonlinear systems, which converges very quickly
(in about 2-3 iterations) to a very accurate solution,
since the starting approximate solution obtained by
linear interpolation is already very close to the ex-
act one. Newton-Raphson method is applied between
lines 11-14, in which ∆s
∗
is the improvement of the
solution in each iteration, ε is a small threshold be-
low which further improvements are considered neg-
ligible (stop criterion), and F and J are the constraint
vector function and its Jacobian matrix, respectively,
which are defined as follows: F = [e
1
,e
2
,e
3
]
T
and
J =
∂e
1
/∂α ∂e
1
/∂β ∂e
1
/∂z
∂e
2
/∂α ∂e
2
/∂β ∂e
2
/∂z
∂e
3
/∂α ∂e
3
/∂β ∂e
3
/∂z
(40)
where e
i
are functions of s = [α,β,z]
T
, defined in
Eqs. (1)-(3). Since s
∗
will change little during New-
ton iterations, matrix J
−1
may be computed only once
before refining each solution s
∗
(right before line 11)
and kept constant in line 12, which saves computa-
tions without impeding fast convergence.
Solution of the Forward Kinematic Problem of 3UPS-PU Parallel Manipulators based on Constraint Curves
331