Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

""" 

Regular polygons in the upper half model for hyperbolic plane 

 

AUTHORS: 

 

- Javier Honrubia (2016-01) 

""" 

 

#****************************************************************************** 

# Copyright (C) 2016 Javier Honrubia Gonzalez <jhonrubia6@alumno.uned.es> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

from __future__ import print_function 

 

from sage.plot.hyperbolic_polygon import HyperbolicPolygon, hyperbolic_polygon 

from sage.plot.all import Graphics 

from sage.rings.all import CC 

from sage.rings.integer import Integer 

from sage.plot.misc import options, rename_keyword 

from sage.symbolic.constants import pi, e 

from sage.functions.hyperbolic import arccosh 

from sage.functions.trig import sin, cos, cot 

from sage.misc.functional import is_odd 

from sage.matrix.constructor import matrix 

 

class HyperbolicRegularPolygon(HyperbolicPolygon): 

r""" 

Primitive class for regular hyberbolic polygon type. 

 

See ``hyperbolic_regular_polygon?`` for information about plotting 

a hyperbolic regular polygon in the upper complex halfplane. 

 

INPUT: 

 

- ``sides`` -- number of sides of the polygon 

 

- ``i_angle`` -- interior angle of the polygon 

 

- ``center``-- center point as a complex number of the polygon 

 

EXAMPLES: 

 

Note that constructions should use :func:`hyperbolic_regular_polygon`:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: print(HyperbolicRegularPolygon(5,pi/2,I, {})) 

Hyperbolic regular polygon (sides=5, i_angle=1/2*pi, center=1.00000000000000*I) 

 

The code verifies is there exists a compact hyperbolic regular polygon 

with the given data, checking 

 

.. MATH:: 

 

A(\mathcal{P}) = \pi(s-2) - s \cdot \alpha > 0, 

 

where `s` is ``sides`` and `\alpha` is ``i_angle`. This raises an error if 

the ``i_angle`` is less than the minimum to generate a compact polygon:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P = HyperbolicRegularPolygon(4, pi/2, I, {}) 

Traceback (most recent call last): 

... 

ValueError: there exists no hyperbolic regular compact polygon, 

for sides=4 the interior angle must be less than 1/2*pi 

 

It is an error to give a center outside the upper half plane in this model :: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P = HyperbolicRegularPolygon(4, pi/4, 1-I, {}) 

Traceback (most recent call last): 

... 

ValueError: center: 1.00000000000000 - 1.00000000000000*I is not 

a valid point in the upper half plane model of the hyperbolic plane 

 

TESTS:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P = HyperbolicRegularPolygon(4, -pi/4, I, {}) 

Traceback (most recent call last): 

... 

ValueError: interior angle -1/4*pi must be in (0, pi) interval 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P=HyperbolicRegularPolygon(16, 3*pi/2, I, {}) 

Traceback (most recent call last): 

... 

ValueError: interior angle 3/2*pi must be in (0, pi) interval 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P = HyperbolicRegularPolygon(2, pi/10, I, {}) 

Traceback (most recent call last): 

... 

ValueError: degenerated polygons (sides<=2) are not supported 

""" 

def __init__(self, sides, i_angle, center, options): 

""" 

Initialize HyperbolicRegularPolygon. 

 

EXAMPLES:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: print(HyperbolicRegularPolygon(5,pi/2,I, {})) 

Hyperbolic regular polygon (sides=5, i_angle=1/2*pi, center=1.00000000000000*I) 

""" 

self.center = CC(center) 

if self.center.imag() <= 0 : 

raise ValueError("center: %s is not a valid point in the upper half plane model of the hyperbolic plane"%(self.center)) 

if sides < 3 : 

raise ValueError("degenerated polygons (sides<=2) are not supported") 

if i_angle <=0 or i_angle >= pi: 

raise ValueError("interior angle %s must be in (0, pi) interval"%(i_angle)) 

if pi*(sides-2) - sides*i_angle <= 0 : 

raise ValueError("there exists no hyperbolic regular compact polygon, for sides=%s the interior angle must be less than %s"%(sides, pi * (sides-2) / sides)) 

self.sides = sides 

self.i_angle = i_angle 

beta = 2 * pi / self.sides # compute the rotation angle to be used ahead 

alpha = self.i_angle / Integer(2) 

I = CC(0, 1) 

# compute using cosine theorem the radius of the circumscribed circle 

# using the triangle formed by the radius and the three known angles 

r = arccosh(cot(alpha) * (1 + cos(beta)) / sin(beta)) 

 

# The first point will be always on the imaginary axis limited 

# to 8 digits for efficiency in the subsequent calculations. 

z_0 = [I*(e**r).n(digits=8)] 

 

# Compute the dilation isometry used to move the center 

# from I to the imaginary part of the given center. 

scale = self.center.imag() 

 

# Compute the parabolic isometry to move the center to the 

# real part of the given center. 

h_disp = self.center.real() 

 

d_z_k = [z_0[0]*scale + h_disp] #d_k has the points for the polygon in the given center 

z_k = z_0 #z_k has the Re(z)>0 vertices for the I centered polygon  

r_z_k = [] #r_z_k has the Re(z)<0 vertices 

if is_odd(self.sides): 

vert = (self.sides - 1) / 2 

else: 

vert = self.sides / 2 - 1 

for k in range(0, vert): 

