Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/plot/hyperbolic_arc.py
4034 views
1
"""
2
Arcs in hyperbolic geometry
3
4
AUTHORS:
5
6
- Hartmut Monien (2011 - 08)
7
"""
8
#*****************************************************************************
9
# Copyright (C) 2011 Hartmut Monien <[email protected]>,
10
#
11
# Distributed under the terms of the GNU General Public License (GPL)
12
#
13
# This code is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# General Public License for more details.
17
#
18
# The full text of the GPL is available at:
19
#
20
# http://www.gnu.org/licenses/
21
#*****************************************************************************
22
from sage.plot.bezier_path import BezierPath
23
from sage.plot.colors import to_mpl_color
24
from sage.plot.misc import options, rename_keyword
25
from sage.rings.all import CC
26
27
class HyperbolicArc(BezierPath):
28
"""
29
Primitive class for hyberbolic arc type. See ``hyperbolic_arc?`` for
30
information about plotting a hyperbolic arc in the complex plane.
31
32
INPUT:
33
34
- ``a, b`` - coordinates of the hyperbolic arc in the complex plane
35
- ``options`` - dict of valid plot options to pass to constructor
36
37
EXAMPLES:
38
39
Note that constructions should use ``hyperbolic_arc``::
40
41
sage: from sage.plot.hyperbolic_arc import HyperbolicArc
42
43
sage: print HyperbolicArc(0, 1/2+I*sqrt(3)/2, {})
44
Hyperbolic arc (0.000000000000000, 0.500000000000000 + 0.866025403784439*I)
45
"""
46
47
def __init__(self, A, B, options):
48
A, B = (CC(A), CC(B))
49
self.path = []
50
self._hyperbolic_arc(A, B, True);
51
BezierPath.__init__(self, self.path, options)
52
self.A, self.B = (A, B)
53
54
def _repr_(self):
55
"""
56
String representation of HyperbolicArc.
57
"""
58
return "Hyperbolic arc (%s, %s)" % (self.A, self.B)
59
60
def _hyperbolic_arc(self, z0, z3, first=False):
61
"""
62
Function to construct Bezier path as an approximation to
63
the hyperbolic arc between the complex numbers z0 and z3 in the
64
hyperbolic plane.
65
"""
66
if (z0-z3).real() == 0:
67
self.path.append([(z0.real(),z0.imag()), (z3.real(),z3.imag())])
68
return
69
z0, z3 = (CC(z0), CC(z3))
70
if z0.imag() == 0 and z3.imag() == 0:
71
p = (z0.real()+z3.real())/2
72
r = abs(z0-p)
73
zm = CC(p, r)
74
self._hyperbolic_arc(z0, zm, first)
75
self._hyperbolic_arc(zm, z3)
76
return
77
else:
78
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
79
r = abs(z0-p)
80
zm = ((z0+z3)/2-p)/abs((z0+z3)/2-p)*r+p
81
t = (8*zm-4*(z0+z3)).imag()/3/(z3-z0).real()
82
z1 = z0 + t*CC(z0.imag(), (p-z0.real()))
83
z2 = z3 - t*CC(z3.imag(), (p-z3.real()))
84
if first:
85
self.path.append([(z0.real(), z0.imag()),
86
(z1.real(), z1.imag()),
87
(z2.real(), z2.imag()),
88
(z3.real(), z3.imag())]);
89
first = False
90
else:
91
self.path.append([(z1.real(), z1.imag()),
92
(z2.real(), z2.imag()),
93
(z3.real(), z3.imag())]);
94
95
@rename_keyword(color='rgbcolor')
96
@options(alpha=1, fill=False, thickness=1, rgbcolor="blue", zorder=2, linestyle='solid')
97
def hyperbolic_arc(a, b, **options):
98
"""
99
Plot an arc from a to b in hyperbolic geometry in the complex upper
100
half plane.
101
102
INPUT:
103
104
- ``a, b`` - complex numbers in the upper half complex plane
105
connected bye the arc
106
107
OPTIONS:
108
109
- ``alpha`` - default: 1
110
111
- ``thickness`` - default: 1
112
113
- ``rgbcolor`` - default: 'blue'
114
115
- ``linestyle`` - default: 'solid'
116
117
Examples:
118
119
Show a hyperbolic arc from 0 to 1::
120
121
sage: hyperbolic_arc(0, 1)
122
123
Show a hyperbolic arc from 1/2 to `i` with a red thick line::
124
125
sage: hyperbolic_arc(1/2, I, color='red', thickness=2)
126
127
Show a hyperbolic arc form `i` to `2 i` with dashed line::
128
129
sage: hyperbolic_arc(I, 2*I, linestyle='dashed')
130
"""
131
from sage.plot.all import Graphics
132
g = Graphics()
133
g._set_extra_kwds(g._extract_kwds_for_show(options))
134
g.add_primitive(HyperbolicArc(a, b, options))
135
g.set_aspect_ratio(1)
136
return g
137
138