You need some basic 2d gemetric functions (line line intersection, circle circle inter. etc)
void Horocycle()
{
const double DIMX = 800;
const double DIMY = 800;
const double B = 32;
FILE * fp = fopen("c:\\temp\\horocycle.svg","w");
fprintf(fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg\n"
"xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
"xmlns=\"http://www.w3.org/2000/svg\"\n"
"version=\"1.0\"\n"
"width=\"%g\"\n"
"height=\"%g\"\n"
"id=\"rocco\">\n"
,DIMX,DIMY
);
circle2 gc; gc.c = point2(DIMX/2,DIMY/2); gc.r = (DIMX-2*B)/2;
fprintf(fp,"<circle cx=\"%g\" cy=\"%g\" r=\"%g\" style=\"fill:#ffffE0;stroke:#000000;stroke-width:3;stroke-opacity:1\" />\n"
,gc.c.x,gc.c.y
,gc.r
);
circle2 hc; hc.r = DIMX/3; hc.c = point2(DIMX/2,B+hc.r);
fprintf(fp,"<circle cx=\"%g\" cy=\"%g\" r=\"%g\" style=\"fill:none;stroke:#0000A0;stroke-width:3;stroke-opacity:1\" />\n"
,hc.c.x,hc.c.y
,hc.r
);
const int N = 24;
int i;
for(i=0;i<N;++i)
{
double a = 2*PI*i/N + PI/N;
point2 p = hc.point(a);
fprintf(fp,"<circle cx=\"%g\" cy=\"%g\" r=\"%g\" style=\"fill:#000000;stroke:#000000;stroke-width:3;stroke-opacity:1\" />\n"
,p.x,p.y
,4.0
);
segment2 s( p, point2(DIMX/2,B) );
line2 ax; s.axis(ax);
line2 ba; ba.orig.x = DIMX/2; ba.orig.y = B; ba.dire.x = 1; ba.dire.y = 0;
point2 pp; line_line_int(ax,ba,pp);
double ra = dist(pp,p);
circle2 cc; cc.c = pp; cc.r = ra;
point2 p1,p2; intersection(cc,gc,p1,p2);
fprintf(fp,"<path d=\"M%g,%g A%g,%g 0 0,1 %g,%g\" style=\"fill:none;stroke:#800000;stroke-width:1.5;stroke-opacity:1\" />\n"
,p1.x,p1.y
,cc.r,cc.r
,p2.x,p2.y
);
}
fprintf(fp,"</svg>\n");
fclose(fp);
}