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

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

# -*- coding: utf-8 -*- 

r""" 

Hyperbolic Geodesics 

 

This module implements the abstract base class for geodesics in 

hyperbolic space of arbitrary dimension. It also contains the 

implementations for specific models of hyperbolic geometry. 

 

AUTHORS: 

 

- Greg Laun (2013): initial version 

 

EXAMPLES: 

 

We can construct geodesics in the upper half plane model, abbreviated 

UHP for convenience:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2, 3) 

sage: g 

Geodesic in UHP from 2 to 3 

 

This geodesic can be plotted using :meth:`plot`, in this example we will show 

the axis. 

 

:: 

 

sage: g.plot(axes=True) 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(2.0, 3.0) 

sphinx_plot(g.plot(axes=True)) 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 3 + I) 

sage: g.length() 

arccosh(11/2) 

sage: g.plot(axes=True) 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

sphinx_plot(HyperbolicPlane().UHP().get_geodesic(I, 3 + I).plot(axes=True)) 

 

Geodesics of both types in UHP are supported:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 3*I) 

sage: g 

Geodesic in UHP from I to 3*I 

sage: g.plot() 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

sphinx_plot(HyperbolicPlane().UHP().get_geodesic(I, 3*I).plot()) 

 

Geodesics are oriented, which means that two geodesics with the same 

graph will only be equal if their starting and ending points are 

the same:: 

 

sage: g1 = HyperbolicPlane().UHP().get_geodesic(1,2) 

sage: g2 = HyperbolicPlane().UHP().get_geodesic(2,1) 

sage: g1 == g2 

False 

 

.. TODO:: 

 

Implement a parent for all geodesics of the hyperbolic plane? 

Or implement geodesics as a parent in the subobjects category? 

 

""" 

 

 

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

# Copyright (C) 2013 Greg Laun <glaun@math.umd.edu> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# 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 sage.structure.sage_object import SageObject 

from sage.symbolic.all import I 

from sage.misc.lazy_attribute import lazy_attribute 

from sage.rings.infinity import infinity 

from sage.rings.all import CC, RR 

from sage.plot.arc import arc 

from sage.plot.line import line 

from sage.symbolic.constants import pi 

from sage.modules.free_module_element import vector 

from sage.matrix.constructor import matrix 

from sage.functions.other import real, imag, sqrt 

from sage.functions.trig import arccos 

from sage.functions.log import exp 

from sage.functions.hyperbolic import sinh, cosh, arcsinh 

from sage.symbolic.ring import SR 

from sage.geometry.hyperbolic_space.hyperbolic_constants import EPSILON 

from sage.misc.superseded import deprecated_function_alias 

 

from sage.misc.lazy_import import lazy_import 

lazy_import('sage.geometry.hyperbolic_space.hyperbolic_isometry', 

'moebius_transform') 

 

 

class HyperbolicGeodesic(SageObject): 

r""" 

Abstract base class for oriented geodesics that are not necessarily 

complete. 

 

INPUT: 

 

- ``start`` -- a HyperbolicPoint or coordinates of a point in 

hyperbolic space representing the start of the geodesic 

 

- ``end`` -- a HyperbolicPoint or coordinates of a point in 

hyperbolic space representing the end of the geodesic 

 

EXAMPLES: 

 

We can construct a hyperbolic geodesic in any model:: 

 

sage: HyperbolicPlane().UHP().get_geodesic(1, 0) 

Geodesic in UHP from 1 to 0 

sage: HyperbolicPlane().PD().get_geodesic(1, 0) 

Geodesic in PD from 1 to 0 

sage: HyperbolicPlane().KM().get_geodesic((0,1/2), (1/2, 0)) 

Geodesic in KM from (0, 1/2) to (1/2, 0) 

sage: HyperbolicPlane().HM().get_geodesic((0,0,1), (0,1, sqrt(2))) 

Geodesic in HM from (0, 0, 1) to (0, 1, sqrt(2)) 

 

""" 

 

##################### 

# "Private" Methods # 

##################### 

 

def __init__(self, model, start, end, **graphics_options): 

r""" 

See :class:`HyperbolicGeodesic` for full documentation. 

 

EXAMPLES :: 

 

sage: HyperbolicPlane().UHP().get_geodesic(I, 2 + I) 

Geodesic in UHP from I to I + 2 

 

""" 

 

self._model = model 

self._start = start 

self._end = end 

self._graphics_options = graphics_options 

 

@lazy_attribute 

def _cached_geodesic(self): 

r""" 

The representation of the geodesic used for calculations. 

 

EXAMPLES:: 

 

sage: A = HyperbolicPlane().PD().get_geodesic(0, 1/2) 

sage: A._cached_geodesic 

Geodesic in UHP from I to 3/5*I + 4/5 

 

""" 

 

M = self._model.realization_of().a_realization() 

return self.to_model(M) 

 

@lazy_attribute 

def _complete(self): 

r""" 

Return whether the geodesic is complete. This is used for 

geodesics in non-bounded models. For these models, 

``self.complete()`` simply sets ``_complete`` to ``True``. 

 

EXAMPLES:: 

 

sage: HyperbolicPlane().UHP().get_geodesic(1, -12)._complete 

True 

sage: HyperbolicPlane().UHP().get_geodesic(I, 2 + I)._complete 

False 

sage: HM = HyperbolicPlane().HM() 

sage: g = HM.get_geodesic((0,0,1), (0,1, sqrt(2))) 

sage: g._complete 

False 

sage: g.complete()._complete 

True 

 

""" 

 

if self._model.is_bounded(): 

return (self._start.is_boundary() and self._end.is_boundary()) 

return False # All non-bounded geodesics start life incomplete. 

 

def _repr_(self): 

r""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: UHP.get_geodesic(3 + 4*I, I) 

Geodesic in UHP from 4*I + 3 to I 

 

sage: PD = HyperbolicPlane().PD() 

sage: PD.get_geodesic(1/2 + I/2, 0) 

Geodesic in PD from 1/2*I + 1/2 to 0 

 

sage: KM = HyperbolicPlane().KM() 

sage: KM.get_geodesic((1/2, 1/2), (0, 0)) 

Geodesic in KM from (1/2, 1/2) to (0, 0) 

 

sage: HM = HyperbolicPlane().HM() 

sage: HM.get_geodesic((0,0,1), (0, 1, sqrt(Integer(2)))) 

Geodesic in HM from (0, 0, 1) to (0, 1, sqrt(2)) 

 

""" 

 

msg = "Geodesic in {0} from {1} to {2}" 

return msg.format(self._model.short_name(), 

self._start.coordinates(), 

self._end.coordinates()) 

 

def __eq__(self, other): 

r""" 

Return ``True`` if ``self`` is equal to other as an oriented geodesic. 

 

EXAMPLES:: 

 

sage: g1 = HyperbolicPlane().UHP().get_geodesic(I, 2*I) 

sage: g2 = HyperbolicPlane().UHP().get_geodesic(2*I, I) 

sage: g1 == g2 

False 

sage: g1 == g1 

True 

""" 

if not isinstance(other, HyperbolicGeodesic): 

return False 

return (self._model is other._model and 

self._start == other._start and 

self._end == other._end) 

 

def __ne__(self, other): 

""" 

Test unequality of self and other. 

 

EXAMPLES:: 

 

sage: g1 = HyperbolicPlane().UHP().get_geodesic(I, 2*I) 

sage: g2 = HyperbolicPlane().UHP().get_geodesic(2*I, I) 

sage: g1 != g2 

