In the Poincaré model of non-Euclidean geometry,
the geodesic lines are the arcs interior to
the unit circle perpendicular to its boundary.
Define a method with points P, Q as
arguments that draws the `line'
between them.
The problem is to find
the center C
of the a circle
passing through the two points P
and Q that is orthogonal
to the boundary of the unit circle.
Vector algebra works well.
Set R = (1/2)(P+Q), the midpoint
between P and Q, v = Q-P,
w the vector obtained from v by rotating 90 degrees:
w = [-v[1], v[0]]. Then C is of the form
C(t) = R + tw, and we have to determine t so
the distance from C(t) to P is the same as
the length of the tangent segment from the circle
to C(t). This length
is determined by Pythagoras' theorem to
be |R + tw|2 - 1, so we write
|
|R + tw - P|2 = |R + tw|2 - 1
|
and also using |u + v|2 = |u|2 + 2 u*v + |v|2
(where * is dot product).
We get a linear equation for t.
There is a special case when P and Q
lie on a diameter of the circle, or close to it.