#include "epix2.h"
using namespace ePiX2;

double rad(3), ht(3), tw(0.3333);

Point fp_top(const double t)
{
  return Point(rad*Cos(t), rad*Sin(t), ht);
}

Point fp_bot(const double t)
{
  return Point(rad*Cos(t+tw), rad*Sin(t+tw), -ht);
}

Point fm_top(const double t)
{
  return Point(rad*Cos(t+tw), rad*Sin(t+tw), ht);
}

Point fm_bot(const double t)
{
  return Point(rad*Cos(t), rad*Sin(t), -ht);
}

int main() {

  World world;

  Camera camera;
  Picture picture(Pair(-4,-4), Pair(4,4), "6x6in");

  std::string fore("1pt"), aft("2.5pt");

  text_style().text(RGB(0.8,0.1)).back(White()).pad(Length("1pt")).align(tr);
  const int N(24);

  Duo_Pen green(Green(1.2), fore, Green(0.6), aft);
  Duo_Pen blue(Blue(1.5), fore, Blue(0.8), aft);
  Duo_Pen purple(RGB(0.8,0.6,1), fore, RGB(0.6, 0, 0.8), aft);
  Duo_Pen neon(Red(1.5), fore, Red(0.6), aft);

  rotations();

  for (int i=0; i<N; ++i)
    {
      Point head_p(fp_top(i*1.0/N)), tail_p(fp_bot(i*1.0/N));
      Point head_m(fm_top(i*1.0/N)), tail_m(fm_bot(i*1.0/N));

      for (int j=0; j<12; ++j)
	world << Segment(tail_p+(j*1.0/12)*(head_p - tail_p),
			 tail_p+((j+1)*1.0/12)*(head_p - tail_p)).stroke(green)
	      << Segment(tail_m+(j*1.0/12)*(head_m - tail_m),
			 tail_m+((j+1)*1.0/12)*(head_m - tail_m)).stroke(purple);
    }

  world << Circle(Point(0,0,ht), rad, E_3(Point(0,0,ht))).stroke(blue)
	<< Circle(Point(0,0,-ht), rad, -E_3(Point(0,0,-ht))).stroke(blue);


  Vector blade(Point(0,0,0.5), -1, 0, -1);
  Knife k(blade, bold(Red()));
  world.chop(k);

  world	<< Label(fm_bot(0.25), "$x^2 + y^2 - z^2 = 1$").offset("4x4pt")
	<< Label(Point(-1,2,2), "$x+z = 1$").offset("4x4pt");

  camera.at(Point(10, 1, 2)).tilt(-0.0125);

  world.fog(Black(), 0.25, 10);

  world.photo(picture, camera);
  picture.backing(Black());

  print(picture, "cut_hyperboloid.eepic", PSTricks());
}