True 

sage: g1 != g1 

False 

""" 

return not (self == other) 

 

####################### 

# Setters and Getters # 

####################### 

 

def start(self): 

r""" 

Return the starting point of the geodesic. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 3*I) 

sage: g.start() 

Point in UHP I 

 

""" 

return self._start 

 

def end(self): 

r""" 

Return the starting point of the geodesic. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 3*I) 

sage: g.end() 

Point in UHP 3*I 

 

""" 

 

return self._end 

 

def endpoints(self): 

r""" 

Return a list containing the start and endpoints. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 3*I) 

sage: g.endpoints() 

[Point in UHP I, Point in UHP 3*I] 

 

""" 

 

return [self._start, self._end] 

 

def model(self): 

r""" 

Return the model to which the :class:`HyperbolicGeodesic` belongs. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: UHP.get_geodesic(I, 2*I).model() 

Hyperbolic plane in the Upper Half Plane Model 

 

sage: PD = HyperbolicPlane().PD() 

sage: PD.get_geodesic(0, I/2).model() 

Hyperbolic plane in the Poincare Disk Model 

 

sage: KM = HyperbolicPlane().KM() 

sage: KM.get_geodesic((0, 0), (0, 1/2)).model() 

Hyperbolic plane in the Klein Disk Model 

 

sage: HM = HyperbolicPlane().HM() 

sage: HM.get_geodesic((0, 0, 1), (0, 1, sqrt(2))).model() 

Hyperbolic plane in the Hyperboloid Model 

""" 

return self._model 

 

def to_model(self, model): 

r""" 

Convert the current object to image in another model. 

 

INPUT: 

 

- ``model`` -- the image model 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: PD = HyperbolicPlane().PD() 

sage: UHP.get_geodesic(I, 2*I).to_model(PD) 

Geodesic in PD from 0 to 1/3*I 

sage: UHP.get_geodesic(I, 2*I).to_model('PD') 

Geodesic in PD from 0 to 1/3*I 

 

""" 

 

if isinstance(model, str): 

model = getattr(self._model.realization_of(), model)() 

if not model.is_bounded() and self.length() == infinity: 

raise NotImplementedError("cannot convert to an unbounded model") 

start = model(self._start) 

end = model(self._end) 

g = model.get_geodesic(start, end) 

return g 

 

def graphics_options(self): 

r""" 

Return the graphics options of ``self``. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 2*I, color="red") 

sage: g.graphics_options() 

{'color': 'red'} 

 

""" 

 

return self._graphics_options 

 

def update_graphics(self, update=False, **options): 

r""" 

Update the graphics options of ``self``. 

 

INPUT: 

 

- ``update`` -- if ``True``, the original option are updated 

rather than overwritten 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(I, 2*I) 

sage: g.graphics_options() 

{} 

 

sage: g.update_graphics(color = "red"); g.graphics_options() 

{'color': 'red'} 

 

sage: g.update_graphics(color = "blue"); g.graphics_options() 

{'color': 'blue'} 

 

sage: g.update_graphics(True, size = 20); g.graphics_options() 

{'color': 'blue', 'size': 20} 

 

""" 

 

if not update: 

self._graphics_options = {} 

self._graphics_options.update(**options) 

 

################### 

# Boolean Methods # 

################### 

 

def is_complete(self): 

r""" 

Return ``True`` if ``self`` is a complete geodesic (that is, both 

endpoints are on the ideal boundary) and ``False`` otherwise. 

 

If we represent complete geodesics using green color and incomplete 

using red colors we have the following graphic: 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(1.5*I, 2.5*I) 

h = UHP.get_geodesic(0, I) 

l = UHP.get_geodesic(2, 4) 

m = UHP.get_geodesic(3, infinity) 

G = g.plot(color='red') +\ 

text('is_complete()=False', 

(0, 2), 

horizontal_alignement='left') 

H = h.plot(color='red') +\ 

text('is_complete()=False', 

(0, 0.5), 

horizontal_alignement='left') 

L = l.plot(color='green') +\ 

text('is_complete()=True', 

(5, 1.5)) 

M = m.plot(color='green') + text('is complete()=True', 

(5, 4), 

horizontal_alignement='left') 

sphinx_plot(G+H+L+M) 

 

Notice, that there is no visual indication that the *vertical* geodesic 

is complete 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: UHP.get_geodesic(1.5*I, 2.5*I).is_complete() 

False 

sage: UHP.get_geodesic(0, I).is_complete() 

False 

sage: UHP.get_geodesic(3, infinity).is_complete() 

True 

sage: UHP.get_geodesic(2,5).is_complete() 

True 

 

""" 

 

return self._complete 

 

def is_asymptotically_parallel(self, other): 

r""" 

Return ``True`` if ``self`` and ``other`` are asymptotically 

parallel and ``False`` otherwise. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: h = HyperbolicPlane().UHP().get_geodesic(-2,4) 

sage: g.is_asymptotically_parallel(h) 

True 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2.0,5.0) 

h = HyperbolicPlane().UHP().get_geodesic(-2.0,4.0) 

sphinx_plot(g.plot(color='green')+h.plot(color='green')) 

 

Ultraparallel geodesics are not asymptotically parallel:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: h = HyperbolicPlane().UHP().get_geodesic(-1,4) 

sage: g.is_asymptotically_parallel(h) 

False 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2.0,5.0) 

h = HyperbolicPlane().UHP().get_geodesic(-1.0,4.0) 

sphinx_plot(g.plot(color='red')+h.plot(color='red')) 

 

 

No hyperbolic geodesic is asymptotically parallel to itself:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: g.is_asymptotically_parallel(g) 

False 

 

""" 

 

p1, p2 = self.complete().endpoints() 

q1, q2 = other.complete().endpoints() 

return ((self != other) and ((p1 in [q1, q2]) or (p2 in [q1, q2])) and 

self.model() is other.model()) 

 

def is_ultra_parallel(self, other): 

r""" 

Return ``True`` if ``self`` and ``other`` are ultra parallel 

and ``False`` otherwise. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperbolic_space.hyperbolic_geodesic \ 

....: import * 

sage: g = HyperbolicPlane().UHP().get_geodesic(0,1) 

sage: h = HyperbolicPlane().UHP().get_geodesic(-3,-1) 

sage: g.is_ultra_parallel(h) 

True 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(0.0,1.1) 

h = HyperbolicPlane().UHP().get_geodesic(-3.0,-1.0) 

sphinx_plot(g.plot(color='green')+h.plot(color='green')) 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: h = HyperbolicPlane().UHP().get_geodesic(2,6) 

sage: g.is_ultra_parallel(h) 

False 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

h = HyperbolicPlane().UHP().get_geodesic(2,6) 

sphinx_plot(g.plot(color='red')+h.plot(color='red')) 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: g.is_ultra_parallel(g) 

False 

 

""" 

 

A = self.reflection_involution() 

B = other.reflection_involution() 

return (A * B).classification() == 'hyperbolic' 

 

def is_parallel(self, other): 

r""" 

Return ``True`` if the two given hyperbolic geodesics are either 

ultra parallel or asymptotically parallel and``False`` otherwise. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in any model 

 

OUTPUT: 

 

``True`` if the given geodesics are either ultra parallel or 

asymptotically parallel, ``False`` if not. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: h = HyperbolicPlane().UHP().get_geodesic(5,12) 

sage: g.is_parallel(h) 

True 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

h = HyperbolicPlane().UHP().get_geodesic(5,12) 

