import java.applet.*;
import java.awt.*;


//*****************************************************
class Vector2D
{

    double Sproduct(Vector2D C)
    {
        return Y[0] * C.Y[0] + Y[1] * C.Y[1];
    }

    Vector2D Plus(Vector2D C)
    {
        return new Vector2D(Y[0] + C.Y[0], Y[1] + C.Y[1]);
    }

    double Get_Elem(int i)
    {
        return Y[i];
    }

    Vector2D()
    {
        Y = new double[2];
        Y[0] = 0.0D;
        Y[1] = 0.0D;
    }

    Vector2D(double InitY1, double InitY2)
    {
        Y = new double[2];
        Y[0] = InitY1;
        Y[1] = InitY2;
    }

    Vector2D(Vector2D Other_Vector)
    {
        Y = new double[2];
        int i = 0;
        do
            Y[i] = Other_Vector.Y[i];
        while(++i <= 1);
    }

    double Abs()
    {
        return Math.sqrt(Y[0] * Y[0] + Y[1] * Y[1]);
    }

    String Show()
    {
        return String.valueOf(Y[0]) + "," + String.valueOf(Y[1]);
    }

    Vector2D Minus(Vector2D C)
    {
        return new Vector2D(Y[0] - C.Y[0], Y[1] - C.Y[1]);
    }

    Vector2D Rot(double degree)
    {
        double cosd = Math.cos(degree * 0.017453292519943295D);
        double sind = Math.sin(degree * 0.017453292519943295D);
        return new Vector2D(Y[0] * cosd - Y[1] * sind, Y[0] * sind + Y[1] * cosd);
    }

    Vector2D Unit()
    {
        double ab = Abs();
        if(ab <= 1E-050D)
            return new Vector2D(1.0D, 0.0D);
        else
            return new Vector2D(Y[0] / ab, Y[1] / ab);
    }

    Vector2D Mult(double C)
    {
        return new Vector2D(Y[0] * C, Y[1] * C);
    }

    final double DPAI = 0.017453292519943295D;
    double Y[];
}


//********************************************************









//******************************************

class Engineer extends java.applet.Applet

//******************************************

