Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/plot/hyperbolic_arc.py
8815 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
TESTS::
59
60
sage: from sage.plot.hyperbolic_arc import HyperbolicArc
61
sage: HyperbolicArc(0, 1/2+I*sqrt(3)/2, {})._repr_()
62
'Hyperbolic arc (0.000000000000000, 0.500000000000000 + 0.866025403784439*I)'
63
"""
64
65
return "Hyperbolic arc (%s, %s)" % (self.A, self.B)
66
67
def _hyperbolic_arc(self, z0, z3, first=False):
68
"""
69
Function to construct Bezier path as an approximation to
70
the hyperbolic arc between the complex numbers z0 and z3 in the
71
hyperbolic plane.
72
"""
73
if (z0-z3).real() == 0:
74
self.path.append([(z0.real(),z0.imag()), (z3.real(),z3.imag())])
75
return
76
z0, z3 = (CC(z0), CC(z3))
77
if z0.imag() == 0 and z3.imag() == 0:
78
p = (z0.real()+z3.real())/2
79
r = abs(z0-p)
80
zm = CC(p, r)
81
self._hyperbolic_arc(z0, zm, first)
82
self._hyperbolic_arc(zm, z3)
83
return
84
else:
85
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
86
r = abs(z0-p)
87
zm = ((z0+z3)/2-p)/abs((z0+z3)/2-p)*r+p
88
t = (8*zm-4*(z0+z3)).imag()/3/(z3-z0).real()
89
z1 = z0 + t*CC(z0.imag(), (p-z0.real()))
90
z2 = z3 - t*CC(z3.imag(), (p-z3.real()))
91
if first:
92
self.path.append([(z0.real(), z0.imag()),
93
(z1.real(), z1.imag()),
94
(z2.real(), z2.imag()),
95
(z3.real(), z3.imag())]);
96
first = False
97
else:
98
self.path.append([(z1.real(), z1.imag()),
99
(z2.real(), z2.imag()),
100
(z3.real(), z3.imag())]);
101
102
@rename_keyword(color='rgbcolor')
103
@options(alpha=1, fill=False, thickness=1, rgbcolor="blue", zorder=2, linestyle='solid')
104
def hyperbolic_arc(a, b, **options):
105
"""
106
Plot an arc from a to b in hyperbolic geometry in the complex upper
107
half plane.
108
109
INPUT:
110
111
- ``a, b`` - complex numbers in the upper half complex plane
112
connected bye the arc
113
114
OPTIONS:
115
116
- ``alpha`` - default: 1
117
118
- ``thickness`` - default: 1
119
120
- ``rgbcolor`` - default: 'blue'
121
122
- ``linestyle`` - (default: ``'solid'``) The style of the line, which is one
123
of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``,
124
``':'``, ``'-'``, ``'-.'``, respectively.
125
126
Examples:
127
128
Show a hyperbolic arc from 0 to 1::
129
130
sage: hyperbolic_arc(0, 1)
131
132
Show a hyperbolic arc from 1/2 to `i` with a red thick line::
133
134
sage: hyperbolic_arc(1/2, I, color='red', thickness=2)
135
136
Show a hyperbolic arc form `i` to `2 i` with dashed line::
137
138
sage: hyperbolic_arc(I, 2*I, linestyle='dashed')
139
sage: hyperbolic_arc(I, 2*I, linestyle='--')
140
"""
141
from sage.plot.all import Graphics
142
g = Graphics()
143
g._set_extra_kwds(g._extract_kwds_for_show(options))
144
g.add_primitive(HyperbolicArc(a, b, options))
145
g.set_aspect_ratio(1)
146
return g
147
148