function maakTop(x1,y1,x2,y2,dirX,dirY)
{xm = Math.round((x1+x2)/2);
 ym = Math.round((y1+y2)/2);
 z = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
 cosinus = (x2-x1)/z;
 sinus = (y2-y1)/z;
 h = 0.866*z;
 this.Tx = Math.round(xm - dirX*h*sinus);
 this.Ty = Math.round(ym + dirY*h*cosinus);
}
function drawTor(canvas)
{with (canvas)
{clear();
 setColor("#d00000");
 setStroke(2);
 drawLine(Ax,Ay,Bx,By);
 drawLine(Ax,Ay,Cx,Cy);
 drawLine(Cx,Cy,Bx,By);
 setColor("#c0c0c0");
 drawLine(Cx,Cy,BC.Tx,BC.Ty);
 drawLine(Cx,Cy,AC.Tx,AC.Ty);
 drawLine(Bx,By,AB.Tx,AB.Ty);
 drawLine(Bx,By,BC.Tx,BC.Ty);
 drawLine(Ax,Ay,AC.Tx,AC.Ty);
 drawLine(Ax,Ay,AB.Tx,AB.Ty);
 setColor("#000000");
 fillEllipse(Ax,Ay,5,5);//A
 fillEllipse(Bx,By,5,5);//B
 fillEllipse(Cx,Cy,5,5);//C
 fillEllipse(AB.Tx,AB.Ty,5,5);//C'
 fillEllipse(AC.Tx,AC.Ty,5,5);//B'
 fillEllipse(BC.Tx,BC.Ty,5,5);//A'
 setColor("#0000e0");
 setFont("arial",16,Font.BOLD);
 drawString("A",Ax-10,Ay);
 drawString("B",Bx+10,By);
 drawString("C",Cx,Cy-20);
 drawString("A'",BC.Tx+10,BC.Ty-10);
 drawString("B'",AC.Tx-20,AC.Ty-10);
 drawString("C'",AB.Tx+10,AB.Ty-10);
}}
function drawT(canvas)
{with (canvas)
 {setColor("#00d000");
 drawLine(Ax,Ay,BC.Tx,BC.Ty);
 drawLine(Bx,By,AC.Tx,AC.Ty);
 drawLine(Cx,Cy,AB.Tx,AB.Ty);
 setColor("#000000");
 fillEllipse(289,162,5,5);
 setColor("#0000e0");
 setFont("arial",16,Font.BOLD);
 drawString("T",300,160);
}} 
function tekenMLboog(canvas,x1,y1,x2,y2)
//teken boog voor middelloodlijn
{xx = x2-x1;
 yy = y2-y1;
 mx = Math.round((x1+x2)/2);
 my = Math.round((y1+y2)/2);
 xxyy = Math.abs(yy/xx);
 ha = Math.atan(xxyy);
 b = Math.sqrt(yy*yy + xx*xx)/2;
 r = Math.sqrt(b*b + 2500);
 dx = 50*Math.sin(ha);
 dy = 50*Math.cos(ha);
 da = Math.atan(50/b);
 code = 0;
 if (xx<0){code++}
 if (yy<0){code+=2}
 switch (code)
 {case 1 : {ha = 3.1416 - ha;
            dx = -dx}
   break
  case 2 : {ha = -ha;
            dy = -dy}
   break
  case 3 : {ha = ha + 3.1416;
            dx = -dx;
			dy = -dy}
 }  
 x11 = mx + dx;
 y11 = my - dy;
 x12 = mx - dx;
 y12 = my + dy;
 ha1 = ha-da;
 ha2 = ha+da;
 da = (ha2-ha1)/20;
 with (canvas)
 {setStroke(stroke.DOTTED);
  setColor("#00d000");
  drawLine(x1,y1,x11,y11);
  drawLine(x1,y1,x12,y12);
  setColor("#c0c0c0");
  setStroke(1);
 }
 oldX = x1 + Math.round(r*Math.cos(ha1));
 oldY = y1 + Math.round(r*Math.sin(ha1));
 with (canvas)
 {for (i = ha1; i<=ha2; i=i+da)
   {newX = x1 + Math.round(r*Math.cos(i));
    newY = y1 + Math.round(r*Math.sin(i));
    drawLine(oldX,oldY,newX,newY);
	oldX = newX;
    oldY = newY;
}}}
function tekenMLlijn(canvas,x1,y1,x2,y2)
{with (canvas)
 {setColor("#0000b0");
  canvas.drawLine(x1,y1,x2,y2); 
}} 
function tekenOmCirkel(canvas,x1,y1,x2,y2,x3,y3)
{teller3 = 3;
 a1 = (x1-x2)/(y2-y1);
 b1 = (y1+y2-a1*(x1+x2))/2;
 a2 = (x1-x3)/(y3-y1);
 b2 = (y1+y3-a2*(x1+x3))/2;
 sx = Math.round((b2-b1)/(a1-a2));
 sy = Math.round(a1*sx+b1);
 dx = sx-x1;
 dy = sy-y1;
 r = Math.round(Math.sqrt(dx*dx+dy*dy));
 d = r + r;
 with (canvas)
 {setColor("#000000");
  fillEllipse(sx-3,sy-3,6,6);
  setColor("#0000b0");
  drawLine(sx,sy,(x1+x2)*0.5,(y1+y2)*0.5);
  drawLine(sx,sy,(x2+x3)*0.5,(y2+y3)*0.5);
  setStroke(2);
  setColor("#0000e0");
  drawEllipse(sx-r,sy-r,d,d);
}} 
function MLlijn(canvas,x1,y1,x2,y2)
{switch (teller3)
 {case 1 : tekenMLboog(canvas,x1,y1,x2,y2)
   break
  case 2 : tekenMLboog(canvas,x2,y2,x1,y1)
   break
  case 3 : tekenMLlijn(canvas,x11,y11,x12,y12)
}}
function trekLijnen()
{switch (teller2*10+teller3)
 {case 11 : {canv2.setColor("#00b000");
			 canv2.setStroke(2);
			 canv2.drawLine(ptx,pty,Ax,Ay)  
		    }
   break
  case 12 : {canv2.drawLine(ptx,pty,Bx,By)}
   break 
  case 13 : {canv2.drawLine(ptx,pty,Cx,Cy)}
   break
  case 21 : {canv2.drawLine(ptx,pty,AC.Tx,AC.Ty)}
   break 
  case 22 : {canv2.drawLine(ptx,pty,BC.Tx,BC.Ty)}
   break
  case 23 : {canv2.drawLine(ptx,pty,AB.Tx,AB.Ty)}
   break 
  case 31 : {teller2 = 3;
             canv2.setColor("#000000");
             canv2.drawString("W",ptx,pty)}
}}
function OmCirkel(canvas,x1,y1,x2,y2,x3,y3)
{switch (teller2)
 {case 1 : MLlijn(canvas,x1,y1,x2,y2)
   break
  case 2 : MLlijn(canvas,x2,y2,x3,y3)
   break
  case 3 : tekenOmCirkel(canvas,x1,y1,x2,y2,x3,y3) 
}}
function action2X()
{switch (teller1)
  {case 0 : {drawTor(canv2);
             teller1++;
			 teller3 = 0;
			}
    break
   case 1 : OmCirkel(canv2,Cx,Cy,AC.Tx,AC.Ty,Ax,Ay)
    break
   case 2 : OmCirkel(canv2,Bx,By,BC.Tx,BC.Ty,Cx,Cy)
    break
   case 3 : trekLijnen()
  } 
  teller3++;//1pass
  if (teller3 == 4)
   {teller3 = 1;
    teller2++;
   }
  if (teller2 == 4)
   {teller2 = 1;
    teller1++;
   }
  if (teller1 == 4) {busy = 0;
                     canv2.drawString("finished",10,400)}
  else {setTimeout("action2X()",1000)};
 canv2.paint(); 
}
function rotate(canvas,xc,yc,x1,y1,x2,y2,h)
{xx1 = (x1-xc);
 yy1 = (y1-yc);
 xx2 = (x2-xc);
 yy2 = (y2-yc);
 cosinus =  Math.cos(h);
 sinus = Math.sin(h);
 rx1 = xc + Math.round(xx1*cosinus - yy1*sinus);
 ry1 = yc + Math.round(yy1*cosinus + xx1*sinus);
 rx2 = xc + Math.round(xx2*cosinus - yy2*sinus);
 ry2 = yc + Math.round(yy2*cosinus + xx2*sinus);
 with (canvas)
 {setColor("#d000d0");
  drawLine(xc,yc,rx1,ry1);
  drawLine(xc,yc,rx2,ry2);
  drawLine(rx1,ry1,rx2,ry2)
}}
function action3X()
{hv = 0.10472*teller1;
 drawTor(canv3);
 drawT(canv3);
 rotate(canv3,Cx,Cy,ptx,pty,Ax,Ay,hv);
 canv3.paint();
 if (teller1 < 10){teller1++;
                   setTimeout("action3X()",400)}
 else {busy=0;
       with (canv3)
	   {setColor("#000000");
	    drawString("T'",210,120);
        drawString("finished",10,400);
	    paint()}
	  }	
}
function setPuntT()
{a1 = (BC.Ty-Ay)/(BC.Tx-Ax);
 b1 = Ay-a1*Ax;
 a2 = (AC.Ty-By)/(AC.Tx-Bx);
 b2 = By-a2*Bx;
 ptx = (b2-b1)/(a1-a2);
 pty = a1*ptx+b1;
}   