sphinx_plot(g.plot(color='green')+h.plot(color='green')) 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: h = HyperbolicPlane().UHP().get_geodesic(-2,4) 

sage: g.is_parallel(h) 

True 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2.0,5.0) 

h = HyperbolicPlane().UHP().get_geodesic(-2.0,4.0) 

sphinx_plot(g.plot(color='green')+h.plot(color='green')) 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,2) 

sage: h = HyperbolicPlane().UHP().get_geodesic(-1,4) 

sage: g.is_parallel(h) 

False 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(-2,2) 

h = HyperbolicPlane().UHP().get_geodesic(-1,4) 

sphinx_plot(g.plot(color='red')+h.plot(color='red')) 

 

 

No hyperbolic geodesic is either ultra parallel or 

asymptotically parallel to itself:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(-2,5) 

sage: g.is_parallel(g) 

False 

 

""" 

 

A = self.reflection_involution() 

B = other.reflection_involution() 

return (A * B).classification() in ['parabolic', 'hyperbolic'] 

 

def ideal_endpoints(self): 

r""" 

Return the ideal endpoints in bounded models. Raise a 

``NotImplementedError`` in models that are not bounded. 

 

EXAMPLES:: 

 

sage: H = HyperbolicPlane() 

sage: UHP = H.UHP() 

sage: UHP.get_geodesic(1 + I, 1 + 3*I).ideal_endpoints() 

[Boundary point in UHP 1, Boundary point in UHP +Infinity] 

 

sage: PD = H.PD() 

sage: PD.get_geodesic(0, I/2).ideal_endpoints() 

[Boundary point in PD -I, Boundary point in PD I] 

 

sage: KM = H.KM() 

sage: KM.get_geodesic((0,0), (0, 1/2)).ideal_endpoints() 

[Boundary point in KM (0, -1), Boundary point in KM (0, 1)] 

 

sage: HM = H.HM() 

sage: HM.get_geodesic((0,0,1), (1, 0, sqrt(2))).ideal_endpoints() 

Traceback (most recent call last): 

... 

NotImplementedError: boundary points are not implemented in 

the HM model 

 

""" 

 

if not self._model.is_bounded(): 

errtxt = "boundary points are not implemented in the " + \ 

"{0} model".format(self._model.short_name()) 

raise NotImplementedError(errtxt) 

if self.is_complete(): 

return self.endpoints() 

return [self._model(k) 

for k in self._cached_geodesic.ideal_endpoints()] 

 

def complete(self): 

r""" 

Return the geodesic with ideal endpoints in bounded models. Raise a 

``NotImplementedError`` in models that are not bounded. 

In the following examples we represent complete geodesics by a dashed 

line. 

 

EXAMPLES:: 

 

sage: H = HyperbolicPlane() 

sage: UHP = H.UHP() 

sage: UHP.get_geodesic(1 + I, 1 + 3*I).complete() 

Geodesic in UHP from 1 to +Infinity 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(1 + I, 1 + 3*I) 

h = g.complete() 

sphinx_plot(g.plot()+h.plot(linestyle='dashed')) 

 

:: 

 

sage: PD = H.PD() 

sage: PD.get_geodesic(0, I/2).complete() 

Geodesic in PD from -I to I 

sage: PD.get_geodesic(0.25*(-1-I),0.25*(1-I)).complete() 

Geodesic in PD from -0.895806416477617 - 0.444444444444444*I to 0.895806416477617 - 0.444444444444444*I 

 

.. PLOT:: 

 

PD = HyperbolicPlane().PD() 

g = PD.get_geodesic(0, I/2) 

h = g. complete() 

m = PD.get_geodesic(0.25*(-1-I),0.25*(1-I)) 

l = m.complete() 

sphinx_plot(g.plot()+h.plot(linestyle='dashed') + 

m.plot()+l.plot(linestyle='dashed')) 

 

:: 

 

sage: KM = H.KM() 

sage: KM.get_geodesic((0,0), (0, 1/2)).complete() 

Geodesic in KM from (0, -1) to (0, 1) 

 

.. PLOT:: 

 

g = HyperbolicPlane().KM().get_geodesic((0.0,0.0), (0.0, 0.5)) 

h = g.complete() 

sphinx_plot(g.plot()+h.plot(linestyle='dashed')) 

 

:: 

 

sage: HM = H.HM() 

sage: HM.get_geodesic((0,0,1), (1, 0, sqrt(2))).complete() 

Geodesic in HM from (0, 0, 1) to (1, 0, sqrt(2)) 

 

.. PLOT:: 

 

g = HyperbolicPlane().HM().get_geodesic((0,0,1), (1, 0, sqrt(2))) 

h = g.complete() 

sphinx_plot(g.plot(color='black')+h.plot(linestyle='dashed',color='black')) 

 

:: 

 

sage: g = HM.get_geodesic((0,0,1), (1, 0, sqrt(2))).complete() 

sage: g.is_complete() 

True 

 

TESTS: 

 

Check that floating points remain floating points through this method:: 

 

sage: H = HyperbolicPlane() 

sage: g = H.UHP().get_geodesic(CC(0,1), CC(2,2)) 

sage: gc = g.complete() 

sage: parent(gc.start().coordinates()) 

Real Field with 53 bits of precision 

 

""" 

 

if self._model.is_bounded(): 

return self._model.get_geodesic(*self.ideal_endpoints()) 

 

from copy import copy 

g = copy(self) 

g._complete = True 

return g 

 

def reflection_involution(self): 

r""" 

Return the involution fixing ``self``. 

 

EXAMPLES:: 

 

sage: H = HyperbolicPlane() 

sage: gU = H.UHP().get_geodesic(2,4) 

sage: RU = gU.reflection_involution(); RU 

Isometry in UHP 

[ 3 -8] 

[ 1 -3] 

 

sage: RU*gU == gU 

True 

 

sage: gP = H.PD().get_geodesic(0, I) 

sage: RP = gP.reflection_involution(); RP 

Isometry in PD 

[ 1 0] 

[ 0 -1] 

 

sage: RP*gP == gP 

True 

 

sage: gK = H.KM().get_geodesic((0,0), (0,1)) 

sage: RK = gK.reflection_involution(); RK 

Isometry in KM 

[-1 0 0] 

[ 0 1 0] 

[ 0 0 1] 

 

sage: RK*gK == gK 

True 

 

sage: HM = H.HM() 

sage: g = HM.get_geodesic((0,0,1), (1,0, n(sqrt(2)))) 

sage: A = g.reflection_involution() 

sage: B = diagonal_matrix([1, -1, 1]) 

sage: bool((B - A.matrix()).norm() < 10**-9) 

True 

 

The above tests go through the Upper Half Plane. It remains to 

test that the matrices in the models do what we intend. :: 

 

sage: from sage.geometry.hyperbolic_space.hyperbolic_isometry \ 

....: import moebius_transform 

sage: R = H.PD().get_geodesic(-1,1).reflection_involution() 

sage: bool(moebius_transform(R.matrix(), 0) == 0) 

True 

 

""" 

 

ri = self._cached_geodesic.reflection_involution() 

return ri.to_model(self._model) 

 

def common_perpendicula(self, other): 

r""" 

Return the unique hyperbolic geodesic perpendicular to two given 

geodesics, if such a geodesic exists. If none exists, raise a 

``ValueError``. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in the same model as ``self`` 

 

OUTPUT: 

 

- a hyperbolic geodesic 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2,3) 

sage: h = HyperbolicPlane().UHP().get_geodesic(4,5) 

sage: g.common_perpendicular(h) 

