📄 mapping.java
字号:
import java.awt.*;
public class mapping extends machine {
machine root;
Panel flowtype,numbers,controls,baseline; //GUI declarations
mDrawing drawing;
Legend legend;
Choice options;
TextField aD,bD;
Label label2,label3,dum,xD,yD;
Button newflow,mapbut,databut;
dataPort out;
errorPort err;
//declare variables that hold the mapping info
int mapno,ncrit;
double aconst;
double bconst;
String mlabel;
double critx[]=new double[10];
double crity[]=new double[10];
mapping(machine target) {
setTitle("Mapped plane: z1 = z");
root=target;
setBackground(Color.white);
GridBagLayout gridbag=new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
numbers=new Panel();
numbers.setLayout(gridbag);
c.weightx=1.0;
options= new Choice();
options.setFont(new Font("Dialog",Font.PLAIN,10));
options.addItem("z1 = z");
options.addItem("z1 = az^b");
options.addItem("z1 = a(z + b/z)");
options.addItem("z1 = a ln(z) - ib");
options.addItem("z1 = a(exp(bz) + bz)");
options.addItem("z1 = (z - a)/(az - 1) + b");
gridbag.setConstraints(options,c);
numbers.add(options);
//c.anchor=GridBagConstraints.EAST;
label2=new Label("a =");
label2.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(label2,c);
numbers.add(label2);
aD=new TextField(5);
aD.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(aD,c);
numbers.add(aD);
label3=new Label("b =");
label3.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(label3,c);
numbers.add(label3);
bD=new TextField(5);
bD.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(bD,c);
numbers.add(bD);
//c.anchor=GridBagConstraints.WEST;
xD=new Label("x1 = 0.00");
xD.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(xD,c);
numbers.add(xD);
c.gridwidth = GridBagConstraints.REMAINDER;
yD=new Label("y1 = 0.00");
yD.setFont(new Font("Dialog",Font.PLAIN,10));
gridbag.setConstraints(yD,c);
numbers.add(yD);
buttonbar=new Panel();
buttonbar.setLayout(new GridLayout(1,3,10,5));
newflow=new Button("Apply Mapping");
newflow.setFont(new Font("Dialog",Font.PLAIN,10));
buttonbar.add(newflow);
databut=new Button("Show data");
databut.setFont(new Font("Dialog",Font.PLAIN,10));
buttonbar.add(databut);
dum=new Label(" ",Label.RIGHT);
buttonbar.add(dum);
legend=new Legend(this);
baseline=new Panel();
baseline.setLayout(new BorderLayout());
baseline.add("East",buttonbar);
baseline.add("Center",legend);
drawing=new mDrawing(this);
setLayout(new BorderLayout());
add("North",numbers);
add("South",baseline);
add("Center",drawing);
aD.setText("1.0");
bD.setText("0.0");
setBackground(Color.white);
drawing.repaint();
legend.repaint();
out=new dataPort();
out.setTitle("Mapped Streamline Data: (x1,y1,u1,v1)");
err=new errorPort(this,"Incorrect Input");
}
public Insets insets() {
return new Insets(30,20,30,20);
}
public void paint (Graphics g){
legend.repaint();
}
public boolean handleEvent(Event event) {
if (event.id == Event.WINDOW_DESTROY) {
hide();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == newflow) {
clickedNewflow();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == databut) {
clickedMapbut();
return true;
}
return super.handleEvent(event);
}
public void clickedNewflow() {
Double aconstD= new Double(0.0); //There has to be an easier way to do this!!
Double bconstD= new Double(0.0);
aconstD=Double.valueOf(aD.getText());
bconstD=Double.valueOf(bD.getText());
aconst=aconstD.doubleValue();
bconst=bconstD.doubleValue();
int xI,yI;
Graphics g;
mapno=options.getSelectedIndex();
switch (mapno) {
case 0: //s=z
break;
case 1: //s=az^b
case 4: //s=a(exp(bz)+bz)
if((aconst==0.0 || bconst==0.0)) {
err.msg.setText("Neither 'a' nor 'b' may be zero");
err.resize(256,150);
err.show();
err.move(100,100);
return;
}
break;
case 2: //s=a(z+b/z)
case 3: //s=alog(z) - ib
if (aconst==0.0) {
err.msg.setText("'a' may not be zero");
err.resize(256,150);
err.show();
err.move(100,100);
return;
}
break;
case 5: //s=(z-a)/(az-1) + b
if (aconst==1.0 || aconst==-1.0) {
err.msg.setText("'a' may not be 1 or -1");
err.resize(256,150);
err.show();
err.move(100,100);
return;
}
break;
}
switch (mapno) {
case 0: //s=z
mlabel="z1 = z";;
ncrit=0;
break;
case 1: //s=az^b
mlabel="z1 = ";
if(aconst!=1.0) mlabel+=aconst;
mlabel+="z";
if(bconst!=1.0) mlabel+="^"+bconst;
ncrit=0;
if(bconst>1.0) {
ncrit=1;
critx[0]=0.0;crity[0]=0.0;}
break;
case 2: //s=a(z+b/z)
mlabel="z1 = ";
if(aconst!=1.0) mlabel+=aconst+"(";
mlabel+="z+"+bconst+"/z";
if(aconst!=1.0) mlabel+=")";
ncrit=2;
if(bconst>0.0) {
critx[0]=Math.sqrt(bconst);
critx[1]=-Math.sqrt(bconst);
crity[0]=0.0;crity[1]=0.0;
}
else {
critx[0]=0.0;critx[1]=0.0;
crity[0]=Math.sqrt(-bconst);
crity[1]=-Math.sqrt(-bconst);
}
break;
case 3: //s=alog(z) - ib
mlabel="z1 = ";
if(aconst!=1.0) mlabel+=aconst;
mlabel+="ln(z)";
if(bconst!=0.0) mlabel+=" - ";
if(bconst!=1.0 && bconst!=0.0) mlabel+=bconst;
if(bconst!=0.0) mlabel+="i";
ncrit=0;
break;
case 4: //s=a(exp(bz)+bz)
mlabel="z1 = ";
if(aconst!=1.0) mlabel+=aconst+"(";
mlabel+="exp(";
if(bconst!=1.0) mlabel+=bconst;
mlabel+="z)+";
if(bconst!=1.0) mlabel+=bconst;
mlabel+="z";
if(aconst!=1.0) mlabel+=")";
ncrit=2;
critx[0]=0.0;critx[1]=0.0;
crity[0]=Math.PI/bconst;crity[1]=-crity[0];
break;
case 5: //s=(z-a)/(az-1) + b
mlabel="z1 = (z-"+aconst+")/("+aconst+"z-1)";
if(bconst!=0.0) mlabel+=" + "+bconst;
ncrit=0;
break;
}
drawing.repaint();setTitle("Mapped plane : "+mlabel);
root.drawing.repaint();
}
public void clickedMapbut() {
if(root.drawing.nst!=0) {
out.resize(500,300);
out.show();
drawing.record=true;
drawing.drawStreamline(root.drawing.xstream[root.drawing.nst-1],root.drawing.ystream[root.drawing.nst-1]);
drawing.record=false;
}
}
}
class mDrawing extends Canvas {
mapping root;
int w,h,xImin,xImax,yImin,yImax,x0,y0,xO=0,yO=0,rO=0;
double x,y,x1,y1;
int nf=0,nst=0; //nf is a counter for the singularities, nst is a counter for the streamlines
double xstream[]=new double[1000];
double ystream[]=new double[1000];
double freeStreamU=0.0,freeStreamV=0.0;
double circlex,circley,circler,kuttat;
boolean circleOn=false,kuttaOn=false,record=false;
mDrawing(mapping target) {
root=target;
setBackground(Color.white);
}
public void paint (Graphics g){
int xI,yI;
Velocity upiv=new Velocity(0.0,0.0);
w=size().width;h=size().height;
xImin=(int)(w*0.10);xImax=xImin+((int)(w*0.85)/50)*50;
yImin=(int)(h*.05);yImax=yImin+((int)(h*0.9)/50)*50;
g.clearRect(0,0,w,h);
g.setColor(Color.gray); //Draw grid
for(int i=xImin;i<=xImax;i+=50) {
for(int j=yImin;j<=yImax;j+=50) {
g.drawLine(i-3,j,i+3,j);
g.drawLine(i,j-3,i,j+3);
}
}
x0=(xImax-xImin)/50/2;
y0=(yImax-yImin+99)/50/2;
g.drawLine(x0*50-6+xImin,yImin+y0*50,x0*50+6+xImin,yImin+y0*50);
g.drawLine(x0*50+xImin,yImin+y0*50-6,x0*50+xImin,yImin+y0*50+6);
for(int i=0;i<root.ncrit;i++) {
upiv=W(root.critx[i],root.crity[i]);
xI=(int)Math.round((upiv.u+x0)*50.0)+xImin;
yI=(int)Math.round((y0-upiv.v)*50.0)+yImin;
if(xI>=xImin && xI<=xImax && yI>=yImin && yI<=yImax) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -