# Thread: Drawing lines on a Poincaré ball model

1. ## Drawing lines on a Poincaré ball model

Dear all, hi again,

Is it possible to draw lines in a Poincaré ball model by Mathematica 6.0?
To draw a line on a Poincaré ball model, we need two point in the unit open ball, and such lines are circular arcs that pass through the given two points and intersect the boundary of the unit open ball orthogonally.

Thanks.

2. I have coded the following:
Code:
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, s, {0, 2 Pi}]},
If[b c - a d == 0,
Line[{{a, b}, {c, d}}], {Red,
Circle[{(-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)), (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))},
Sqrt[((-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
a d - b c))^2 + ((
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
b c - a d))^2 - 4 s^2]/2, {0, 2 Pi}]}], {PointSize[Large],
Point[{0, 0}]}, {PointSize[Medium],
Point[{a, b}]}, {PointSize[Medium], Point[{c, d}]}},
ImageSize -> 300], {{s, 1, "s"}, 1, 5,
Appearance -> "Labeled"}, {{a, 1/2, "a"}, -s, s,
Appearance -> "Labeled"}, {{b, 1/2, "b"}, -Sqrt[-a^2 + s^2],
Sqrt[-a^2 + s^2], Appearance -> "Labeled"}, {{c, -1/3, "c"}, -s, s,
Appearance -> "Labeled"}, {{d, 1/3, "d"}, -Sqrt[-c^2 + s^2],
Sqrt[-c^2 + s^2], Appearance -> "Labeled"}]
Here $\displaystyle s$ is the radius of the blue ball, $\displaystyle P=(a,b)$ and $\displaystyle Q=(c,d)$ are two points inside the blue ball.
The problem now is how to draw the arc of the red circle that that combines $\displaystyle P$ and $\displaystyle Q$. :S

3. Originally Posted by bkarpuz
I have coded the following:
Code:
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, s, {0, 2 Pi}]},
If[b c - a d == 0,
Line[{{a, b}, {c, d}}], {Red,
Circle[{(-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)), (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))},
Sqrt[((-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
a d - b c))^2 + ((
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
b c - a d))^2 - 4 s^2]/2, {0, 2 Pi}]}], {PointSize[Large],
Point[{0, 0}]}, {PointSize[Medium],
Point[{a, b}]}, {PointSize[Medium], Point[{c, d}]}},
ImageSize -> 300], {{s, 1, "s"}, 1, 5,
Appearance -> "Labeled"}, {{a, 1/2, "a"}, -s, s,
Appearance -> "Labeled"}, {{b, 1/2, "b"}, -Sqrt[-a^2 + s^2],
Sqrt[-a^2 + s^2], Appearance -> "Labeled"}, {{c, -1/3, "c"}, -s, s,
Appearance -> "Labeled"}, {{d, 1/3, "d"}, -Sqrt[-c^2 + s^2],
Sqrt[-c^2 + s^2], Appearance -> "Labeled"}]
Here $\displaystyle s$ is the radius of the blue ball, $\displaystyle P=(a,b)$ and $\displaystyle Q=(c,d)$ are two points inside the blue ball.
The problem now is how to draw the arc of the red circle that that combines $\displaystyle P$ and $\displaystyle Q$. :S
The following code works fine:
Code:
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, s, {0, 2 Pi}]},
If[b c - a d == 0,
Line[{{a, b}, {c, d}}], {Red,
Circle[{(-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)), (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))},
Sqrt[((-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
a d - b c))^2 + ((
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
b c - a d))^2 - 4 s^2]/
2, {Min[If[
b >= (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d)),
ArcCos[Dot[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]],
2 Pi - ArcCos[
Dot[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]]],
If[d >= (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d)),
ArcCos[Dot[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]],
2 Pi - ArcCos[
Dot[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]]]],
Max[If[b >= (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d)),
ArcCos[Dot[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]],
2 Pi - ArcCos[
Dot[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{a - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
b - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]]],
If[d >= (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d)),
ArcCos[Dot[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]],
2 Pi - ArcCos[
Dot[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 + d s^2)/(
2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}, {1, 0}]/
Norm[{c - (-b c^2 + a^2 d + b^2 d - b d^2 - b s^2 +
d s^2)/(2 (a d - b c)),
d - (a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(
2 (b c - a d))}]]]]}]}], {PointSize[Medium],
Point[{0, 0}]}, {PointSize[Medium],
Point[{a, b}]}, {PointSize[Medium], Point[{c, d}]}},
ImageSize -> 300], {{s, 1, "s"}, 1, 5,
Appearance -> "Labeled"}, Delimiter, {{a, 1/2, "a"}, -s, s,
Appearance -> "Labeled"}, {{b, 1/2, "b"}, -Sqrt[-a^2 + s^2],
Sqrt[-a^2 + s^2],
Appearance -> "Labeled"}, Delimiter, {{c, -1/3, "c"}, -s, s,
Appearance -> "Labeled"}, {{d, 1/3, "d"}, -Sqrt[-c^2 + s^2],
Sqrt[-c^2 + s^2], Appearance -> "Labeled"}]