Geodesic in UHP from 1/2*sqrt(3) + 7/2 to -1/2*sqrt(3) + 7/2 

 

.. PLOT:: 

 

g = HyperbolicPlane().UHP().get_geodesic(2.0, 3.0) 

h = HyperbolicPlane().UHP().get_geodesic(4.0, 5.0) 

l = g.common_perpendicular(h) 

P = g.plot(color='blue') +\ 

h.plot(color='blue') +\ 

l.plot(color='orange') 

sphinx_plot(P) 

 

It is an error to ask for the common perpendicular of two 

intersecting geodesics:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2,4) 

sage: h = HyperbolicPlane().UHP().get_geodesic(3, infinity) 

sage: g.common_perpendicular(h) 

Traceback (most recent call last): 

... 

ValueError: geodesics intersect; no common perpendicular exists 

 

""" 

 

if not self.is_parallel(other): 

raise ValueError('geodesics intersect; ' + 

'no common perpendicular exists') 

cp = self._cached_geodesic.common_perpendicular(other) 

return cp.to_model(self._model) 

 

def intersection(self, other): 

r""" 

Return the point of intersection of two geodesics (if such a 

point exists). 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in the same model as ``self`` 

 

OUTPUT: 

 

- a hyperbolic point or geodesic 

 

EXAMPLES:: 

 

sage: PD = HyperbolicPlane().PD() 

 

""" 

 

if self == other: 

return self 

elif self.is_parallel(other): 

raise ValueError("geodesics don't intersect") 

inters = self._cached_geodesic.intersection(other) 

if len(inters) == 2: 

return self 

elif len(inters) == 1: 

return [self._model(inters[0])] 

return [] 

 

def perpendicular_bisector(self): 

r""" 

Return the perpendicular bisector of ``self`` if ``self`` has 

finite length. Here distance is hyperbolic distance. 

 

EXAMPLES:: 

 

sage: PD = HyperbolicPlane().PD() 

sage: g = PD.get_geodesic(-0.3+0.4*I,+0.7-0.1*I) 

sage: h = g.perpendicular_bisector() 

sage: P = g.plot(color='blue')+h.plot(color='orange');P 

Graphics object consisting of 4 graphics primitives 

 

.. PLOT:: 

 

g = HyperbolicPlane().PD().get_geodesic(-0.3+0.4*I,+0.7-0.1*I) 

h = g.perpendicular_bisector() 

sphinx_plot(g.plot(color='blue')+h.plot(color='orange')) 

 

Complete geodesics cannot be bisected:: 

 

sage: g = HyperbolicPlane().PD().get_geodesic(0, 1) 

sage: g.perpendicular_bisector() 

Traceback (most recent call last): 

... 

ValueError: the length must be finite 

 

TESTS:: 

 

sage: g = HyperbolicPlane().PD().random_geodesic() 

sage: h = g.perpendicular_bisector() 

sage: bool(h.intersection(g)[0].coordinates() - g.midpoint().coordinates() < 10**-9) 

True 

 

""" 

 

P = self._cached_geodesic.perpendicular_bisector() 

return P.to_model(self._model) 

 

def midpoint(self): 

r""" 

Return the (hyperbolic) midpoint of a hyperbolic line segment. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().random_geodesic() 

sage: m = g.midpoint() 

sage: end1, end2 = g.endpoints() 

sage: bool(abs(m.dist(end1) - m.dist(end2)) < 10**-9) 

True 

 

Complete geodesics have no midpoint:: 

 

sage: HyperbolicPlane().UHP().get_geodesic(0,2).midpoint() 

Traceback (most recent call last): 

... 

ValueError: the length must be finite 

 

""" 

 

UHP = self._model.realization_of().a_realization() 

P = self.to_model(UHP).midpoint() 

return self._model(P) 

 

def dist(self, other): 

r""" 

Return the hyperbolic distance from a given hyperbolic geodesic 

to another geodesic or point. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic or hyperbolic point in 

the same model 

 

OUTPUT: 

 

- the hyperbolic distance 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2, 4.0) 

sage: h = HyperbolicPlane().UHP().get_geodesic(5, 7.0) 

sage: bool(abs(g.dist(h).n() - 1.92484730023841) < 10**-9) 

True 

 

If the second object is a geodesic ultraparallel to the first, 

or if it is a point on the boundary that is not one of the 

first object's endpoints, then return +infinity 

 

:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2, 2+I) 

sage: p = HyperbolicPlane().UHP().get_point(5) 

sage: g.dist(p) 

+Infinity 

 

TESTS: 

 

Check that floating points remain floating points in :meth:`dist` :: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(CC(0,1), CC(2,2)) 

sage: UHP.dist(g.start(), g.end()) 

1.45057451382258 

sage: parent(_) 

Real Field with 53 bits of precision 

 

""" 

 

return self._model.dist(self, other) 

 

def angle(self, other): 

r""" 

Return the angle between any two given geodesics if they 

intersect. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in the same model as ``self`` 

 

OUTPUT: 

 

- the angle in radians between the two given geodesics 

 

EXAMPLES:: 

 

sage: PD = HyperbolicPlane().PD() 

sage: g = PD.get_geodesic(3/5*I + 4/5, 15/17*I + 8/17) 

sage: h = PD.get_geodesic(4/5*I + 3/5, I) 

sage: g.angle(h) 

1/2*pi 

 

.. PLOT:: 

 

PD = HyperbolicPlane().PD() 

g = PD.get_geodesic(3.0/5.0*I + 4.0/5.0, 15.0/17.0*I + 8.0/17.0) 

h = PD.get_geodesic(4.0/5.0*I + 3.0/5.0, I) 

sphinx_plot(g.plot()+h.plot(color='orange')) 

 

""" 

 

if self.is_parallel(other): 

raise ValueError("geodesics do not intersect") 

return self._cached_geodesic.angle(other) 

 

def length(self): 

r""" 

Return the Hyperbolic length of the hyperbolic line segment. 

 

EXAMPLES:: 

 

sage: g = HyperbolicPlane().UHP().get_geodesic(2 + I, 3 + I/2) 

sage: g.length() 

arccosh(9/4) 

 

""" 

 

return self._model._dist_points(self._start.coordinates(), 

self._end.coordinates()) 

 

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

# UHP geodesics 

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

 

 

class HyperbolicGeodesicUHP(HyperbolicGeodesic): 

r""" 

Create a geodesic in the upper half plane model. 

 

The geodesics in this model are represented by circular arcs perpendicular 

to the real axis (half-circles whose origin is on the real axis) and 

straight vertical lines ending on the real axis. 

 

INPUT: 

 

- ``start`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the start of the geodesic 

 

- ``end`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the end of the geodesic 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(UHP.get_point(I), UHP.get_point(2 + I)) 

sage: g = UHP.get_geodesic(I, 2 + I) 

sage: h = UHP.get_geodesic(-1, -1+2*I) 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(I, 2 + I) 

h = UHP.get_geodesic(-1, -1+2*I) 

sphinx_plot(g.plot()+h.plot()) 

 

""" 

 

def reflection_involution(self): 

r""" 

Return the isometry of the involution fixing the geodesic ``self``. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g1 = UHP.get_geodesic(0, 1) 

sage: g1.reflection_involution() 

Isometry in UHP 

[ 1 0] 

[ 2 -1] 

sage: UHP.get_geodesic(I, 2*I).reflection_involution() 

Isometry in UHP 

[ 1 0] 

[ 0 -1] 

 