# Compute with 8 digits to accelerate calculations 

new_z_k = self._i_rotation(z_k[-1], beta).n(digits=8) 

z_k = z_k + [new_z_k] 

d_z_k = d_z_k + [new_z_k * scale + h_disp] 

r_z_k=[-(new_z_k).conjugate() * scale + h_disp] + r_z_k 

if is_odd(self.sides): 

HyperbolicPolygon.__init__(self, d_z_k + r_z_k, options) 

else: 

z_opo = [I * (e**(-r)).n(digits=8) * scale + h_disp] 

HyperbolicPolygon.__init__(self, d_z_k + z_opo + r_z_k, options) 

 

def _repr_(self): 

""" 

String representation of HyperbolicRegularPolygon. 

 

TESTS:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: HyperbolicRegularPolygon(5,pi/2,I, {})._repr_() 

'Hyperbolic regular polygon (sides=5, i_angle=1/2*pi, center=1.00000000000000*I)' 

""" 

return ("Hyperbolic regular polygon (sides=%s, i_angle=%s, center=%s)" 

% (self.sides, self.i_angle, self.center)) 

 

def _i_rotation(self, z, alpha): 

r""" 

Return the resulting point after applying a hyperbolic 

rotation centered at `0 + i` and angle ``alpha`` to ``z``. 

 

INPUT: 

 

- ``z``-- point in the upper complex halfplane to which 

apply the isometry 

 

- ``alpha``-- angle of rotation (radians,counterwise) 

 

OUTPUT: 

 

- rotated point in the upper complex halfplane 

 

TESTS:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import HyperbolicRegularPolygon 

sage: P = HyperbolicRegularPolygon(4, pi/4, 1+I, {}) 

sage: P._i_rotation(2+I, pi/2) 

I - 2 

""" 

_a = alpha / 2 

_c = cos(_a) 

_s = sin(_a) 

G = matrix([[_c, _s], [-_s, _c]]) 

return (G[0][0] * z + G[0][1]) / (G[1][0] * z + G[1][1]) 

 

@rename_keyword(color='rgbcolor') 

@options(alpha=1, fill=False, thickness=1, rgbcolor="blue", zorder=2, 

linestyle='solid') 

def hyperbolic_regular_polygon(sides, i_angle, center=CC(0,1), **options): 

r""" 

Return a hyperbolic regular polygon in the upper half model of 

Hyperbolic plane given the number of sides, interior angle and 

possibly a center. 

 

Type ``?hyperbolic_regular_polygon`` to see all options. 

 

INPUT: 

 

- ``sides`` -- number of sides of the polygon 

 

- ``i_angle`` -- interior angle of the polygon 

 

- ``center`` -- (default: `i`) hyperbolic center point 

(complex number) of the polygon 

 

OPTIONS: 

 

- ``alpha`` -- default: 1 

 

- ``fill`` -- default: ``False`` 

 

- ``thickness`` -- default: 1 

 

- ``rgbcolor`` -- default: ``'blue'`` 

 

- ``linestyle`` -- (default: ``'solid'``) the style of the line, 

which can be one of the following: 

 

* ``'dashed'`` or ``'--'`` 

* ``'dotted'`` or ``':'`` 

* ``'solid'`` or ``'-'`` 

* ``'dashdot'`` or ``'-.'`` 

 

EXAMPLES: 

 

Show a hyperbolic regular polygon with 6 sides and square angles:: 

 

sage: g = hyperbolic_regular_polygon(6, pi/2) 

sage: g.plot() 

Graphics object consisting of 1 graphics primitive 

 

.. PLOT:: 

 

g = hyperbolic_regular_polygon(6, pi/2) 

sphinx_plot(g.plot()) 

 

With more options:: 

 

sage: g = hyperbolic_regular_polygon(6, pi/2, center=3+2*I, fill=True, color='red') 

sage: g.plot() 

Graphics object consisting of 1 graphics primitive 

 

.. PLOT:: 

 

g = hyperbolic_regular_polygon(6, pi/2, center=3+2*I, fill=True, color='red') 

sphinx_plot(g.plot()) 

 

The code verifies is there exists a hyperbolic regular polygon 

with the given data, checking 

 

.. MATH:: 

 

A(\mathcal{P}) = \pi(s-2) - s \cdot \alpha > 0, 

 

where `s` is ``sides`` and `\alpha` is ``i_angle`. This raises an error if 

the ``i_angle`` is less than the minimum to generate a compact polygon:: 

 

sage: hyperbolic_regular_polygon(4, pi/2) 

Traceback (most recent call last): 

... 

ValueError: there exists no hyperbolic regular compact polygon, 

for sides=4 the interior angle must be less than 1/2*pi 

 

It is an error to give a center outside the upper half plane in 

this model:: 

 

sage: from sage.plot.hyperbolic_regular_polygon import hyperbolic_regular_polygon 

sage: hyperbolic_regular_polygon(4, pi/4, 1-I) 

Traceback (most recent call last): 

... 

ValueError: center: 1.00000000000000 - 1.00000000000000*I is not 

a valid point in the upper half plane model of the hyperbolic plane 

""" 

g = Graphics() 

g._set_extra_kwds(g._extract_kwds_for_show(options)) 

g.add_primitive(HyperbolicRegularPolygon(sides, i_angle, center, options)) 

g.set_aspect_ratio(1) 

return g