{



short Ascii_Address[]={

  1,  2,  3,  4,  5,  6,  7,  8,

  9, 10, 11, 12, 13, 14, 15, 16,

 17, 18, 19, 20, 21, 22, 23, 24,

 25, 26, 27, 28, 29, 35, 41, 51,

 57, 58, 63, 68, 77, 92,105,118,

121,128,135,142,147,154,157,163,

166,176,182,191,205,213,223,235,

240,258,271,282,295,299,304,308,

319,338,346,358,367,374,381,386,

398,404,411,417,423,427,432,436,

449,456,468,478,491,496,503,507,

513,517,523,530,535,545,550,554,

557,558,572,583,592,603,614,622,

635,643,648,656,663,666,677,686,

696,707,718,726,737,744,753,757,

763,768,775,780,786,796,797,798

};



short Symbol_Table[]={

999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,

999,999,999,999,999,999,999,999,999,999,999,999,999,213,262, 34,

263,442,999,263,212, 26,212,432,999,413,512,622,632,542,442,332,

322,412,999,313,612,642,342,312,999,999, 19,522,623,722,999, 11,

212, 27,232,999,303,242,503,442, 11,712, 27,732,999,603,712,732,

642,442,332,312,202,102, 12, 32,142, 19,722,999,  3, 10,112,102,

  2,743,732,632,642,742,143,602,999,743,522,102, 10, 18,132,232,

402,602,712,732,642,999, 27,212,999, 27,122,312,412,622,732,999,

 11,122,332,432,622,712,999,143,542,123,562,163,522,999,143,542,

323,362,999,723,632,532,522,622,632,999,303,342,999,723,622,632,

732,722,999, 35,702,999,603,102, 12, 32,142,642,732,712,602,999,

113, 22,722,712,732,999,103, 10, 32,142,342,602,702,742,999,103,

 12, 32,142,242,332,312,332,442,642,732,712,602,999, 33,502,542,

 33,732,722,742,999,603,712,732,642,442,332,302,  2, 42,999,303,

332,442,642,732,712,602,102, 12, 32,142,999,  3, 42,622,722,999,

603,402,312,332,242,142, 32, 12,102,202,312,332,442,642,732,712,

602,999,603,712,732,642,142, 32, 12,102,302,412,432,342,999,223,

322,332,232,222,523,622,632,532,522,999,223,322,332,232,222,523,

622,632,532,522,633,722,999,143,302,542,999,203,242,503,542,999,

103,342,502,999,303,102, 10, 26,142,242,422,522,623,722,999,103,

 10, 26,142,642,532,332,222,212,302,502,612,622,532,643,732,712,

602,999,102, 12, 32,142,742,443,402,999,  2, 32,142,242,332,302,

333,442,642,732,702,999,143, 32, 12,102,602,712,732,642,999,  2,

 32,142,642,732,702,999,  2, 42,333,302,703,742,999,  2, 42,333,

302,999,603,102, 12, 32,142,603,712,732,642,542,532,999,  2,303,

342, 43,742,999,713,732,723, 22, 13, 32,999,603,712,732,642, 42,

999,  2,403, 42,223,742,999,  2,703,742,999,  2,322, 42,742,999,

  2,742, 42,999,603,102, 12, 32,223, 42, 33,142,642,732,712,602,

999,  2, 32,142,242,332,302,999,603,102, 12, 32,142,642,732,712,

602,523,742,999,  2, 32,142,242,332,302,333,442,742,999,603,712,

732,642,442,332,312,202,102, 12, 32,142,999,  3, 42, 23,722,999,

  3,602,712,732,642, 42,999,  3,722, 42,999,  3,702,422,742, 42,

999, 42,  3,742,999,  3,222, 42,223,722,999, 42,  2,323,332,703,

742,999, 27, 18,722,732,999,  3,222, 42,223,722,303,342,503,542,

999, 11, 18,722,712,999,503, 18,542,999,703,742,999,999,303,212,

222,332,632,742,633,722,712,602,502,412,432,999,  3,702,603,712,

732,642,342,232,212,302,999,343,232,212,302,602,712,732,642,999,

 35,742,343,232,212,302,602,712,732,642,999,403,442,342,232,212,

302,602,712,732,642,999,143, 26, 18,112,712,303,332,999,443,532,

512,402,302,212,232,342,742,832,812,702,999,  3,702,303,212,232,

342,742,999, 19,122,223,722,999, 27,132,233,732,822,812,702,999,

  3,702,503,242,413,742,999, 19,722,999,203,702,303,212,322,722,

323,232,342,742,999,203,312,712,313,222,232,342,742,999,713,732,

642,342,232,212,302,602,712,999,203,802,303,212,232,342,642,732,

712,602,999,343,232,212,302,602,712,732,642,243,842,999,203,312,

712,413,222,232,342,999,343,232,212,302,402,542,642,732,712,602,

999,123,622,732,642,203,242,999,203,602,712,722,632,232,633,742,

999,203,722,242,999,203,712,222,732,242,999,203,742,243,702,999,

203,532,243,822,812,702,999,203,242,702,742,999,203,602,642,242,

202,999,303,502,612,632,542,342,232,212,302,999,999,999,999,999

};

  int x_dim,y_dim;



  double  

		ixold ,		iyold ,

		gx01=0.0 ,	gy01=0.0 ,

		ch1=1.4 ,	ch2=0.7  , 

		dxy ,		wid;



  long	jgx0=  0 ,	jgy0=  0 ,

		jgx1 ,		jgy1 ;



  final double DPAI=Math.PI/180.;



// Constructor start

//==========================================

  Engineer(int x_dim,int y_dim,

	  double wid,

	  double gx01,double gy01,

	  long jgx0,long jgy0,

	  long jgx1,long jgy1)

//==========================================

  {

	  this.x_dim=x_dim;

	  this.y_dim=y_dim;

	  this.wid=wid;

	  this.gx01=gx01;

	  this.gy01=gy01;

	  this.jgx0=jgx0;

	  this.jgy0=jgy0;

	  this.jgx1=jgx1;

	  this.jgy1=jgy1;

	  dxy=(double)(jgx1-jgx0)/wid;

  }

//==========================================

  Engineer(int x_dim,int y_dim,

	  double wid,

	  double gx01,double gy01)

//==========================================

  {

	  this(x_dim,y_dim,wid,gx01,gy01,0,0,x_dim,y_dim);

  }

//==========================================

  Engineer()

//==========================================

  {

	  this(300,200,30.,0.,0.);

  }

//==========================================

  Engineer(int x_dim,int y_dim)

//==========================================

  {

	  this(x_dim,y_dim,30.,0.,0.);

  }

//==========================================

  Engineer(int x_dim,int y_dim,double wid)

//==========================================

  {

	  this(x_dim,y_dim,wid,0.,0.);

  }

// Constructor end

// from Tim 980223



//==========================================

void setWorldWidth( double wid, double gx01)

//==========================================

{

    this.wid=wid;

    this.gx01=gx01;



	dxy=(double)(jgx1-jgx0)/wid;

}

//==========================================

  public double convert(int x)

//==========================================

  {

	  return x/dxy;

  }



//==========================================

  public double convertX(int x)

//==========================================

  {

	  return gx01+x/dxy;

  }



//==========================================

  public double convertY(int y)

//==========================================

  {

	  return gy01+(y_dim-y)/dxy;

  }

// from Tim 980223



//==========================================

  public void u_plot(Graphics g,double x,double y,int n)

//==========================================	

  {

	int ix,iy;

	if(n == -3)

	{

	    gx01=gx01-x;

	    gy01=gy01-y;

		return;

	}

	ix=(int)     (jgx0+(x-gx01)*dxy);

	iy=(int)(jgy1-(jgy0+(y-gy01)*dxy));

	if(n == 2)	g.drawLine((int)ixold,(int)iyold,ix,iy);

	ixold=ix;

	iyold=iy;

  }

//==========================================

  public void u_plot(Graphics g,Vector2D V,int n)

//==========================================	

  {

	u_plot(g,V.Get_Elem(0),V.Get_Elem(1),n);

  }

//==========================================

  public Vector2D getScreenCoord(Graphics g,Vector2D V)

//==========================================	

  {

	u_plot(g,V.Get_Elem(0),V.Get_Elem(1),3);

	return new Vector2D(this.ixold,this.iyold);

  }

//==========================================

  public void arc_arrow(Graphics g,

	  Vector2D e0,Vector2D e1, double angle,int mode)

//==========================================

  {

   	  Vector2D ixoldQ=getScreenCoord(g,e1);

   	  Vector2D ixoldD=getScreenCoord(g,new Vector2D(0.,0.));

	  ixoldQ=ixoldQ.Minus(ixoldD);



	  double widhei=2.*ixoldQ.Abs();	



	  double theta=Math.acos(e1.Sproduct(new Vector2D(1.0,0.))/

		  e1.Abs())*180./Math.PI;

	  if(e1.Get_Elem(1) <0.)theta=-theta;



   	  ixoldQ=getScreenCoord(g,e0);

	  double ixoldq=ixoldQ.Get_Elem(0);

	  double iyoldq=ixoldQ.Get_Elem(1);



	  g.drawArc((int)(ixoldq-widhei*.5),(int)(iyoldq-widhei*.5),

		  (int)widhei,(int)widhei,(int)theta,(int)angle);



	  Vector2D Termarrow,Wing0arrow,Wing1arrow;

	  if(mode%2 ==0)

	  {

		  Termarrow=new Vector2D(e0.Plus(e1.Rot(angle)));

		  Wing0arrow=

			  new Vector2D((e1.Rot(angle-90.+ 5.)).Mult(.5));

		  Wing1arrow=

			  new Vector2D((e1.Rot(angle-90.-35.)).Mult(.5));

		  u_plot(g,Termarrow.Plus(Wing0arrow),3);

		  u_plot(g,Termarrow,2);

		  u_plot(g,Termarrow.Plus(Wing1arrow),2);

	  }

	  if(mode>=3)

	  {

		  Termarrow=new Vector2D(e0.Plus(e1));

		  Wing0arrow=

			  new Vector2D((e1.Rot(90.- 5.)).Mult(.5));

		  Wing1arrow=

			  new Vector2D((e1.Rot(90.+35.)).Mult(.5));



		  u_plot(g,Termarrow.Plus(Wing0arrow),3);

		  u_plot(g,Termarrow,2);

		  u_plot(g,Termarrow.Plus(Wing1arrow),2);

	  }

  }

//==========================================

  public void arrow(Graphics g,

	  double x0,double y0, double x1,double y1,

	  int mode)

//==========================================

  {

	  arrow(g,new Vector2D(x0,y0),new Vector2D(x1,y1),mode);

  }

//==========================================

  public void arrow(Graphics g,

	  Vector2D e0,Vector2D e1, int mode)

//==========================================

/*  e0(x0,y0),e1(x1,y1)

	mode

	1 : no arrow

	2 : only on e1 side

	3 : only on e0 side

	4 : both side of e0 and e1

*/

  {

	  Vector2D	de=new Vector2D(e1.Minus(e0)),

				deunit=new Vector2D(de.Unit()),

				wing0=new Vector2D(deunit.Rot(15.)),

				wing1=new Vector2D(deunit.Rot(-15.));



  	  u_plot(g,e0,3);

	  u_plot(g,e1,2);

	if(mode <=1 || mode >4)return;

	if(mode>=3)

	{

		u_plot(g,e0.Plus(wing0),3);

		u_plot(g,e0,2);

		u_plot(g,e0.Plus(wing1),2);

	}

	if(mode%2 ==0)

	{

		u_plot(g,e1.Minus(wing0),3);

		u_plot(g,e1,2);

		u_plot(g,e1.Minus(wing1),2);

	}



	return;	

  }

//==========================================

  public void Dimension(Graphics g,

	  double x0,double y0, double x1,double y1,double supl,

	  int mode,String title)

//==========================================

  {

	  Dimension(g,

	  new Vector2D(x0,y0),new Vector2D(x1,y1),supl,mode,title);

  }

//==========================================

  public void Dimension(Graphics g,

	  Vector2D e0,Vector2D e1,double supl,

	  int mode,String title)

//==========================================

/*  X0(x0,y0),X1(x1,y1)

	supl > 0 line set is in 90 degree( left turn side)

	supl < 0 -90 degree (right turn side)

	mode

	1 : no arrow

	2 : only on X1 side

	3 : only on X0 side

	4 : both side of X0 and X1

*/

  {

	  Vector2D	de=new Vector2D(e1.Minus(e0)),

				deunit=new Vector2D(de.Unit()),

				sup=new Vector2D((deunit.Rot(90.)).Mult(supl));



	  u_plot(g,e0,3);

	  u_plot(g,e0.Plus(sup),2);

	  u_plot(g,e1,3);

	  u_plot(g,e1.Plus(sup),2);

  	  arrow(g,e0.Plus(sup.Mult(0.5)),e1.Plus(sup.Mult(0.5)),mode);

	return;	

  }

//==========================================

  public void u_rect(Graphics g,

	  Vector2D X0,Vector2D X1)

//==========================================

  {

	  u_rect( g,

		  X0.Get_Elem(0),X0.Get_Elem(1),

		  X1.Get_Elem(0),X1.Get_Elem(1));

  }

//==========================================

  public void u_rect(Graphics g,

	  double x0,double y0, double x1,double y1)

//==========================================

  {

	  u_plot(g,x0,y0,3);u_plot(g,x0,y1,2);u_plot(g,x1,y1,2);

	  u_plot(g,x1,y0,2);u_plot(g,x0,y0,2);

  }

//==========================================

  public void f_rect(Graphics g,

	  Vector2D X0,Vector2D X1)

//==========================================

  {

	  f_rect( g,

		  X0.Get_Elem(0),X0.Get_Elem(1),

		  X1.Get_Elem(0),X1.Get_Elem(1));

  }

//==========================================

  public void f_rect(Graphics g,

	  double x0,double y0, double x1,double y1)

//==========================================

  {

	  int xpol[]=new int[4];

	  int ypol[]=new int[4];

	  

	  u_plot(g,x0,y0,3);xpol[0]=(int)ixold;ypol[0]=(int)iyold;

	  u_plot(g,x0,y1,3);xpol[1]=(int)ixold;ypol[1]=(int)iyold;

	  u_plot(g,x1,y1,3);xpol[2]=(int)ixold;ypol[2]=(int)iyold;

	  u_plot(g,x1,y0,3);xpol[3]=(int)ixold;ypol[3]=(int)iyold;



	  g.fillPolygon(xpol,ypol,4);

  }

//==========================================

  public void lattice( Graphics g ,

	  Vector2D X0,Vector2D X1,

	  double dx,double dy) 

//==========================================

  {

	  lattice(g,X0.Get_Elem(0),X0.Get_Elem(1),

		  X1.Get_Elem(0),X1.Get_Elem(1),dx,dy);

  }

//==========================================

  public void lattice( Graphics g ,double x0,double y0, 

	  double x1,double y1,double dx,double dy) 

//==========================================

  {

	  if(dx<=0.)dx=x1-x0;

	  if(dy<=0.)dy=y1-y0;

	  for(double x=x0;x<=x1;x+=dx)

	  {

		  u_plot(g,x,y0,3);u_plot(g,x,y1,2);

	  }

	  for(double y=y0;y<=y1;y+=dy)

	  {

		  u_plot(g,x0,y,3);u_plot(g,x1,y,2);

	  }

  }

//==========================================

void symbol(Graphics g,Vector2D X,double h,

			String text,double theta,int in)

//==========================================

{

	symbol( g,X.Get_Elem(0),X.Get_Elem(1), h,

			 text, theta, in);

}

//==========================================

void symbol(Graphics g,double x,double y,double h,

			String text,double theta,int in)

//==========================================

{

    double  th,costh,sinth,x0,y0,xx,yy;

    char    ich;

    int     a,i,j,ixy,ipp;



    th=theta*DPAI;

    costh=h*Math.cos(th);

    sinth=h*Math.sin(th);

    for(i=0;i<in;i++)

    {

        x0=x+i*costh;        y0=y+i*sinth;

        u_plot(g,x0,y0,3);

        ich=text.charAt(i);

        j=Ascii_Address[ich];

        a=Symbol_Table[j] ;

		while(j < Ascii_Address[ich+1]-1)

        {

            j++;

			ipp=a%10;   /* ipp=3 Pen up, =2 Pen down */

            ixy=a/10;

            xx=ixy%10/7.0;      yy=1.0-ixy/10/7.0;



            u_plot(g,x0+xx*costh-yy*sinth,y0+xx*sinth+yy*costh,ipp);

            a=Symbol_Table[j];

        }

    }

}

//==========================================

void symbol(Graphics g,double x,double y,

			String text)

//==========================================

{

	u_plot(g,x,y,3);

	g.drawString(text,(int)ixold,(int)iyold);

}

//==========================================

void number(Graphics g,Vector2D X,double h,

			double fpn,double theta,int n)

//==========================================

{

	number( g,X.Get_Elem(0),X.Get_Elem(1), h,

			 fpn, theta, n);

}

//==========================================

void number(Graphics g,double x,double y,double h,

			double fpn,double theta,int n)

//==========================================

{

	char   idigi[]=new char[20];

    int    s,id,i,num,l,ianum;

    double abfpn,sum;

	id=0;



    abfpn=Math.abs(fpn);

    if(abfpn == 0.0)

        l=0;

    else

    	l=(int)(Math.log(abfpn)/Math.log(10.0));



    if(fpn < 0.0)

    {

        idigi[id]='-';

		id++;

    }



    if(n < 0)	s=1;

    else		s=0;

    sum=0.0;

//	boolean underzero=false;

    for(i=l+s;i>=(-n);i--)

    {

		ianum=(int)((abfpn-sum)/Math.pow(10.0,(double)(i-s)));

		num=ianum%10;

		sum=sum+num*Math.pow(10.0,(double)i);

		idigi[id]=Character.forDigit(num,10);

		id++;

//		if(i == 0 || (i<0 && !underzero))

		if(i == 0 )

		{

			idigi[id]='.';

			id++;

//			underzero=true;

        }

    }

	String st0=new String(idigi);

	symbol(g,x,y,h,st0,theta,id);

}

//==========================================

void number(Graphics g,double x,double y,double fpn,int n)

//==========================================

{

	u_plot(g,x,y,3);

	Double fdummy=

		new Double(Math.rint(fpn*Math.pow(10.,n))/Math.pow(10.,n));

	g.drawString(fdummy.toString(),(int)ixold,(int)iyold);

}

//==========================================

void axis(Graphics g,

		  double x0,double y0,double d,double t,

		  double theta,String title,

		  int n,int m,int md,double sm,double smd)

//==========================================

{

    double  costh,sinth;

    int     i,mold,jsep;

    double  direc,dx,

		scosth,ssinth,

	    dcosth,dsinth,

	    x,y,xx,yy,xxx,yyy,

	    fpn              ;

    costh=Math.cos(theta*DPAI);

    sinth=Math.sin(theta*DPAI);



    u_plot(g,x0,y0,3);



    direc=d*0.3;

    dx=Math.abs(d);

    jsep=(int)((t+0.00001)/dx+1);

    scosth=dx*costh;

    ssinth=dx*sinth;

    dcosth=direc*Math.cos((theta+90.0)*DPAI);

    dsinth=direc*Math.sin((theta+90.0)*DPAI);



    for(i=1;i<=jsep;i++)

	{

		x=(i-1)*scosth+x0;

		y=(i-1)*ssinth+y0;

		u_plot(g,x,y,2);

        u_plot(g,x+dcosth,y+dsinth,2);

        u_plot(g,x,y,3);

    }



/* Draw Number */

    yyy=ch2*(-0.5-d/Math.abs(d));

    for(i=1;i<=jsep;i+=md)

    {

		xxx=(i-1)*dx-ch2;

		if((m-1)*dx+xxx>t)break;

        fpn=sm+smd*(double)((i-1)/md);

		number(g,x0+(m-1)*scosth+xxx*costh-yyy*sinth,

	       y0+(m-1)*ssinth+xxx*sinth+yyy*costh,ch2,fpn,theta,1);

	}



/* Draw Title */

    xx=t*0.5-ch1*0.5*n;

    yy=ch1*(-0.5-d/Math.abs(d)*(1.+ch2/ch1));

    symbol(g,x0+xx*costh-yy*sinth,y0+xx*sinth+yy*costh,

           ch1,title,theta,n);

}

//==========================================

void lgaxis(Graphics g,

			double x0,double y0,double t,double theta,

			int isep,String title,int n,int m)

//==========================================

{

    int    i,j,mold,jsep;

    double  th,costh,sinth,

            dx,direc,

		    scosth,ssinth,dsinth,dcosth,

		    x,y,xx,yy,vx,vy;



    th=theta*DPAI;

    costh=Math.cos(th);

    sinth=Math.sin(th);



    u_plot(g,x0,y0,3);



    jsep=Math.abs(isep);

    dx=t/(double)jsep;

    scosth=dx*costh;

    ssinth=dx*sinth;

    direc=dx*0.05*(double)(isep/jsep);

    dcosth=direc*Math.cos((theta+90.0)*DPAI);

    dsinth=direc*Math.sin((theta+90.0)*DPAI);



    for(i=1;i<=jsep;i++)

    {

        for(j=1;j<=10;j++)

	    {

			x=((double)(i-1)+Math.log((double)j)/Math.log(10.))*scosth+x0;

    	    y=((double)(i-1)+Math.log((double)j)/Math.log(10.))*ssinth+y0;



			u_plot(g,x,y,2);



			u_plot(g,x+dcosth,y+dsinth,2);

      	    u_plot(g,x,y,3);

	    }

    }

/* Draw Ttile */



    xx=t*0.5-ch1*0.5*n;

    yy=ch1*(-0.5-(double)(isep/jsep)*2.0);

    symbol(g,x0+xx*costh-yy*sinth,y0+xx*sinth+yy*costh,

           ch1,title,theta,n);



/* Draw 10 and Power */



    vy=ch1*(-0.5-(double)(isep/jsep)*0.8);

    vx=-1.5*ch1;

    for(i=1;i<=jsep+1;i++)

	{

        if(m+i-1>=-9 && m+i-1<=99)

	    {

/* 10(Height of character :ch1) */

            xx=dx*(i-1)+vx;

			yy=vy;

			symbol(g,x0+costh*xx-sinth*yy,

				y0+sinth*xx+costh*yy,

				ch1,"10",theta,2);

			/* Power(Height of character :ch2) */

            xx=xx+1.8*ch1;

			yy=yy+0.6*ch1;

			number(g,x0+costh*xx-sinth*yy,

				y0+sinth*xx+costh*yy,

				ch2,(double)(m+i-1),theta,-1);

        }

	}

}

//==========================================

void lline(Graphics g,

		   Vector2D xp,

		   Vector2D[] x,

		   int nn,int isym)

//==========================================

{

    int     n , i ,ip ;

    double  x0 , y0 , dx , dy ;

    n = Math.abs(nn);

    x0 = x[n+1].Get_Elem(0) ;

    y0 = x[n+1].Get_Elem(1) ;

    dx = 1.0 / x[n+2].Get_Elem(0) ;

    dy = 1.0 / x[n+2].Get_Elem(1) ;

    u_plot(g,(x[0].Get_Elem(0)-x0)*dx+xp.Get_Elem(0) ,

		(x[0].Get_Elem(1)-y0)*dy+xp.Get_Elem(1) , 3) ;

    if(isym>0 && isym<15)

    {

        marker(g,(x[1].Get_Elem(0)-x0)*dx+xp.Get_Elem(0),

			(x[1].Get_Elem(1)-y0)*dy+xp.Get_Elem(1),isym) ;

	}



    if(nn < 0)	ip=3;

    else        ip=2;



    for (i=0 ; i<n ; i++)

    {

		u_plot(g,(x[i].Get_Elem(0)-x0)*dx+xp.Get_Elem(0) ,

			(x[i].Get_Elem(1)-y0)*dy+xp.Get_Elem(1) , ip) ;

        if (isym>0 && isym<=15)

        {

			marker(g,(x[i].Get_Elem(0)-x0)*dx+xp.Get_Elem(0),

				(x[i].Get_Elem(1)-y0)*dy+xp.Get_Elem(1),isym) ;

        }

     }

}

//==========================================

void lline(Graphics g,

		   Vector2D xp,

		   Vector2D[] x,Vector2D X0,Vector2D Dx,

		   int nn,int isym)

//==========================================

{

    int     n , i ,ip ;

    double  x0 , y0 , dx , dy ;

    n = Math.abs(nn);

    x0 = X0.Get_Elem(0) ;

    y0 = X0.Get_Elem(1) ;

    dx = 1.0 / Dx.Get_Elem(0) ;

    dy = 1.0 / Dx.Get_Elem(1) ;

    u_plot(g,(x[0].Get_Elem(0)-x0)*dx+xp.Get_Elem(0) ,

		(x[0].Get_Elem(1)-y0)*dy+xp.Get_Elem(1) , 3) ;

    if(isym>0 && isym<15)

    {

        marker(g,(x[1].Get_Elem(0)-x0)*dx+xp.Get_Elem(0),

			(x[1].Get_Elem(1)-y0)*dy+xp.Get_Elem(1),isym) ;

	}



    if(nn < 0)	ip=3;

    else        ip=2;



    for (i=0 ; i<n ; i++)

    {

		u_plot(g,(x[i].Get_Elem(0)-x0)*dx+xp.Get_Elem(0) ,

			(x[i].Get_Elem(1)-y0)*dy+xp.Get_Elem(1) , ip) ;

        if (isym>0 && isym<=15)

        {

			marker(g,(x[i].Get_Elem(0)-x0)*dx+xp.Get_Elem(0),

				(x[i].Get_Elem(1)-y0)*dy+xp.Get_Elem(1),isym) ;

        }

     }

}

//==========================================

void lline(Graphics g,

		   double xp,double yp,

		   double[] x,double[] y,

		   int nn,int isym)

//==========================================

{

    int     n , i ,ip ;

    double  x0 , y0 , dx , dy ;

    n = Math.abs(nn);

    x0 = x[n+1] ;

    y0 = y[n+1] ;

    dx = 1.0 / x[n+2] ;

    dy = 1.0 / y[n+2] ;

    u_plot(g,(x[0]-x0)*dx+xp , (y[0]-y0)*dy+yp , 3) ;

    if(isym>0 && isym<15)

    {

        marker(g,(x[1]-x0)*dx+xp,(y[1]-y0)*dy+yp,isym) ;

	}



    if(nn < 0)	ip=3;

    else        ip=2;



    for (i=0 ; i<n ; i++)

    {

        u_plot(g,(x[i]-x0)*dx+xp , (y[i]-y0)*dy+yp , ip) ;

        if (isym>0 && isym<=15)

        {

            marker(g,(x[i]-x0)*dx+xp,(y[i]-y0)*dy+yp,isym) ;

        }

     }

}

//==========================================

void lgline(Graphics g,

			double	xp ,double	 yp ,

			double[] x ,double[] y ,

			int nn ,int ils ,int isym)

//==========================================

{

int     n , i ,ip;

double  x0 , y0 , dx , dy , xc , yc ;



	n = Math.abs(nn);

	x0 = x[n+1] ;y0 = y[n+1] ;

	dx = x[n+2] ;dy = y[n+2] ;

	xc = x[0] ;

	if (ils == 1 || ils == 2)

	    xc = Math.log(x[0])/Math.log(10.) ;

	yc = y[0] ;

	if (ils == 1 || ils == 3)

	    yc = Math.log(y[0])/Math.log(10.) ;

		u_plot(g,(xc-x0)*dx+xp , (yc-y0)*dy+yp , 3) ;

//	if (isym>0 && isym<15)

	    marker(g,(xc-x0)*dx+xp,(yc-y0)*dy+yp,isym) ;



	if (nn<0)   ip = 3 ;

	else	    ip = 2 ;



	for (i=0 ; i<n ; i++){

	    xc = x[i] ;

	    if (ils == 1 || ils == 2)

	        xc = Math.log(x[i])/Math.log(10.) ;

	    yc = y[i] ;

	    if (ils == 1 || ils == 3)

	        yc = Math.log(y[i])/Math.log(10.) ;

		u_plot(g,(xc-x0)*dx+xp , (yc-y0)*dy+yp , ip) ;

//	    if (isym>0 && isym<15)

	        marker(g,(xc-x0)*dx+xp,(yc-y0)*dy+yp,isym) ;

	    }

	}

//==========================================

void scale(double[] x,int n,double dx)

//==========================================

{

    int    i;

    double  xmin,jpow;



    xmin=x[1];

    for(i=2;i<=n;i++)

    {

		if(x[i]<xmin)    xmin=x[i];

    }

    jpow=xmin/10.0;

    if(xmin<0.0)	jpow=jpow-1;



    x[n+1]=jpow*10;

    x[n+2]=dx;

}

//==========================================

void lgscal(double[] x,int n,double dx)

//==========================================

{

    int     i;

    double  xmin,jpow;



    xmin=x[1];

    for(i=2;i<=n;i++)

    {

		if(x[i]<xmin)    xmin=x[i];

    }

    jpow=Math.log(xmin)/Math.log(10.);

    x[n+1]=jpow;

    x[n+2]=dx;

}

//==========================================

void marker(Graphics g,Vector2D X,int n)

//==========================================

{

	marker( g,X.Get_Elem(0),X.Get_Elem(1), n);

}

//==========================================

void marker(Graphics g,double x,double y,int n)

//==========================================

{

    double theta,rx,ry;

	int ix,iy,hi;

	u_plot(g,x-ch2/2,y-ch2/2,3);

	ix=(int)ixold;iy=(int)iyold;

	u_plot(g,x,y,3);

	hi=2*((int)ixold-ix);

    switch(n)

    {

        case 0:

			break;

		case 1:

			g.drawRect(ix,iy-hi,hi,hi);

			break;

		case 2:

			g.drawOval(ix,iy-hi,hi,hi);

			break;

//		case 3:

//			u_plot(g,x,y+ch2*(Math.sin(Math.PI/3.))*2/3,3);

//			u_plot(g,x-ch2/2,y-ch2*(Math.sin(Math.PI/3.))*1/3,2);

//			u_plot(g,x+ch2/2,y-ch2*(Math.sin(Math.PI/3.))*1/3,2);

//			u_plot(g,x,y+ch2*(Math.sin(Math.PI/3.))*2/3,2);

//			break;

		case 4:

			g.fillRect(ix,iy-hi,hi,hi);

            break;

		case 5:

			g.fillOval(ix,iy-hi,hi,hi);

			break;

		case 6:

		{

			int xPoints[]={(int)ixold,(int)ixold-hi/2,(int)ixold+hi/2};

			int yPoints[]={(int)iyold,(int)iyold+hi  ,(int)iyold+hi};

			g.fillPolygon(xPoints,yPoints,3);

			

		}



    }

    u_plot(g,x,y,3);

}

//==========================================

  public void SectionPaper( Graphics g ,Vector2D X0, 

	  Vector2D X1) 

//==========================================

  {

	  SectionPaper(  g ,  X0.Get_Elem(0),X0.Get_Elem(1),

	   X1.Get_Elem(0),X1.Get_Elem(1), 1., 1.,

	   1, 10) ;

  }

//==========================================

  public void SectionPaper( Graphics g ,Vector2D X0, 

	  Vector2D X1,double dx,double dy) 

//==========================================

  {

	  SectionPaper(  g ,  X0,  X1, dx, dy,

	   1, 10) ;

  }

//==========================================

  public void SectionPaper( Graphics g ,Vector2D X0, 

	  Vector2D X1,double dx,double dy,

	  int pitch0,int pitch1) 

//==========================================

  {

	  SectionPaper(  g ,  X0,  X1, dx, dy,

	   pitch0,pitch1,pitch0,pitch1) ;

  }

//==========================================

  public void SectionPaper( Graphics g ,Vector2D X0, 

	  Vector2D X1,double dx,double dy,

	  int pitch0x,int pitch1x,int pitch0y,int pitch1y) 

//==========================================

  {

	  SectionPaper(  g ,  X0.Get_Elem(0),X0.Get_Elem(1),

	   X1.Get_Elem(0),X1.Get_Elem(1), dx, dy,

	   pitch0x,pitch1x,pitch0y,pitch1y) ;

  }

//==========================================

  public void SectionPaper( Graphics g ,double x0,double y0, 

	  double x1,double y1,double dx,double dy,

	  int pitch0,int pitch1) 

//==========================================

  {

	  SectionPaper(  g , x0, y0, 

	   x1, y1, dx, dy,

	   pitch0, pitch1, pitch0, pitch1) ;

  }

//==========================================

  public void SectionPaper( Graphics g ,double x0,double y0, 

	  double x1,double y1,double dx,double dy,

	  int pitch0x,int pitch1x,int pitch0y,int pitch1y) 

//==========================================

  {

	  g.setColor(Color.white);

	  f_rect(g,x0,y0,x1,y1); 

	  g.setColor(Color.lightGray);

	  lattice(g,x0,y0,x1,y1,dx*pitch0x,dy*pitch0y);

	  g.setColor(Color.darkGray);

	  lattice(g,x0,y0,x1,y1,dx*pitch1x,dy*pitch1y);

	  u_rect(g,x0,y0,x1,y1);

	  g.setColor(Color.black);



  }

//==========================================

  void lgSectionPaper(Graphics g,Vector2D X0,

	  Vector2D X1)

//==========================================

// ils:	1:log-log,2:log-linear,3:linear-log

// idraw: 3:Draw x,y	1:Draw x	,2:Draw y 

  {

	  lgSectionPaper( g, X0.Get_Elem(0),X0.Get_Elem(1),

	   X1.Get_Elem(0),X1.Get_Elem(1), 1.0, 1.0,

	   1,  1);

  }

//==========================================

  void lgSectionPaper(Graphics g,Vector2D X0,

	  Vector2D X1,double widunit,double heiunit,

	  int ils, int idraw)

//==========================================

// ils:	1:log-log,2:log-linear,3:linear-log

// idraw: 3:Draw x,y	1:Draw x	,2:Draw y 

  {

	  lgSectionPaper( g,X0,X1,widunit,heiunit,

	  ils, idraw,1,0,1,0);

  }

//==========================================

  void lgSectionPaper(Graphics g,Vector2D X0,

	  Vector2D X1,double widunit,double heiunit,

	  int ils, int idraw,

	  int ix0,int ix1,int iy0,int iy1)

//==========================================

// ils:	1:log-log,2:log-linear,3:linear-log

// idraw: 3:Draw x,y	1:Draw x	,2:Draw y 

  {

	  lgSectionPaper( g, X0.Get_Elem(0),X0.Get_Elem(1),

	   X1.Get_Elem(0),X1.Get_Elem(1), widunit, heiunit,

	   ils,  idraw,ix0,ix1,iy0,iy1);

  }

//==========================================

  void lgSectionPaper(Graphics g,double x0,double y0,

	  double x1,double y1,double widunit,double heiunit,

	  int ils, int idraw)

//==========================================

// ils:	3:log-log,1:log-linear,2:linear-log

// idraw: 3:Draw x,y	1:Draw x	,2:Draw y 

 {

	  lgSectionPaper(g,x0,y0,

	  x1,y1,widunit,heiunit,

	  ils, idraw,1,0,1,0);

  }

//==========================================

  void lgSectionPaper(Graphics g,double x0,double y0,

	  double x1,double y1,double widunit,double heiunit,

	  int ils, int idraw,

	  int ix0,int ix1,int iy0,int iy1)

//==========================================

// ils:	3:log-log,1:log-linear,2:linear-log

// idraw: 3:Draw x,y	1:Draw x	,2:Draw y 

{

	double xb,yb,dx=widunit,dy=heiunit;

	double xbase,ybase;



	g.setColor(Color.white);

	f_rect(g,x0,y0,x1,y1);

	if(idraw%2 == 1)

	{

		if(ils%2 == 1)

		{

			g.setColor(Color.lightGray);

			for(int i=0;i<(int)((x1-x0)/widunit);i++)

			{

				xbase=x0+i*widunit;

				u_plot(g,xbase,y0,3);

				for(int j=2;j<=9;j++)

				{

					xb=xbase+Math.log((double)j)/

						Math.log(10.)*widunit;

					if(j==1||j==10)

						g.setColor(Color.darkGray);

					else

						g.setColor(Color.lightGray);

					u_plot(g,xb,y0,3);u_plot(g,xb,y1,2);

				}

			}

		}

		else

		{

			if(ix0>0)

			{

				g.setColor(Color.lightGray);

				for(double x=x0;x<=x1;x+=dx*ix0)

				{

					u_plot(g,x,y0,3);u_plot(g,x,y1,2);

				}

			}

			if(ix1>0)

			{

				g.setColor(Color.darkGray);

				for(double x=x0;x<=x1;x+=dx*ix1)

				{

					u_plot(g,x,y0,3);u_plot(g,x,y1,2);

				}

			}

		}

	}



	if((idraw>>1)%2 ==1)

	{

		if((ils>>1)%2 == 1)

		{ 

			for(int i=0;i<(int)((y1-y0)/heiunit);i++)

			{

				ybase=y0+i*heiunit;

				u_plot(g,x0,ybase,3);

				for(int j=1;j<=10;j++)

				{

					yb=ybase+Math.log((double)j)/

						Math.log(10.)*heiunit;

					if(j==1||j==10)

						g.setColor(Color.darkGray);

					else 

						g.setColor(Color.lightGray);

					u_plot(g,x0,yb,3);u_plot(g,x1,yb,2);

				}

			}

		}

		else

		{

			if(iy0>0)

			{

				g.setColor(Color.lightGray);

				for(double y=y0;y<=y1;y+=dy*iy0)

				{

					u_plot(g,x0,y,3);u_plot(g,x1,y,2);

				}

			}

			if(iy1>0)

			{

				g.setColor(Color.darkGray);

				for(double y=y0;y<=y1;y+=dy*iy1)

				{

					u_plot(g,x0,y,3);u_plot(g,x1,y,2);

				}

			}

		}



	}

	if(idraw%2==1)

	{

		if(ils%2 == 1)

		{

			g.setColor(Color.darkGray);

			for(int i=0;i<(int)((x1-x0)/widunit);i++)

			{

				xbase=x0+i*widunit;

				u_plot(g,xbase,y0,3);

				for(int j=1;j<=10;j+=9)

				{

					xb=xbase+Math.log(

						(double)j)/Math.log(10.

						)*widunit;

					u_plot(g,xb,y0,3);u_plot(g,xb,y1,2);

				}

			}

		}

		else

		{

			if(ix1>0)

			{

				g.setColor(Color.darkGray);

				for(double x=x0;x<=x1;x+=dx*ix1)

				{

					u_plot(g,x,y0,3);u_plot(g,x,y1,2);

				}

			}

		}



	}

	g.setColor(Color.darkGray);

	u_rect(g,x0,y0,x1,y1);



  }

//==========================================	

void Poly2DPaint(Graphics g,Color Ucolor,

				 Vector2D[] v,int n)

//==========================================	

{

	int xPoints[]=new int[n],

		yPoints[]=new int[n];

	if( n<=0)return;



	for(int i=0;i<n;i++)

	{

		u_plot(g,v[i],3);

		xPoints[i]=(short)ixold;

		yPoints[i]=(short)iyold;

	}

	g.setColor(Ucolor);

	g.fillPolygon(xPoints,yPoints,n);

}

//==========================================

}