""" 

 

x, y = [real(k.coordinates()) for k in self.ideal_endpoints()] 

if x == infinity: 

M = matrix([[1, -2*y], [0, -1]]) 

elif y == infinity: 

M = matrix([[1, -2*x], [0, -1]]) 

else: 

M = matrix([[(x+y)/(y-x), -2*x*y/(y-x)], [2/(y-x), -(x+y)/(y-x)]]) 

return self._model.get_isometry(M) 

 

def plot(self, boundary=True, **options): 

r""" 

Plot ``self``. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: UHP.get_geodesic(0, 1).plot() 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(0.0, 1.0).plot() 

sphinx_plot(g) 

 

:: 

 

sage: UHP.get_geodesic(I, 3+4*I).plot(linestyle="dashed", color="brown") 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(I, 3+4*I).plot(linestyle="dashed", color="brown") 

sphinx_plot(g) 

 

:: 

 

sage: UHP.get_geodesic(1, infinity).plot(color='orange') 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(1, infinity).plot(color='orange') 

sphinx_plot(g) 

 

""" 

 

opts = {'axes': False, 'aspect_ratio': 1} 

opts.update(self.graphics_options()) 

opts.update(options) 

end_1, end_2 = [CC(k.coordinates()) for k in self.endpoints()] 

bd_1, bd_2 = [CC(k.coordinates()) for k in self.ideal_endpoints()] 

if (abs(real(end_1) - real(end_2)) < EPSILON) \ 

or CC(infinity) in [end_1, end_2]: # on same vertical line 

# If one of the endpoints is infinity, we replace it with a 

# large finite point 

if end_1 == CC(infinity): 

end_1 = (real(end_2), (imag(end_2) + 10)) 

end_2 = (real(end_2), imag(end_2)) 

elif end_2 == CC(infinity): 

end_2 = (real(end_1), (imag(end_1) + 10)) 

end_1 = (real(end_1), imag(end_1)) 

pic = line((end_1, end_2), **opts) 

if boundary: 

cent = min(bd_1, bd_2) 

bd_dict = {'bd_min': cent - 3, 'bd_max': cent + 3} 

bd_pic = self._model.get_background_graphic(**bd_dict) 

pic = bd_pic + pic 

return pic 

else: 

center = (bd_1 + bd_2) / 2 # Circle center 

radius = abs(bd_1 - bd_2) / 2 

theta1 = CC(end_1 - center).arg() 

theta2 = CC(end_2 - center).arg() 

if abs(theta1 - theta2) < EPSILON: 

theta2 += pi 

pic = arc((real(center), imag(center)), radius, 

sector=(theta1, theta2), **opts) 

if boundary: 

# We want to draw a segment of the real line. The 

# computations below compute the projection of the 

# geodesic to the real line, and then draw a little 

# to the left and right of the projection. 

shadow_1, shadow_2 = [real(k) for k in [end_1, end_2]] 

midpoint = (shadow_1 + shadow_2)/2 

length = abs(shadow_1 - shadow_2) 

bd_dict = {'bd_min': midpoint - length, 'bd_max': midpoint + 

length} 

bd_pic = self._model.get_background_graphic(**bd_dict) 

pic = bd_pic + pic 

return pic 

 

show = deprecated_function_alias(20530, plot) 

 

def ideal_endpoints(self): 

r""" 

Determine the ideal (boundary) endpoints of the complete 

hyperbolic geodesic corresponding to ``self``. 

 

OUTPUT: 

 

- a list of 2 boundary points 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: UHP.get_geodesic(I, 2*I).ideal_endpoints() 

[Boundary point in UHP 0, 

Boundary point in UHP +Infinity] 

sage: UHP.get_geodesic(1 + I, 2 + 4*I).ideal_endpoints() 

[Boundary point in UHP -sqrt(65) + 9, 

Boundary point in UHP sqrt(65) + 9] 

 

""" 

 

start = self._start.coordinates() 

end = self._end.coordinates() 

[x1, x2] = [real(k) for k in [start, end]] 

[y1, y2] = [imag(k) for k in [start, end]] 

M = self._model 

# infinity is the first endpoint, so the other ideal endpoint 

# is just the real part of the second coordinate 

if start == infinity: 

return [M.get_point(start), M.get_point(x2)] 

# Same idea as above 

if end == infinity: 

return [M.get_point(x1), M.get_point(end)] 

# We could also have a vertical line with two interior points 

if x1 == x2: 

return [M.get_point(x1), M.get_point(infinity)] 

# Otherwise, we have a semicircular arc in the UHP 

c = ((x1+x2)*(x2-x1) + (y1+y2)*(y2-y1)) / (2*(x2-x1)) 

r = sqrt((c - x1)**2 + y1**2) 

return [M.get_point(c - r), M.get_point(c + r)] 

 

def common_perpendicular(self, other): 

r""" 

Return the unique hyperbolic geodesic perpendicular to ``self`` 

and ``other``, if such a geodesic exists; otherwise raise a 

``ValueError``. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in current model 

 

OUTPUT: 

 

- a hyperbolic geodesic 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(2, 3) 

sage: h = UHP.get_geodesic(4, 5) 

sage: g.common_perpendicular(h) 

Geodesic in UHP from 1/2*sqrt(3) + 7/2 to -1/2*sqrt(3) + 7/2 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(2.0, 3.0) 

h = UHP.get_geodesic(4.0, 5.0) 

p = g.common_perpendicular(h) 

sphinx_plot(g.plot(color='blue')+h.plot(color='blue')+p.plot(color='orange')) 

 

It is an error to ask for the common perpendicular of two 

intersecting geodesics:: 

 

sage: g = UHP.get_geodesic(2, 4) 

sage: h = UHP.get_geodesic(3, infinity) 

sage: g.common_perpendicular(h) 

Traceback (most recent call last): 

... 

ValueError: geodesics intersect; no common perpendicular exists 

 

""" 

 

# Make sure both are in the same model 

if other._model is not self._model: 

other = other.to_model(self._model) 

 

A = self.reflection_involution() 

B = other.reflection_involution() 

C = A * B 

if C.classification() != 'hyperbolic': 

raise ValueError("geodesics intersect; " + 

"no common perpendicular exists") 

return C.fixed_point_set() 

 

def intersection(self, other): 

r""" 

Return the point of intersection of ``self`` and ``other`` 

(if such a point exists). 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in the current model 

 

OUTPUT: 

 

- a list of hyperbolic points or a hyperbolic geodesic 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(3, 5) 

sage: h = UHP.get_geodesic(4, 7) 

sage: g.intersection(h) 

[Point in UHP 2/3*sqrt(-2) + 13/3] 

 

If the given geodesics do not intersect, the function returns an 

empty list:: 

 

sage: g = UHP.get_geodesic(4, 5) 

sage: h = UHP.get_geodesic(5, 7) 

sage: g.intersection(h) 

[] 

 

If the given geodesics are identical, return that 

geodesic:: 

 

sage: g = UHP.get_geodesic(4 + I, 18*I) 

sage: h = UHP.get_geodesic(4 + I, 18*I) 

sage: g.intersection(h) 

[Boundary point in UHP -1/8*sqrt(114985) - 307/8, 

Boundary point in UHP 1/8*sqrt(114985) - 307/8] 

 

