Skip to content

Commit

Permalink
Trac #19217: Bugfix hyperbolic_arc and hyperbolic_polygon
Browse files Browse the repository at this point in the history
If you draw an hyperbolic arc between two points with almost the same
real part, it may result in a wrong arc.

You can see it as follows:
{{{
g = hyperbolic_triangle(-1+I, 1.0000000000001+I, 1000*I+1, fill = true);
g.set_axes_range(-1.5,1.5,-.5,2.5)
g.show()
}}}

URL: http://trac.sagemath.org/19217
Reported by: skraemer
Ticket author(s): Stefan Kraemer
Reviewer(s): Vincent Delecroix
  • Loading branch information
Release Manager authored and vbraun committed Oct 14, 2015
2 parents 1bace59 + adec9d2 commit 522a88c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/sage/plot/hyperbolic_arc.py
Expand Up @@ -7,6 +7,7 @@
"""
#*****************************************************************************
# Copyright (C) 2011 Hartmut Monien <monien@th.physik.uni-bonn.de>,
# 2015 Stefan Kraemer <skraemer@th.physik.uni-bonn.de>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
Expand Down Expand Up @@ -70,20 +71,21 @@ def _hyperbolic_arc(self, z0, z3, first=False):
the hyperbolic arc between the complex numbers z0 and z3 in the
hyperbolic plane.
"""
if (z0-z3).real() == 0:
z0, z3 = (CC(z0), CC(z3))
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
r = abs(z0-p)

if abs(z3-z0)/r < 0.1:
self.path.append([(z0.real(),z0.imag()), (z3.real(),z3.imag())])
return
z0, z3 = (CC(z0), CC(z3))

if z0.imag() == 0 and z3.imag() == 0:
p = (z0.real()+z3.real())/2
r = abs(z0-p)
zm = CC(p, r)
self._hyperbolic_arc(z0, zm, first)
self._hyperbolic_arc(zm, z3)
return
else:
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
r = abs(z0-p)
zm = ((z0+z3)/2-p)/abs((z0+z3)/2-p)*r+p
t = (8*zm-4*(z0+z3)).imag()/3/(z3-z0).real()
z1 = z0 + t*CC(z0.imag(), (p-z0.real()))
Expand Down
14 changes: 8 additions & 6 deletions src/sage/plot/hyperbolic_polygon.py
Expand Up @@ -8,7 +8,8 @@
"""
#*****************************************************************************
# Copyright (C) 2011 Hartmut Monien <monien@th.physik.uni-bonn.de>,
# 2014 Vincent Delecroix <20100.delecroix@gmail.com>
# 2014 Vincent Delecroix <20100.delecroix@gmail.com>,
# 2015 Stefan Kraemer <skraemer@th.physik.uni-bonn.de>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
Expand Down Expand Up @@ -85,20 +86,21 @@ def _hyperbolic_arc(self, z0, z3, first=False):
the hyperbolic arc between the complex numbers z0 and z3 in the
hyperbolic plane.
"""
if (z0-z3).real() == 0:
z0, z3 = (CC(z0), CC(z3))
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
r = abs(z0-p)

if abs(z3-z0)/r < 0.1:
self.path.append([(z0.real(), z0.imag()), (z3.real(), z3.imag())])
return
z0, z3 = (CC(z0), CC(z3))

if z0.imag() == 0 and z3.imag() == 0:
p = (z0.real()+z3.real())/2
r = abs(z0-p)
zm = CC(p, r)
self._hyperbolic_arc(z0, zm, first)
self._hyperbolic_arc(zm, z3)
return
else:
p = (abs(z0)*abs(z0)-abs(z3)*abs(z3))/(z0-z3).real()/2
r = abs(z0-p)
zm = ((z0+z3)/2-p)/abs((z0+z3)/2-p)*r+p
t = (8*zm-4*(z0+z3)).imag()/3/(z3-z0).real()
z1 = z0 + t*CC(z0.imag(), (p-z0.real()))
Expand Down

0 comments on commit 522a88c

Please sign in to comment.