/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

void dir(P f(double), double t)
{
  P T(f(t)), H(f(t+0.01));
  arrow(T, H);
}

double th(1.0/8), rad(2.5);
const double k1(log(rad)/(2 + th));

P f1(double t)
{
  return polar(exp(k1*t), t);
}

double r2(double t)
{
  double u(t/(1 - th));
  return 1 - 1.75*u + (rad + 0.75)*(0.25*pow(u, 2) + 0.75*pow(u, 4));
}

P f2(double t)
{
  return polar(r2(t), -t);
}

int main()
{
  picture(P(-2, -2), P(3, 2), "2.5 x 2in");

  begin();
  revolutions();
  P pO(0,0), pX(xmax()+0.25, 0), pY(0, ymax()),
    zeta(polar(rad, th)),
    pP(f1(1)), pQ(f1(2));

  arrow_inset(0.5);
  arrow_ratio(2);
  arrow_width(2);

  bold();
  line(P(xmin(), 0), pX);
  line(P(0, ymin()-0.25), pY);

  plot(f1, 0, 2 + th, 180);

  dir(f1, 0.45);
  dir(f1, 0.875);
  dir(f1, 1.475);
  dir(f1, 2.05);

  dir(f2, 0.55);
  dir(f2, 0.8);

  dashed();
  plot(f2, 0, 1 - th, 30);

  label(pO, P(2,-4), "$O$", br);
  label(pX, P(0,-4), "$X$", b);
  label(pY, P(2, 0), "$Y$", r);

  label(zeta, P(4,2), "$\\zeta$", r);

  label(P(1,0), P(0,-4), "$1$", br);
  label(pP, P(0,-4), "$P$", br);
  label(pQ, P(2,-4), "$Q$", br);

  tikz_format();
  end();
}