""" 

 

start_1, end_1 = sorted(self.ideal_endpoints(), key=str) 

start_2, end_2 = sorted(other.ideal_endpoints(), key=str) 

if start_1 == start_2 and end_1 == end_2: # Unoriented geods are same 

return [start_1, end_1] 

if start_1 == start_2: 

return start_1 

elif end_1 == end_2: 

return end_1 

A = self.reflection_involution() 

B = other.reflection_involution() 

C = A * B 

if C.classification() in ['hyperbolic', 'parabolic']: 

return [] 

return C.fixed_point_set() 

 

def perpendicular_bisector(self): # UHP 

r""" 

Return the perpendicular bisector of the hyperbolic geodesic ``self`` 

if that geodesic has finite length. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.random_geodesic() 

sage: h = g.perpendicular_bisector() 

sage: c = lambda x: x.coordinates() 

sage: bool(c(g.intersection(h)[0]) - c(g.midpoint()) < 10**-9) 

True 

 

:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(1+I,2+0.5*I) 

sage: h = g.perpendicular_bisector() 

sage: show(g.plot(color='blue')+h.plot(color='orange')) 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(1+I,2+0.5*I) 

h = g.perpendicular_bisector() 

sphinx_plot(g.plot(color='blue')+h.plot(color='orange')) 

 

Infinite geodesics cannot be bisected:: 

 

sage: UHP.get_geodesic(0, 1).perpendicular_bisector() 

Traceback (most recent call last): 

... 

ValueError: the length must be finite 

 

""" 

 

if self.length() == infinity: 

raise ValueError("the length must be finite") 

start = self._start.coordinates() 

d = self._model._dist_points(start, self._end.coordinates()) / 2 

S = self.complete()._to_std_geod(start) 

T1 = matrix([[exp(d/2), 0], [0, exp(-d/2)]]) 

s2 = sqrt(2) * 0.5 

T2 = matrix([[s2, -s2], [s2, s2]]) 

isom_mtrx = S.inverse() * (T1 * T2) * S 

# We need to clean this matrix up. 

if (isom_mtrx - isom_mtrx.conjugate()).norm() < 5 * EPSILON: 

# Imaginary part is small. 

isom_mtrx = (isom_mtrx + isom_mtrx.conjugate()) / 2 

# Set it to its real part. 

H = self._model.get_isometry(isom_mtrx) 

return self._model.get_geodesic(H(self._start), H(self._end)) 

 

def midpoint(self): # UHP 

r""" 

Return the (hyperbolic) midpoint of ``self`` if it exists. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.random_geodesic() 

sage: m = g.midpoint() 

sage: d1 = UHP.dist(m, g.start()) 

sage: d2 = UHP.dist(m, g.end()) 

sage: bool(abs(d1 - d2) < 10**-9) 

True 

 

Infinite geodesics have no midpoint:: 

 

sage: UHP.get_geodesic(0, 2).midpoint() 

Traceback (most recent call last): 

... 

ValueError: the length must be finite 

 

TESTS: 

 

This checks :trac:`20330` so that geodesics defined by symbolic 

expressions do not generate runtime errors. :: 

 

sage: g=HyperbolicPlane().UHP().get_geodesic(-1+I,1+I) 

sage: g.midpoint() 

Point in UHP 1/2*(sqrt(2)*e^(1/2*arccosh(3)) - sqrt(2) + (I - 1)*e^(1/2*arccosh(3)) + I - 1)/((1/4*I - 1/4)*sqrt(2)*e^(1/2*arccosh(3)) - (1/4*I - 1/4)*sqrt(2) + 1/2*e^(1/2*arccosh(3)) + 1/2) 

 

Check that floating points remain floating points 

in :meth:`midpoint` :: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(CC(0,1), CC(2,2)) 

sage: g.midpoint() 

Point in UHP 0.666666666666667 + 1.69967317119760*I 

sage: parent(g.midpoint().coordinates()) 

Complex Field with 53 bits of precision 

 

""" 

 

from sage.matrix.matrix_symbolic_dense import Matrix_symbolic_dense 

if self.length() == infinity: 

raise ValueError("the length must be finite") 

 

start = self._start.coordinates() 

end = self._end.coordinates() 

d = self._model._dist_points(start, end) / 2 

S = self.complete()._to_std_geod(start) 

 

# If the matrix is symbolic then needs to be simplified in order to 

# make the calculations easier for the symbolic calculus module. 

if isinstance(S, Matrix_symbolic_dense): 

S = S.simplify_full().simplify_full() 

S_1 = S.inverse() 

T = matrix([[exp(d), 0], [0, 1]]) 

M = S_1 * T * S 

if ((real(start - end) < EPSILON) or 

(abs(real(start - end)) < EPSILON and 

imag(start - end) < EPSILON)): 

end_p = start 

else: 

end_p = end 

P_3 = moebius_transform(M, end_p) 

return self._model.get_point(P_3) 

 

def angle(self, other): # UHP 

r""" 

Return the angle between any two given completed geodesics if 

they intersect. 

 

INPUT: 

 

- ``other`` -- a hyperbolic geodesic in the UHP model 

 

OUTPUT: 

 

- the angle in radians between the two given geodesics 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.get_geodesic(2, 4) 

sage: h = UHP.get_geodesic(3, 3 + I) 

sage: g.angle(h) 

1/2*pi 

sage: numerical_approx(g.angle(h)) 

1.57079632679490 

 

.. PLOT:: 

 

UHP = HyperbolicPlane().UHP() 

g = UHP.get_geodesic(2, 4) 

h = UHP.get_geodesic(3, 3 + I) 

sphinx_plot(g.plot()+h.plot()) 

 

If the geodesics are identical, return angle 0:: 

 

sage: g.angle(g) 

0 

 

It is an error to ask for the angle of two geodesics that do not 

intersect:: 

 

sage: g = UHP.get_geodesic(2, 4) 

sage: h = UHP.get_geodesic(5, 7) 

sage: g.angle(h) 

Traceback (most recent call last): 

... 

ValueError: geodesics do not intersect 

 

""" 

 

if self.is_parallel(other): 

raise ValueError("geodesics do not intersect") 

# Make sure the segments are complete or intersect 

if (not(self.is_complete() and other.is_complete()) and 

not self.intersection(other)): 

print("Warning: Geodesic segments do not intersect. " 

"The angle between them is not defined.\n" 

"Returning the angle between their completions.") 

 

# Make sure both are in the same model 

if other._model is not self._model: 

other = other.to_model(self._model) 

 

(p1, p2) = sorted([k.coordinates() 

for k in self.ideal_endpoints()], key=str) 

(q1, q2) = sorted([k.coordinates() 

for k in other.ideal_endpoints()], key=str) 

# if the geodesics are equal, the angle between them is 0 

if (abs(p1 - q1) < EPSILON and 

abs(p2 - q2) < EPSILON): 

return 0 

elif p2 != infinity: # geodesic not a straight line 

# So we send it to the geodesic with endpoints [0, oo] 

T = HyperbolicGeodesicUHP._crossratio_matrix(p1, (p1 + p2) / 2, p2) 

else: 

# geodesic is a straight line, so we send it to the geodesic 

# with endpoints [0,oo] 

T = HyperbolicGeodesicUHP._crossratio_matrix(p1, p1 + 1, p2) 

# b1 and b2 are the endpoints of the image of other 

b1, b2 = [moebius_transform(T, k) for k in [q1, q2]] 

# If other is now a straight line... 

if (b1 == infinity or b2 == infinity): 

# then since they intersect, they are equal 

return 0 

return real(arccos((b1 + b2) / abs(b2 - b1))) 

 

################## 

# Helper methods # 

################## 

 

@staticmethod 

def _get_B(a): 

r""" 

Helper function to get an appropriate matrix transforming 