4. Code:
(*returns the first component of the center of the ortogonal circle*)
\

orcice1[s_, a_, b_, c_, d_] := (-b c^2 + a^2 d + b^2 d - b d^2 -
b s^2 + d s^2)/(2 (a d - b c));
(*returns the second component of the center of the ortogonal circle*)
\

orcice2[s_, a_, b_, c_, d_] := (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(2 (b c - a d));
(*returns the radius component of the ortogonal circle*)
orcira[s_, a_, b_, c_, d_] :=
Sqrt[(2 orcice1[s, a, b, c, d])^2 + (2 orcice2[s, a, b, c, d])^2 -
4 s^2]/2;
(*returns the argument of the number a+\[ImaginaryI]b between 0 and \
\[Pi]*)
ar02pi[a_, b_] :=
If[Arg[a + \[ImaginaryI] b] <= 0, Arg[a + \[ImaginaryI] b] + 2 Pi,
Arg[a + \[ImaginaryI] b]];
(*arc angle of the ortogonal circle combining (a,b) and (c,d) in the \
Poincaré ball with the radious s*)
aran[s_, a_, b_, c_, d_] :=
VectorAngle[{a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]}, {c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]}];
(*angle of the rotation transformation of the ortogonal circle's arc \
(a,b) and (c,d) in the Poincaré ball with the radious s*)
arro[s_, a_, b_, c_, d_] :=
If[Min[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]] + aran[s, a, b, c, d] ==
Max[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d], d - orcice2[s, a, b, c, d]]],
Min[ar02pi[a - orcice1[s, a, b, c, d], b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d], d - orcice2[s, a, b, c, d]]],
Max[ar02pi[a - orcice1[s, a, b, c, d], b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]]];
(*draws a gyroline passing through (a,b) and (c,d) in the Poincaré \
gyroline[s_, a_, b_, c_, d_] :=
If[a d - b c ==
0, {{Green, Opacity -> 0.4, Line[{{a, b}, {c, d}}]}, {Red,
PointSize[Large], Point[{a, b}]}, {Blue, PointSize[Large],
Point[{c, d}]}}, {Rotate[
Circle[{ orcice1[s, a, b, c, d], orcice2[s, a, b, c, d]},
orcira[s, a, b, c, d], {0, aran[s, a, b, c, d]}],
arro[s, a, b, c, d], {orcice1[s, a, b, c, d],
orcice2[s, a, b, c, d]}], {Red, PointSize[Large],
Point[{a, b}]}, {Blue, PointSize[Large], Point[{c, d}]}}];
(*manipulates the radius together with two points*)
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, 1, {0, 2 Pi}]},
gyroline[s, ar*Cos[aa], ar*Sin[aa], br*Cos[ba], br*Sin[ba]]}], {{s,
1, "s"}, 1, 5,
Appearance -> "Labeled"}, Delimiter, {{ar, 0.43, "ar"}, 0, s,
Appearance -> "Labeled"}, {{aa, 1.67133, "aa"}, 0, 2 Pi,
Appearance -> "Labeled"}, Delimiter, {{br, 0.366, "br"}, 0, s,
Appearance -> "Labeled"}, {{ba, 4.73752, "ba"}, 0, 2 Pi,
Appearance -> "Labeled"}]
I have problems with the code above.
I want to explain my algorithm for drawing a gyroline to request some help about my mistake:
Let $\displaystyle C$ be the unit disc, and $\displaystyle P$ and $\displaystyle Q$ be two points inside $\displaystyle C$.
If the angle between $\displaystyle P$ and $\displaystyle Q$ is $\displaystyle \pi$, then the gyroline passing through the points $\displaystyle P$ and $\displaystyle Q$ is the straight segment joining these two points.
If not, then we draw the orthogonal circle $\displaystyle C^{\prime}$ to $\displaystyle C$, which passes through the given points $\displaystyle P$ and $\displaystyle Q$, and the gyroline is the shorter arc segment between $\displaystyle P$ and $\displaystyle Q$.
To draw the gyroline in this present case, I first calculate the center $\displaystyle M^{\prime}$ and the radius $\displaystyle R^{\prime}$ of the orthogonal circle $\displaystyle C^{\prime}$, and then obtain the points $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$ by transforming the points $\displaystyle P$ and $\displaystyle Q$ by the transform vector $\displaystyle M^{\prime}$, respectively, i.e., $\displaystyle P^{\prime}:=P-M^{\prime}$ and $\displaystyle Q^{\prime}:=Q-M^{\prime}$.
Let $\displaystyle \theta$ denote the angle between the vectors $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$.
Then I draw a circle arc $\displaystyle J$ of $\displaystyle \theta$ radian length centered at the origin $\displaystyle M^{\prime}$.
Now the problem is how much radians should I rotate the arc $\displaystyle J$ about the point $\displaystyle M^{\prime}$ to fix it between the points $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$.
My solution that I believed to be true was as follows:
Let $\displaystyle \varphi$ be the rotation angle.
If $\displaystyle \min\{\mathrm{Arg}(P^{\prime}),\mathrm{Arg}(Q^{\pr ime})\}+\theta=\max\{\mathrm{Arg}(P^{\prime}),\mat hrm{Arg}(Q^{\prime})\}$ (the transformed arc $\displaystyle J^{\prime}:=J-M^{\prime}$ does not intersect the segment combining the points $\displaystyle (0,0)$ and $\displaystyle (1,0)$), then $\displaystyle \varphi:=\min\{\mathrm{Arg}(P^{\prime}),\mathrm{Ar g}(Q^{\prime})\}$ radians, where $\displaystyle \mathrm{Arg}$ is the positive angle between the given vector and $\displaystyle (1,0)$ (the argument of the corresponding complex number).
Otherwise (when $\displaystyle J^{\prime}$ intersects the segment combining the points $\displaystyle (0,0)$ and $\displaystyle (1,0)$), $\displaystyle \varphi:=\max\{\mathrm{Arg}(P^{\prime}),\mathrm{Ar g}(Q^{\prime})$.
But the code gives error while drawing the latter case.

Thanks.

5. Originally Posted by bkarpuz
Code:
(*returns the first component of the center of the ortogonal circle*)
\

orcice1[s_, a_, b_, c_, d_] := (-b c^2 + a^2 d + b^2 d - b d^2 -
b s^2 + d s^2)/(2 (a d - b c));
(*returns the second component of the center of the ortogonal circle*)
\

orcice2[s_, a_, b_, c_, d_] := (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(2 (b c - a d));
(*returns the radius component of the ortogonal circle*)
orcira[s_, a_, b_, c_, d_] :=
Sqrt[(2 orcice1[s, a, b, c, d])^2 + (2 orcice2[s, a, b, c, d])^2 -
4 s^2]/2;
(*returns the argument of the number a+\[ImaginaryI]b between 0 and \
\[Pi]*)
ar02pi[a_, b_] :=
If[Arg[a + \[ImaginaryI] b] <= 0, Arg[a + \[ImaginaryI] b] + 2 Pi,
Arg[a + \[ImaginaryI] b]];
(*arc angle of the ortogonal circle combining (a,b) and (c,d) in the \
Poincaré ball with the radious s*)
aran[s_, a_, b_, c_, d_] :=
VectorAngle[{a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]}, {c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]}];
(*angle of the rotation transformation of the ortogonal circle's arc \
(a,b) and (c,d) in the Poincaré ball with the radious s*)
arro[s_, a_, b_, c_, d_] :=
If[Min[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]] + aran[s, a, b, c, d] ==
Max[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d], d - orcice2[s, a, b, c, d]]],
Min[ar02pi[a - orcice1[s, a, b, c, d], b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d], d - orcice2[s, a, b, c, d]]],
Max[ar02pi[a - orcice1[s, a, b, c, d], b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]]];
(*draws a gyroline passing through (a,b) and (c,d) in the Poincaré \
gyroline[s_, a_, b_, c_, d_] :=
If[a d - b c ==
0, {{Green, Opacity -> 0.4, Line[{{a, b}, {c, d}}]}, {Red,
PointSize[Large], Point[{a, b}]}, {Blue, PointSize[Large],
Point[{c, d}]}}, {Rotate[
Circle[{ orcice1[s, a, b, c, d], orcice2[s, a, b, c, d]},
orcira[s, a, b, c, d], {0, aran[s, a, b, c, d]}],
arro[s, a, b, c, d], {orcice1[s, a, b, c, d],
orcice2[s, a, b, c, d]}], {Red, PointSize[Large],
Point[{a, b}]}, {Blue, PointSize[Large], Point[{c, d}]}}];
(*manipulates the radius together with two points*)
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, 1, {0, 2 Pi}]},
gyroline[s, ar*Cos[aa], ar*Sin[aa], br*Cos[ba], br*Sin[ba]]}], {{s,
1, "s"}, 1, 5,
Appearance -> "Labeled"}, Delimiter, {{ar, 0.43, "ar"}, 0, s,
Appearance -> "Labeled"}, {{aa, 1.67133, "aa"}, 0, 2 Pi,
Appearance -> "Labeled"}, Delimiter, {{br, 0.366, "br"}, 0, s,
Appearance -> "Labeled"}, {{ba, 4.73752, "ba"}, 0, 2 Pi,
Appearance -> "Labeled"}]
I have problems with the code above.
I want to explain my algorithm for drawing a gyroline to request some help about my mistake:
Let $\displaystyle C$ be the unit disc, and $\displaystyle P$ and $\displaystyle Q$ be two points inside $\displaystyle C$.
If the angle between $\displaystyle P$ and $\displaystyle Q$ is $\displaystyle \pi$, then the gyroline passing through the points $\displaystyle P$ and $\displaystyle Q$ is the straight segment joining these two points.
If not, then we draw the orthogonal circle $\displaystyle C^{\prime}$ to $\displaystyle C$, which passes through the given points $\displaystyle P$ and $\displaystyle Q$, and the gyroline is the shorter arc segment between $\displaystyle P$ and $\displaystyle Q$.
To draw the gyroline in this present case, I first calculate the center $\displaystyle M^{\prime}$ and the radius $\displaystyle R^{\prime}$ of the orthogonal circle $\displaystyle C^{\prime}$, and then obtain the points $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$ by transforming the points $\displaystyle P$ and $\displaystyle Q$ by the transform vector $\displaystyle M^{\prime}$, respectively, i.e., $\displaystyle P^{\prime}:=P-M^{\prime}$ and $\displaystyle Q^{\prime}:=Q-M^{\prime}$.
Let $\displaystyle \theta$ denote the angle between the vectors $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$.
Then I draw a circle arc $\displaystyle J$ of $\displaystyle \theta$ radian length centered at the origin $\displaystyle M^{\prime}$.
Now the problem is how much radians should I rotate the arc $\displaystyle J$ about the point $\displaystyle M^{\prime}$ to fix it between the points $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$.
My solution that I believed to be true was as follows:
Let $\displaystyle \varphi$ be the rotation angle.
If $\displaystyle \min\{\mathrm{Arg}(P^{\prime}),\mathrm{Arg}(Q^{\pr ime})\}+\theta=\max\{\mathrm{Arg}(P^{\prime}),\mat hrm{Arg}(Q^{\prime})\}$ (the transformed arc $\displaystyle J^{\prime}:=J-M^{\prime}$ does not intersect the segment combining the points $\displaystyle (0,0)$ and $\displaystyle (1,0)$), then $\displaystyle \varphi:=\min\{\mathrm{Arg}(P^{\prime}),\mathrm{Ar g}(Q^{\prime})\}$ radians, where $\displaystyle \mathrm{Arg}$ is the positive angle between the given vector and $\displaystyle (1,0)$ (the argument of the corresponding complex number).
Otherwise (when $\displaystyle J^{\prime}$ intersects the segment combining the points $\displaystyle (0,0)$ and $\displaystyle (1,0)$), $\displaystyle \varphi:=\max\{\mathrm{Arg}(P^{\prime}),\mathrm{Ar g}(Q^{\prime})$.
But the code gives error while drawing the latter case.

Thanks.
Okay I got the solution.
In the latter case above, I rotate the points $\displaystyle P^{\prime}$ and $\displaystyle Q^{\prime}$ by the angle $\displaystyle \pi$ around the origin $\displaystyle O$, then consider the first case by increasing its rotation angle by $\displaystyle \pi$.
The correct code is given below:

Correct code for the gyroline
Code:
(*returns the first component of the center of the ortogonal circle*)
\

orcice1[s_, a_, b_, c_, d_] := (-b c^2 + a^2 d + b^2 d - b d^2 -
b s^2 + d s^2)/(2 (a d - b c));
(*returns the second component of the center of the ortogonal circle*)
\

orcice2[s_, a_, b_, c_, d_] := (
a^2 c + b^2 c - a c^2 - a d^2 - a s^2 + c s^2)/(2 (b c - a d));
(*returns the radius component of the ortogonal circle*)
orcira[s_, a_, b_, c_, d_] :=
Sqrt[(orcice1[s, a, b, c, d])^2 + (orcice2[s, a, b, c, d])^2 -
s^2];
(*returns the argument of the number a+\[ImaginaryI]b between 0 and \
\[Pi]*)
ar02pi[a_, b_] :=
If[Arg[a + \[ImaginaryI] b] <= 0, Arg[a + \[ImaginaryI] b] + 2 Pi,
Arg[a + \[ImaginaryI] b]];
(*arc angle of the ortogonal circle combining (a,b) and (c,d) in the \
Poincaré ball with the radious s*)
aran[s_, a_, b_, c_, d_] :=
VectorAngle[{a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]}, {c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]}];
(*draws a gyroline passing through (a,b) and (c,d) in the Poincaré \
gyroline[s_, a_, b_, c_, d_] :=
If[a d - b c == 0, Line[{{a, b}, {c, d}}],
If[Min[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]] + aran[s, a, b, c, d] ==
Max[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d], d - orcice2[s, a, b, c, d]]],
Rotate[Circle[{ orcice1[s, a, b, c, d], orcice2[s, a, b, c, d]},
orcira[s, a, b, c, d], {0, aran[s, a, b, c, d]}],
Min[ar02pi[a - orcice1[s, a, b, c, d],
b - orcice2[s, a, b, c, d]],
ar02pi[c - orcice1[s, a, b, c, d],
d - orcice2[s, a, b, c, d]]], {orcice1[s, a, b, c, d],
orcice2[s, a, b, c, d]}],
Rotate[Circle[{ orcice1[s, a, b, c, d], orcice2[s, a, b, c, d]},
orcira[s, a, b, c, d], {0, aran[s, a, b, c, d]}],
Min[ar02pi[-a - orcice1[s, -a, -b, -c, -d], -b -
orcice2[s, -a, -b, -c, -d]],
ar02pi[-c - orcice1[s, -a, -b, -c, -d], -d -
orcice2[s, -a, -b, -c, -d]]] + \[Pi], {orcice1[s, a, b, c,
d], orcice2[s, a, b, c, d]}]]];
Code for the example which gives error in the previous codes
Code:
Manipulate[
Graphics[{{Blue, Circle[{0, 0}, 1, {0, 2 Pi}]},
gyroline[s, ar*Cos[aa], ar*Sin[aa], br*Cos[ba], br*Sin[ba]]}], {{s,
1, "s"}, 1, 5,
Appearance -> "Labeled"}, Delimiter, {{ar, 0.43, "ar"}, 0, s,
Appearance -> "Labeled"}, {{aa, 1.67133, "aa"}, 0, 2 Pi,
Appearance -> "Labeled"}, Delimiter, {{br, 0.366, "br"}, 0, s,
Appearance -> "Labeled"}, {{ba, 4.73752, "ba"}, 0, 2 Pi,
Appearance -> "Labeled"}]