The L2Primitives Package for Mathematica
by I. Knezevic, R. Sazdanovic, S. Vukmirovic
      (knele@yubc.net, seasmile@galeb.etf.bg.ac.yu, vsrdjan@matf.bg.ac.yu)
(User's Guide for version 1.1, 16.01.2002)

L2Primitives is a package for manipulation with basic objects of the Lobachevskian  plane (L2) and their representation in three models of that geometry. Basic objects include: points, polygonal lines, polygons, circles and disks. Transformations that can be applied on the objects are: reflection with respect to a point or line, rotation and hyperbolic translation. Models of the Lobachevskian plane supported are: PoincareDisk(PD) , KleinDisk (KD) and HalfPlane (HP).

Basic objects are abstract most of the time. That means that user has only two contacts with their representation in a certain model.
As first, he enters L2 points in a chosen model using the commands PDPoint, KDPoint, HPPoint. Then they become abstract points internally called LPoint.  User then can  manipulate them without thinking how  they are internally represented.  He can make of them any basic object(line, circle...) which is purely abstract. Such abstract objects can be isometrically  mapped  into other abstract objects. 
When the objects are created, user can graphically represent them in a model of his choice using the function LToGraphics.

Inputing L2 points in various models.

This loads the package  (change the path to the location where you have copied L2Primitives.m).

<< c://L2Primitives.m

Here we define three LPoints using different models (usually, it doesn't make much sense).

a  =  PDPoint[{-1/3,  1/3}];
b =  KDPoint[{1/2,  1/3}];
c =  HPPoint[{1,  3}];

Each of them has internal LPoint representation.

?a

All other basic objects are based on LPoints

Basic L2 objects are based on the LPoints

We define triangle polygonal line and filled triangle determined by the points a, b, c.

tr  =  LLine[{a,  b,  c,  a}];
poltr  =  LPolygon[{a,  b,  c}];

Here are isometric transformations that can be applied to a basic object or to a list of them

Isometric transformations of L2

We reflect the triangle over the its edges and obtain another three triangles.

tr1  =   L2Reflection[LLine[{a, b}]][
          tr];
tr2  =   L2Reflection[LLine[{a, c}]][
          tr];
tr3  =   L2Reflection[LLine[{b, c}]][tr];

Finally, we can draw  in a model of choice the objects that we have created.
 We use the function LToGraphics to represent a basic object or a list of them as a Graphics primitive depending on the chosen model.

Transforming a basic L2 object into Graphics object

Now,we apply LToGraphics to the list of our object and obtain a list of Graphics primitives representing them. Then we apply Graphics.

grPD  =  
        Graphics[
          LToGraphics[{a,  b,  c,  poltr,  tr1,  tr2,  tr3},  
            Model -> PoincareDisk]];

We create the unit circle representing the points at the infinity in KleinDisk and PoincareDisk model.

absolut =  Graphics[Circle[{0, 0},  1]];

Now,we draw the objects in a PoincareDisk model as ordinary Graphics objects.

Show[{grPD, absolut},  
        PlotRange -> {{-1, 1},  {-1, 1}},  
        AspectRatio -> Automatic];

We create their representation in remaining models in order to show them together.

grKD  =  
        Graphics[
          LToGraphics[{a,  b,  c,  poltr,  tr1,  tr2,  tr3},  
            Model -> KleinDisk]];
grHP  =  
        Graphics[
          LToGraphics[{a,  b,  c,  poltr,  tr1,  tr2,  tr3},  
            Model -> HalfPlane]];

Show[
        GraphicsArray[{
Show[absolut,  grPD,  
              PlotRange -> {{-1, 1},  {-1, 1}},  
              AspectRatio -> Automatic,  
              DisplayFunction -> Identity], 
Show[
              absolut,  grKD,  
              PlotRange -> {{-1, 1},  {-1, 1}},  
              AspectRatio -> Automatic, 
              DisplayFunction -> Identity], 
Show[
              grHP,  PlotRange -> {{-1, 3},  {0, 4}},  
              AspectRatio -> Automatic,  Axes -> {True,  True}, 
              DisplayFunction -> 
                Identity]
}]];

Finally, we are going to rotate triangle tr, around its vertex a. Output of LToGraphics can be treated as any  Graphics primitive. For example, we color triangle in each instance of time by a different colour.

Table[
Show[
          absolut, 
         Graphics[{RGBColor[
                Cos[t/4],  Sin[t/4], 
                0.5], 
                            LToGraphics[
                LPolygon[{a,  L2Rotation[a, t][b], L2Rotation[a, t][
                      c]}],  Model -> 
                  PoincareDisk]
                        }], 
          PlotRange -> {{-1, 1},  {-1, 1}},  
          AspectRatio -> Automatic], 
     {t,  
          0,  2 Pi,  2 Pi/20}];