(0,1,inf) -> (0,I,inf) based on the type of a 

 

INPUT: 

 

- ``a`` -- an element to identify the class of the resulting matrix. 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: g = UHP.random_geodesic() 

sage: B = g._get_B(CDF.an_element()); B 

[ 1.0 0.0] 

[ 0.0 -1.0*I] 

sage: type(B) 

<type 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'> 

 

:: 

 

sage: B = g._get_B(SR(1)); B 

[ 1 0] 

[ 0 -I] 

sage: type(B) 

<type 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'> 

 

:: 

 

sage: B = g._get_B(complex(1)); B 

[ 1.0 0.0] 

[ 0.0 -1.0*I] 

sage: type(B) 

<type 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'> 

 

:: 

 

sage: B = g._get_B(QQbar(1+I)); B 

[ 1 0] 

[ 0 -I] 

sage: type(B[1,1]) 

<class 'sage.rings.qqbar.AlgebraicNumber'> 

sage: type(B) 

<type 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'> 

 

""" 

from sage.structure.element import Element 

from sage.symbolic.expression import Expression 

from sage.rings.complex_double import CDF 

 

if isinstance(a, (int, float, complex)): # Python number 

a = CDF(a) 

 

if isinstance(a, Expression): # symbolic 

P = SR 

zero = SR.zero() 

one = SR.one() 

I = SR("I") 

elif isinstance(a, Element): # Sage number 

P = a.parent() 

zero = P.zero() 

one = P.one() 

I = P.gen() 

if I.is_one() or (I*I).is_one() or not (-I*I).is_one(): 

raise ValueError("invalid number") 

else: 

raise ValueError("not a complex number") 

 

return matrix(P, 2, [one, zero, zero, -I]) 

 

def _to_std_geod(self, p): 

r""" 

Given the coordinates of a geodesic in hyperbolic space, return the 

hyperbolic isometry that sends that geodesic to the geodesic 

through 0 and infinity that also sends the point ``p`` to `i`. 

 

INPUT: 

 

- ``p`` -- the coordinates of the 

 

EXAMPLES:: 

 

sage: UHP = HyperbolicPlane().UHP() 

sage: (p1, p2) = [UHP.random_point() for k in range(2)] 

sage: g = UHP.get_geodesic(p1, p2) 

sage: m = g.midpoint() 

sage: A = g._to_std_geod(m.coordinates()) # Send midpoint to I. 

sage: A = UHP.get_isometry(A) 

sage: [s, e]= g.complete().endpoints() 

sage: bool(abs(A(s).coordinates()) < 10**-9) 

True 

sage: bool(abs(A(m).coordinates() - I) < 10**-9) 

True 

sage: bool(abs(A(e).coordinates()) > 10**9) 

True 

 

TESTS: 

 

Check that floating points remain floating points through this method:: 

 

sage: H = HyperbolicPlane() 

sage: g = H.UHP().get_geodesic(CC(0,1), CC(2,2)) 

sage: gc = g.complete() 

sage: parent(gc._to_std_geod(g.start().coordinates())) 

Full MatrixSpace of 2 by 2 dense matrices over Complex Field 

with 53 bits of precision 

 

""" 

 

[s, e] = [k.coordinates() for k in self.complete().endpoints()] 

B = HyperbolicGeodesicUHP._get_B(p) 

# outmat below will be returned after we normalize the determinant. 

outmat = B * HyperbolicGeodesicUHP._crossratio_matrix(s, p, e) 

outmat = outmat / outmat.det().sqrt() 

if (outmat - outmat.conjugate()).norm(1) < 10**-9: 

# Small imaginary part. 

outmat = (outmat + outmat.conjugate()) / 2 

# Set it equal to its real part. 

return outmat 

 

@staticmethod 

def _crossratio_matrix(p0, p1, p2): # UHP 

r""" 

Given three points (the list `p`) in `\mathbb{CP}^{1}` in affine 

coordinates, return the linear fractional transformation taking 

the elements of `p` to `0`, `1`, and `\infty`. 

 

INPUT: 

 

- a list of three distinct elements 

of `\mathbb{CP}^1` in affine coordinates; that is, each element 

must be a complex number, `\infty`, or symbolic. 

 

OUTPUT: 

 

- an element of `\GL(2,\CC)` 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperbolic_space.hyperbolic_geodesic \ 

....: import HyperbolicGeodesicUHP 

sage: from sage.geometry.hyperbolic_space.hyperbolic_isometry \ 

....: import moebius_transform 

sage: UHP = HyperbolicPlane().UHP() 

sage: (p1, p2, p3) = [UHP.random_point().coordinates() 

....: for k in range(3)] 

sage: A = HyperbolicGeodesicUHP._crossratio_matrix(p1, p2, p3) 

sage: bool(abs(moebius_transform(A, p1)) < 10**-9) 

True 

sage: bool(abs(moebius_transform(A, p2) - 1) < 10**-9) 

True 

sage: bool(moebius_transform(A, p3) == infinity) 

True 

sage: (x,y,z) = var('x,y,z'); 

sage: HyperbolicGeodesicUHP._crossratio_matrix(x,y,z) 

[ y - z -x*(y - z)] 

[ -x + y (x - y)*z] 

 

""" 

 

if p0 == infinity: 

return matrix([[0, -(p1 - p2)], [-1, p2]]) 

elif p1 == infinity: 

return matrix([[1, -p0], [1, -p2]]) 

elif p2 == infinity: 

return matrix([[1, -p0], [0, p1 - p0]]) 

return matrix([[p1 - p2, (p1 - p2)*(-p0)], 

[p1 - p0, (p1 - p0)*(-p2)]]) 

 

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

# Other geodesics 

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

 

 

class HyperbolicGeodesicPD(HyperbolicGeodesic): 

r""" 

A geodesic in the Poincaré disk model. 

 

Geodesics in this model are represented by segments of circles contained 

within the unit disk that are orthogonal to the boundary of the disk, 

plus all diameters of the disk. 

 

INPUT: 

 

- ``start`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the start of the geodesic 

 

- ``end`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the end of the geodesic 

 

EXAMPLES:: 

 

sage: PD = HyperbolicPlane().PD() 

sage: g = PD.get_geodesic(PD.get_point(I), PD.get_point(-I/2)) 

sage: g = PD.get_geodesic(I,-I/2) 

sage: h = PD.get_geodesic(-1/2+I/2,1/2+I/2) 

 

.. PLOT:: 

 

PD = HyperbolicPlane().PD() 

g = PD.get_geodesic(I,-I/2) 

h = PD.get_geodesic(-0.5+I*0.5,0.5+I*0.5) 

sphinx_plot(g.plot()+h.plot(color='green')) 

 

""" 

 

def plot(self, boundary=True, **options): 

 

r""" 

Plot ``self``. 

 

EXAMPLES: 

 

First some lines:: 

 

sage: PD = HyperbolicPlane().PD() 

sage: PD.get_geodesic(0, 1).plot() 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

sphinx_plot(HyperbolicPlane().PD().get_geodesic(0, 1).plot()) 

 

:: 

 

sage: PD.get_geodesic(0, 0.3+0.8*I).plot() 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

PD = HyperbolicPlane().PD() 

sphinx_plot(PD.get_geodesic(0, 0.3+0.8*I).plot()) 

 

Then some generic geodesics:: 

 

sage: PD.get_geodesic(-0.5, 0.3+0.4*I).plot() 

Graphics object consisting of 2 graphics primitives 

sage: g = PD.get_geodesic(-1, exp(3*I*pi/7)) 