//******************************************
public class Fig019 extends Engineer implements Runnable
//******************************************
{	
	  
	  Scrollbar mb_number;	  Label mb_title;
	  Scrollbar f_number;	  Label f_title;
	  Scrollbar Xi_number;	  Label Xi_title;
	  Scrollbar n_number;	  Label n_title;
          
	  
	  
	  Thread animator;
	  boolean please_stop;
	  Image offscreen;
	  int imagewidth,imageheight;
	  double Timestep=0.;
	  double dTimestep;
	  
//========================================== 
  public void init()
//==========================================
  {
	setLayout( null );

    mb_title = new Label( "Mass Ratio (mb)" );
    mb_title.reshape(  50, 520, 120, 20 );
    add( mb_title );
    mb_number = new Scrollbar( Scrollbar.HORIZONTAL, 50, 0, 0, 100 );
    mb_number.setPageIncrement( 2 );
    mb_number.reshape(  50, 540, 150, 20 );    
    add( mb_number );

    f_title = new Label( "Frequency (f)" );
    f_title.reshape(  50, 560, 120, 20 );
    add( f_title );
    f_number = new Scrollbar( Scrollbar.HORIZONTAL, 50, 0, 0, 100 );
    f_number.setPageIncrement( 2 );
    f_number.reshape(  50, 580, 150, 20 );
    add( f_number );

    Xi_title = new Label( "Damping (Xi)" );
    Xi_title.reshape(  350, 520, 120, 20 );
    add( Xi_title );
    Xi_number = new Scrollbar( Scrollbar.HORIZONTAL, 50, 0, 0, 100 );
    Xi_number.setPageIncrement( 2 );
    Xi_number.reshape(  350, 540, 150, 20 );
    add( Xi_number );
    
    
     
    n_title = new Label( "Omega" );
    n_title.reshape(  350,560, 120, 20 );
    add( n_title );
    n_number = new Scrollbar( Scrollbar.HORIZONTAL, 50, 0, 0, 100 );
    n_number.setPageIncrement( 2 );
    n_number.reshape(  350, 580, 150, 20 );
    add( n_number );
  }

//========================================== 
public  Fig019()
//========================================== 
{
	super(500,500,30.,-5.,-5.5,0,0,300,400);
}


//===========================================
public void start()
//===========================================
	{
		if (animator == null)
		{
			animator = new Thread(this);
			animator.start();
		}
	}

//===========================================	
	public void stop()
//===========================================	
	{
		if (animator != null)
		{
			animator.stop();
			animator = null;
		}
	}



//==========================================
  public boolean handleEvent( Event event )
//==========================================
  {
    if (event.id == Event.SCROLL_ABSOLUTE ||
		event.id == Event.SCROLL_LINE_DOWN ||
        event.id == Event.SCROLL_LINE_UP ||
        event.id == Event.SCROLL_PAGE_DOWN ||
        event.id == Event.SCROLL_PAGE_UP )
	{
          repaint();
          return true;
    }
	return super.handleEvent( event );
  }
//==========================================
  public void paint( Graphics g )
//==========================================
  {
	  double 
		  Rho[]=new double[110],
		  H1[]=new double[110],
		  H3[]=new double[110],
		  H1Xi0[]=new double[110],
		  H1Xi1[]=new double[110],
		  H3Xi0[]=new double[110],
		  H3Xi1[]=new double[110];
	  
	  double mb     = mb_number.getValue()*.004;
	  double f      = f_number.getValue()*.002+.8;
	  double Xi     = Xi_number.getValue()*.002;
	  
	   
	 // double n     = n_number.getValue()*.018+.2;
	  //dTimestep = n; 
	  double H1peak,Rhopeak;
	  double Rhopeak1,H3peak;
         // public static Rhopeak,
	  
	  double Xaxis=20.0,Yaxis=18.;
	  
	  
	  double Xmax=1.2,Xmin=0.8,Ymax=30.0,Ymin=0.;
	  int Maxp=101;
	  double dx=(Xmax-Xmin)/(Maxp-1);

// Draw scale
	  g.setColor(Color.white);
	  f_rect(g,0.,10.,Xaxis,Yaxis+10); 
	  
	  
	  f_rect(g,30.,10.,Xaxis+30,Yaxis+10); 
	  
	  g.setColor(Color.lightGray);
	  lattice(g,0.,10.,Xaxis,Yaxis+10,Xaxis/16.,Yaxis/30.);
	  
	  
	  lattice(g,30.,10.,Xaxis+30,Yaxis+10,Xaxis/16.,Yaxis/30.);
	  
	  g.setColor(Color.gray);
	  lattice(g,0.,10.,Xaxis,Yaxis+10,Xaxis/4.,Yaxis/3.);
	  
	  
	  lattice(g,30.,10.,Xaxis+30,Yaxis+10,Xaxis/4.,Yaxis/3.);
	  
	  g.setColor(Color.black);

// Calculate values
	  for(int i=0;i<Maxp;i++)
	  {
		  Rho[i]=dx*i+Xmin;
		  double RhoSQ=Rho[i]*Rho[i];
		  double a1=f*f-RhoSQ;
		  double a2=Rho[i]*f;
		  double a3=(1.-RhoSQ)*(f*f-RhoSQ)-
			  mb*RhoSQ*f*f;
		  double a4=Rho[i]*f*(1.-RhoSQ*(1.+mb));

		  H1[i]=Math.sqrt((a1*a1+4.*Xi*Xi*a2*a2)/
			  (a3*a3+4.*Xi*Xi*a4*a4));
		  H3[i]=Math.sqrt(Rho[i]/  
			  (a3*a3+4.*Xi*Xi*a4*a4));
		
		        double X0i = 0.;  		
		  H1Xi0[i]=Math.sqrt((a1*a1+4.*X0i*X0i*a2*a2)/
			  (a3*a3+4.*X0i*X0i*a4*a4));
		  H3Xi0[i]=Math.sqrt(Rho[i]/  
			  (a3*a3+4.*X0i*X0i*a4*a4));
			  
			double X1i = 1.;  
		  H1Xi1[i]=Math.sqrt((a1*a1+4.*X1i*X1i*a2*a2)/
			  (a3*a3+4.*X1i*X1i*a4*a4));
		  H3Xi1[i]=Math.sqrt(Rho[i]/  
			  (a3*a3+4.*X1i*X1i*a4*a4)); 
			  
		  if(H1[i]>Ymax)H1[i]=Ymax;
		  if(H3[i]>Ymax)H3[i]=Ymax;
		  if(H1Xi0[i]>Ymax)H1Xi0[i]=Ymax;
		  if(H1Xi1[i]>Ymax)H1Xi1[i]=Ymax;
		  if(H3Xi0[i]>Ymax)H3Xi0[i]=Ymax;
		  if(H3Xi1[i]>Ymax)H3Xi1[i]=Ymax;
	  }

// Set user's coordinate parameters
	  Rho[Maxp+1]=Xmin;Rho[Maxp+2]=(Xmax-Xmin)/Xaxis;
	  H1[Maxp+1]=Ymin; H1[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  H3[Maxp+1]=Ymin; H3[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  H1Xi0[Maxp+1]=Ymin; H1Xi0[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  H3Xi0[Maxp+1]=Ymin; H3Xi0[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  H1Xi1[Maxp+1]=Ymin; H1Xi1[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  H3Xi1[Maxp+1]=Ymin; H3Xi1[Maxp+2]=(Ymax-Ymin)/Yaxis;

// Peak point for h1
	  g.setColor(Color.blue);
	  double Xpeak,Ypeak;
	  H1peak=H1[0];Rhopeak=Rho[0];
	  for(int i=1;i<Maxp;i++)
	  {
		  if(H1[i]>H1peak)
		  {
			  Rhopeak=Rho[i];H1peak=H1[i];
		  }
		  else break;
	  }
	  Xpeak=(Rhopeak-Rho[Maxp+1])/Rho[Maxp+2]+0.;
	  Ypeak=(H1peak-H1[Maxp+1])/H1[Maxp+2]+0.;
	  number(g,Xpeak,Ypeak+10,Rhopeak,2);
	  symbol(g,Xpeak+2.,Ypeak+10,",");
	  number(g,Xpeak+2.5,Ypeak+10,H1peak,2);
	  
	  marker(g,Xpeak,Ypeak+10,2);

	  
	  H1peak=H1[Maxp];Rhopeak=Rho[Maxp];
	  for(int i=Maxp-1;i>0;i--)
	  {
		  if(H1[i]>H1peak)
		  {
			  Rhopeak=Rho[i];H1peak=H1[i];
		  }
		  else break;
	  }
	  Xpeak=(Rhopeak-Rho[Maxp+1])/Rho[Maxp+2]+0.;
	  Ypeak=(H1peak-H1[Maxp+1])/H1[Maxp+2]+0.;
	  number(g,Xpeak,Ypeak+10,Rhopeak,2);
	  symbol(g,Xpeak+2.,Ypeak+10,",");
	  number(g,Xpeak+3.5,Ypeak+10,H1peak,2);
	  marker(g,Xpeak,Ypeak+10,2);
          double n     = (n_number.getValue()*.018+0.2);
          
          dTimestep = n*H1peak;
          
         
// Peak point for h3
	  g.setColor(Color.blue);
	  double Xpeak1,Ypeak1;
	  H3peak=H3[0];Rhopeak1=Rho[0];
	  for(int i=1;i<Maxp;i++)
	  {
		  if(H3[i]>H3peak)
		  {
			  Rhopeak1=Rho[i];H3peak=H3[i];
		  }
		  else break;
	  }
	  Xpeak1=(Rhopeak1-Rho[Maxp+1])/Rho[Maxp+2]+0.;
	  Ypeak1=(H3peak-H3[Maxp+1])/H3[Maxp+2]+0.;
	  number(g,Xpeak1+30,Ypeak1+10,Rhopeak1,2);
	  symbol(g,Xpeak1+32.,Ypeak1+10,",");
	  number(g,Xpeak1+33.5,Ypeak1+10,H3peak,2);
	  marker(g,Xpeak1+30,Ypeak1+10,2);

	  
	  H3peak=H3[Maxp];Rhopeak1=Rho[Maxp];
	  for(int i=Maxp-1;i>0;i--)
	  {
		  if(H3[i]>H3peak)
		  {
			  Rhopeak1=Rho[i];H3peak=H3[i];
		  }
		  else break;
	  }
	  Xpeak1=(Rhopeak1-Rho[Maxp+1])/Rho[Maxp+2]+0.;
	  Ypeak1=(H3peak-H3[Maxp+1])/H3[Maxp+2]+0.;
	  number(g,Xpeak1+30,Ypeak1+10,Rhopeak1,2);
	  symbol(g,Xpeak1+32.,Ypeak1+10,",");
	  number(g,Xpeak1+32.5,Ypeak1+10,H3peak,2);
	  marker(g,Xpeak1+30,Ypeak1+10,2);



//Draw line
	  g.setColor(Color.blue);
	  lline(g,0.,10.,Rho,H1,Maxp,0);
	  
	  g.setColor(Color.blue);
	  lline(g,30.,10.,Rho,H3,Maxp,0);
	  
	  g.setColor(Color.red);
	  lline(g,0.,10.,Rho,H1Xi0,Maxp,0);
	  lline(g,30.,10.,Rho,H3Xi0,Maxp,0);
	  
	  g.setColor((Color.yellow).darker());	  
	  lline(g,0.,10.,Rho,H1Xi1,Maxp,0);
	  lline(g,30.,10.,Rho,H3Xi1,Maxp,0);		
// Draw out frame
	  g.setColor(Color.black);
	  u_rect(g,0.,10.,Xaxis,Yaxis+10); 
		  
	  u_rect(g,30.,10.,Xaxis+30,Yaxis+10);
	  
	  u_rect(g,0.,-12.,Xaxis,Yaxis-12);
	  //u_rect(g,30.,-12.,Xaxis+30,Yaxis-12);
// Draw Axis
	  axis(g,0.,10., Xaxis/16.,Xaxis, 0.,"Rho",3,1,4,Xmin,.1);
	  axis(g,0.,10.,-Yaxis/30.,Yaxis,90.,"H1" ,2,1,10,Ymin,10.);
		
	  axis(g,30.,10., Xaxis/16.,Xaxis, 0.,"Rho",3,1,4,Xmin,.1);
	  axis(g,30.,10.,-Yaxis/30.,Yaxis,90.,"H3" ,2,1,10,Ymin,10.);	
		
// Draw mb,f,Xi,n
	  g.setColor(Color.red);
	  //symbol(g,-ch1*(0.5*(0.7+ch2/ch1)),Yaxis*.6,ch1,"H3",90.,2);
	  number(g,Xaxis*+0.8,-21,mb,4);
	  number(g,Xaxis*+0.8,-25,f,4);
	  number(g,Xaxis*+2.3,-21,Xi,4);
	  number(g,Xaxis*+2.3,-25,n,4);
	  
// draw the model
	  drawFig(g);	  
	  
  }

//===========================================  
  public void run()
//===========================================  
  {
		
	  while(!please_stop)
	  {
		  Dimension d=this.size();
		  if((offscreen!=null)||
			  ((imagewidth!=d.width)||(imageheight!=d.height)))
		  {
			  offscreen=this.createImage(d.width,d.height);
			  imagewidth=d.width;
			  imageheight=d.height;
		  }

	
		  Graphics g=offscreen.getGraphics();
		  paint(g);
		  g=this.getGraphics();
		  g.drawImage(offscreen,0,0,this);

		  try 
		  {
		  	Thread.sleep(00);
		  }	
		  
		  catch(InterruptedException e){};
	  }
	  animator=null;
         
  }
  
  //==========================================
  public void dashpot( Graphics g ,double x0,double y0,
	  double x1,double y1)
//==========================================
  {
	  Vector2D X0=new Vector2D(x0,y0),
		  DX=new Vector2D(x1-x0,y1-y0),
		  DY=new Vector2D(DX.Rot(90.));

	  u_plot(g,X0,3);
	  u_plot(g,X0.Plus(DX.Mult(.45)),2);
	  u_plot(g,(X0.Plus(DX.Mult(.45))).Plus(DY.Mult(0.075)),2);
	  u_plot(g,(X0.Plus(DX.Mult(.45))).Minus(DY.Mult(0.075)),2);
	  u_plot(g,X0.Plus(DX),3);
	  u_plot(g,X0.Plus(DX.Mult(.55)),2);
	  u_plot(g,(X0.Plus(DX.Mult(.55))).Plus(DY.Mult(0.09)),2);
	  u_plot(g,(X0.Plus(DX.Mult(.4))).Plus(DY.Mult(0.09)),2);

	  u_plot(g,X0.Plus(DX.Mult(.55)),3);
	  u_plot(g,(X0.Plus(DX.Mult(.55))).Minus(DY.Mult(0.09)),2);
	  u_plot(g,(X0.Plus(DX.Mult(.4))).Minus(DY.Mult(0.09)),2);	
  }
//==========================================
  public void spring( Graphics g ,double x0,double y0,
	  double x1,double y1)
//==========================================
  {
	  Vector2D X0=new Vector2D(x0,y0),
		  DX=new Vector2D(x1-x0,y1-y0),
		  DY=new Vector2D(DX.Rot(90.));
	  u_plot(g,X0,3);
	  u_plot(g,X0.Plus(DX.Mult(.1)),2);
	  for(double a=.1;a<.8;a+=.1)
	  {
		  u_plot(g,(X0.Plus(DX.Mult(a+.025))).Plus(DY.Mult(0.1)),2);
		  u_plot(g,(X0.Plus(DX.Mult(a+.075))).Minus(DY.Mult(0.1)),2);
	  }
	  u_plot(g,X0.Plus(DX.Mult(.9)),2);
	  u_plot(g,X0.Plus(DX),2);

  }


//==========================================
  public void drawFig( Graphics g )
//==========================================
  {
      
	  double phase=Timestep*Math.PI/8;
	  double xm=6.+Math.cos(phase);
	  double xmd=18.+Math.sin(phase);
	  double graphx0=0.,graphy0=12.,graphx1=30.,graphy1=30.;
	  double 
		  X[]=new double[110],
		  Y0[]=new double[110],
		  Y1[]=new double[110];

	  //double Xaxis=graphx1-graphx0,Yaxis=graphy1-graphy0;
	  double Xaxis=20,Yaxis=18;
	  double Xmax=2.*Math.PI,Xmin=0.,Ymax=1.0,Ymin=-1.;
	  int Maxp=101;
	  double dx=(Xmax-Xmin)/(Maxp-1);

// Draw scale
	  g.setColor(Color.white);
	  f_rect(g,0.,-12,Xaxis,Yaxis-12); 
	  g.setColor(Color.lightGray);
	  lattice(g,0.,-12,Xaxis,Yaxis-12,Xaxis/20.,Yaxis/20.);
	  g.setColor(Color.gray);
	  lattice(g,0.,-12,Xaxis,Yaxis-12,Xaxis/4.,Yaxis/2.);
	  g.setColor(Color.black);


  	  for(int i=0;i<Maxp;i++)
	  {
		  X[i]=dx*i+Xmin;
		  Y0[i]=Math.sin(X[i]+Timestep);
		  Y1[i]=Math.cos(X[i]+Timestep);
	  }

// Set user's coordinate parameters
	  X[Maxp+1]=Xmin;X[Maxp+2]=(Xmax-Xmin)/Xaxis;
	  Y0[Maxp+1]=Ymin; Y0[Maxp+2]=(Ymax-Ymin)/Yaxis;
	  Y1[Maxp+1]=Ymin; Y1[Maxp+2]=(Ymax-Ymin)/Yaxis;

//Draw line
	  g.setColor(Color.black);
	  lline(g,0.,-12,X,Y0,Maxp,0);
	  g.setColor(Color.red);
	  lline(g,0.,-12,X,Y1,Maxp,0);

// Draw out frame
	  g.setColor(Color.black);
	  u_rect(g,0.,-12,Xaxis,Yaxis-12); 




// Base
	g.setColor((Color.yellow).darker());
	f_rect(g,30,-12,31,Yaxis-12);
// m
	g.setColor((Color.red).darker());
	f_rect(g,30+xm,-8.,xm+34.,Yaxis-15);
// md
	f_rect(g,30+xmd,-8,xmd+34.,Yaxis-15);

// Dash pot
	g.setColor(Color.black);
	dashpot(g,xm+34.,-7,xmd+30,-7);

// Spring
	spring(g,31.,Yaxis-20,30+xm,Yaxis-20);
	spring(g,xm+34.,Yaxis-19,30+xmd,Yaxis-19);
// Arrows 
	g.setColor(Color.red);
	u_plot(g,xm+32.,Yaxis-15,3);
	u_plot(g,xm+32.,Yaxis-14,2);
	arrow(g,xm+32.,Yaxis-14,xm+37.,Yaxis-14,2);

	g.setColor(Color.blue);
	//u_plot(g,31.,-10,3);
	//u_plot(g,31.,-12.,2);
	//arrow(g,31.,-11.,35.,-11.,2);
	u_plot(g,xm+34.,-10,3);
	u_plot(g,xm+34.,-12.,2);
	arrow(g,xm+34.,-11.,xm+39.,-11.,2);
	u_plot(g,xmd+34.,-10,3);
	u_plot(g,xmd+34.,-12,2);
	arrow(g,xmd+34.,-11.,xmd+39.,-11.,2);

	g.setFont(new Font("TimesRoman",Font.BOLD|Font.ITALIC,18));

	symbol(g,33.,-1,"k");
	symbol(g,44.,0.,"kd");
	symbol(g,43.,-5,"cd");
        symbol(g,42.,-10,"u");
	symbol(g,37.5,-5.,"m");
	symbol(g,49.,-5.,"md");
	symbol(g,40.,5,"P");
	symbol(g,53.,-10,"ud");
	g.setFont(new Font("TimesRoman",Font.BOLD|Font.PLAIN,14));

	g.setColor(Color.black);
	symbol(g,30.,-15.,"Fig001:Single-Degree-of-Freedom system");
	//symbol(g,35.,-16.5,"of-Freedom system");
	Timestep+=dTimestep;
  }
  
  
  
  
  
//==========================================
}