sage: G = g.plot(linestyle="dashed",color="red"); G 

Graphics object consisting of 2 graphics primitives 

sage: h = PD.get_geodesic(exp(2*I*pi/11), exp(1*I*pi/11)) 

sage: H = h.plot(thickness=6, color="orange"); H 

Graphics object consisting of 2 graphics primitives 

sage: show(G+H) 

 

.. PLOT:: 

 

PD = HyperbolicPlane().PD() 

PD.get_geodesic(-0.5, 0.3+0.4*I).plot() 

g = PD.get_geodesic(-1, exp(3*I*pi/7)) 

G = g.plot(linestyle="dashed",color="red") 

h = PD.get_geodesic(exp(2*I*pi/11), exp(1*I*pi/11)) 

H = h.plot(thickness=6, color="orange") 

sphinx_plot(G+H) 

 

""" 

 

opts = {'axes': False, 'aspect_ratio': 1} 

opts.update(self.graphics_options()) 

opts.update(options) 

end_1, end_2 = [CC(k.coordinates()) for k in self.endpoints()] 

bd_1, bd_2 = [CC(k.coordinates()) for k in self.ideal_endpoints()] 

# Check to see if it's a line 

if abs(bd_1 + bd_2) < EPSILON: 

pic = line([end_1, end_2], **opts) 

else: 

# If we are here, we know it's not a line 

# So we compute the center and radius of the circle 

invdet = RR.one() / (real(bd_1)*imag(bd_2) - real(bd_2)*imag(bd_1)) 

centerx = (imag(bd_2) - imag(bd_1)) * invdet 

centery = (real(bd_1) - real(bd_2)) * invdet 

center = centerx + I * centery 

radius = RR(abs(bd_1 - center)) 

# Now we calculate the angles for the arc 

theta1 = CC(end_1 - center).arg() 

theta2 = CC(end_2 - center).arg() 

theta1, theta2 = sorted([theta1, theta2]) 

# Make sure the sector is inside the disk 

if theta2 - theta1 > pi: 

theta1 += 2 * pi 

pic = arc((centerx, centery), radius, 

sector=(theta1, theta2), **opts) 

if boundary: 

pic += self._model.get_background_graphic() 

return pic 

 

show = deprecated_function_alias(20530, plot) 

 

 

class HyperbolicGeodesicKM(HyperbolicGeodesic): 

r""" 

A geodesic in the Klein disk model. 

 

Geodesics are represented by the chords, straight line segments with ideal 

endpoints on the boundary circle. 

 

INPUT: 

 

- ``start`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the start of the geodesic 

 

- ``end`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the end of the geodesic 

 

EXAMPLES:: 

 

sage: KM = HyperbolicPlane().KM() 

sage: g = KM.get_geodesic(KM.get_point((0.1,0.9)), KM.get_point((-0.1,-0.9))) 

sage: g = KM.get_geodesic((0.1,0.9),(-0.1,-0.9)) 

sage: h = KM.get_geodesic((-0.707106781,-0.707106781),(0.707106781,-0.707106781)) 

sage: P = g.plot(color='orange')+h.plot(); P 

Graphics object consisting of 4 graphics primitives 

 

 

.. PLOT:: 

 

KM = HyperbolicPlane().KM() 

g = KM.get_geodesic((0.1,0.9), 

(-0.1,-0.9)) 

h = KM.get_geodesic((-0.707106781,-0.707106781), 

(0.707106781,-0.707106781)) 

sphinx_plot(g.plot(color='orange')+h.plot()) 

 

""" 

 

def plot(self, boundary=True, **options): 

r""" 

Plot ``self``. 

 

EXAMPLES:: 

 

sage: HyperbolicPlane().KM().get_geodesic((0,0), (1,0)).plot() 

Graphics object consisting of 2 graphics primitives 

 

.. PLOT:: 

 

KM = HyperbolicPlane().KM() 

sphinx_plot(KM.get_geodesic((0,0), (1,0)).plot()) 

 

""" 

opts = {'axes': False, 'aspect_ratio': 1} 

opts.update(self.graphics_options()) 

opts.update(options) 

pic = line([k.coordinates() for k in self.endpoints()], **opts) 

if boundary: 

pic += self._model.get_background_graphic() 

return pic 

 

show = deprecated_function_alias(20530, plot) 

 

 

class HyperbolicGeodesicHM(HyperbolicGeodesic): 

r""" 

A geodesic in the hyperboloid model. 

 

Valid points in the hyperboloid model satisfy :math:`x^2 + y^2 - z^2 = -1` 

 

INPUT: 

 

- ``start`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the start of the geodesic 

 

- ``end`` -- a :class:`HyperbolicPoint` in hyperbolic space 

representing the end of the geodesic 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperbolic_space.hyperbolic_geodesic import * 

sage: HM = HyperbolicPlane().HM() 

sage: p1 = HM.get_point((4, -4, sqrt(33))) 

sage: p2 = HM.get_point((-3,-3,sqrt(19))) 

sage: g = HM.get_geodesic(p1, p2) 

sage: g = HM.get_geodesic((4, -4, sqrt(33)), (-3, -3, sqrt(19))) 

 

.. PLOT:: 

 

HM = HyperbolicPlane().HM() 

p1 = HM.get_point((4, -4, sqrt(33))) 

p2 = HM.get_point((-3,-3,sqrt(19))) 

g = HM.get_geodesic(p1, p2) 

sphinx_plot(g.plot(color='blue')) 

 

""" 

 

def plot(self, show_hyperboloid=True, **graphics_options): 

r""" 

Plot ``self``. 

 

EXAMPLES:: 

 

sage: from sage.geometry.hyperbolic_space.hyperbolic_geodesic \ 

....: import * 

sage: g = HyperbolicPlane().HM().random_geodesic() 

sage: g.plot() 

Graphics3d Object 

 

.. PLOT:: 

 

sphinx_plot(HyperbolicPlane().HM().random_geodesic().plot()) 

 

""" 

 

x = SR.var('x') 

opts = self.graphics_options() 

opts.update(graphics_options) 

v1, u2 = [vector(k.coordinates()) for k in self.endpoints()] 

# Lorentzian Gram Shmidt. The original vectors will be 

# u1, u2 and the orthogonal ones will be v1, v2. Except 

# v1 = u1, and I don't want to declare another variable, 

# hence the odd naming convention above. 

# We need the Lorentz dot product of v1 and u2. 

v1_ldot_u2 = u2[0]*v1[0] + u2[1]*v1[1] - u2[2]*v1[2] 

v2 = u2 + v1_ldot_u2 * v1 

v2_norm = sqrt(v2[0]**2 + v2[1]**2 - v2[2]**2) 

v2 = v2 / v2_norm 

v2_ldot_u2 = u2[0]*v2[0] + u2[1]*v2[1] - u2[2]*v2[2] 

# Now v1 and v2 are Lorentz orthogonal, and |v1| = -1, |v2|=1 

# That is, v1 is unit timelike and v2 is unit spacelike. 

# This means that cosh(x)*v1 + sinh(x)*v2 is unit timelike. 

hyperbola = cosh(x)*v1 + sinh(x)*v2 

endtime = arcsinh(v2_ldot_u2) 

from sage.plot.plot3d.all import parametric_plot3d 

pic = parametric_plot3d(hyperbola, (x, 0, endtime), **graphics_options) 

if show_hyperboloid: 

pic += self._model.get_background_graphic() 

return pic 

 

show = deprecated_function_alias(20530, plot)