📄 mapping.java
字号:
g.setColor(Color.yellow);
g.fillOval(xI-2,yI-2,4,4);
g.setColor(Color.black);
g.drawOval(xI-2,yI-2,4,4);
}
}
for(int i=0;i<root.root.drawing.nst;i++) drawStreamline(root.root.drawing.xstream[i],root.root.drawing.ystream[i]);
}
public boolean handleEvent(Event event) {
if (event.id == Event.MOUSE_MOVE && event.target == this) {
mouseMoveThis(event);
return true;
}
else
if (event.id == Event.MOUSE_DRAG && event.target == this) {
mouseMoveThis(event);
return true;
}
return super.handleEvent(event);
}
public void mouseMoveThis(Event ev) {
int xIndex,yIndex;
xIndex=ev.x;yIndex=ev.y;
if(xIndex>=xImin && xIndex<=xImax && yIndex>=yImin && yIndex<=yImax) {
x=(double)(xIndex-xImin)/50.0-x0;
y=y0-(double)(yIndex-yImin)/50.0;
root.xD.setText("x1 = "+format(x,3));
root.yD.setText("y1 = "+format(y,3));
}
}
void drawStreamline(double xx, double yy) {
double u,v,vmag=0.0,vmag1=0.0,Uinf,xs,ys,xs0,ys0,xs1,ys1,u1,v1,streamStep=.02;
double kuttag=0.0,xr,yr,r2;
int xI,yI,xI1,yI1,uI,uI1,vI,vI1,step,maxStep=1000,SKIP=3;
float hue;
Velocity vel=new Velocity(0.0,0.0);
Velocity dzdw=new Velocity(0.0,0.0);
Velocity upiv=new Velocity(0.0,0.0);
String s;
Graphics gs;
gs=this.getGraphics();
s="";
xs0=xs=xx;ys0=ys=yy;
upiv=W(xs,ys);
dzdw=D(xs,ys);
gs.setColor(Color.gray);
xI=(int)Math.round((upiv.u+x0)*50.0)+xImin;
yI=(int)Math.round((y0-upiv.v)*50.0)+yImin;
step=0;
while(step++<maxStep) {
vel=root.root.drawing.totalVk(xs,ys);
u=vel.u;v=vel.v;
if(vel.inf==true) break;
vmag = Math.sqrt(Math.abs(u * u + v * v)); //Estimate next point in streamline
if(vmag==0.0) break;
xs1=xs+u/vmag*streamStep;
ys1=ys+v/vmag*streamStep;
vel=root.root.drawing.totalVk(xs1,ys1);
u1=vel.u;v1=vel.v;
if(vel.inf==true) break;
vmag1 = Math.sqrt(Math.abs(u1 * u1 + v1 * v1)); //Re-estimate next point in streamline
if(vmag1==0.0) break;
xs1=xs+(u/vmag+u1/vmag1)*streamStep/2.0;
ys1=ys+(v/vmag+v1/vmag1)*streamStep/2.0;
if(step%SKIP==0) {
upiv=W(xs1,ys1);
xI1=(int)Math.round((upiv.u+x0)*50.0)+xImin;
yI1=(int)Math.round((y0-upiv.v)*50.0)+yImin;
if((xI<xImax && xI>xImin && yI<yImax && yI>yImin)&&(xI1<xImax && xI1>xImin && yI1<yImax && yI1>yImin)) {
dzdw=D(xs,ys);
if(dzdw.inf==false) {
hue=1.0f-(float)(vmag*Math.sqrt(Math.abs(dzdw.u * dzdw.u + dzdw.v * dzdw.v))/2.);
if(hue<0.0f) hue=0.0f;
}
else hue=0.0f;
gs.setColor(Color.getHSBColor(hue,1.0f,1.0f));
if(xs0+xs1<=0 || (ys0*ys1>0.0 || (ys0==0.0 && ys1==0.0))) { //Look for branch cut
gs.drawLine(xI,yI,xI1,yI1);
}
}
xI=xI1;xs0=xs;
yI=yI1;ys0=ys;
if(record) s+=fformat(upiv.u)+"\t"+fformat(upiv.v)+"\t"+fformat(u*dzdw.u+v*dzdw.v)+"\t"+fformat(-u*dzdw.v+v*dzdw.u)+"\n";
}
xs=xs1;ys=ys1;
}
if(record) root.out.addData(s);
}
String format(double d,int fdigits) {
String out="",buf;
String[] zeros={"0.","0.0","0.00"};
int mant,exp,sgn=1;
int sdigits=4; //number of digits to show in scientific format
int sci=4; //absolute magnitude of numbers below which to display floating-point format
if(d>0.0) sgn=1;
else if(d<0.0) sgn=-1;
else return(" 0.00");
d=Math.abs(d);
exp=(int)(Math.log(d*1.0000001)/Math.log(10));
if(d<1.0) exp--;
if(exp<4 & exp>=0) {
mant=(int)Math.round(d*Math.pow(10.,(double)(fdigits-1-exp)));
buf=String.valueOf(mant);
out=buf.substring(0,buf.length()-fdigits+exp+1)+"."+buf.substring(buf.length()-fdigits+exp+1); //insert point
//while(out.lastIndexOf("0")==out.length()-1) out=out.substring(0,out.length()-1); //strip trailing zeros
//if(out.lastIndexOf(".")==out.length()-1) out=out.substring(0,out.length()-1); //strip trailing point if necessary
if(sgn==-1) out="-"+out;
else out=" "+out;
}
else if(exp<0 & exp>-4) {
mant=(int)Math.round(d*Math.pow(10.,(double)(fdigits-1)));
buf=String.valueOf(mant);
out=zeros[-exp-1]+buf; //insert point
//while(out.lastIndexOf("0")==out.length()-1) out=out.substring(0,out.length()-1); //strip trailing zeros
if(sgn==-1) out="-"+out;
else out=" "+out;
}
else {
mant=(int)Math.round(d*Math.pow(10.,(double)(sdigits-1-exp)));
buf=String.valueOf(mant);
out=buf.substring(0,1)+"."+buf.substring(1); //insert point
while(out.lastIndexOf("0")==out.length()-1) out=out.substring(0,out.length()-1); //strip trailing zeros
if(out.lastIndexOf(".")==out.length()-1) out=out.substring(0,out.length()-1); //strip trailing point if necessary
if(sgn==-1) out="-"+out;
if(exp>0) out=out+"e+"+String.valueOf(exp);
else out=out+"e"+String.valueOf(exp);
}
return(out);
}
String fformat(double d) { //fixed scientific format
String out="",buf;
String[] zeros={"0.","0.0","0.00"};
int mant,exp,sgn=1,esgn=1;
int sdigits=5; //number of digits to show in scientific format
if(d>0.0) sgn=1;
else if(d<0.0) sgn=-1;
else return("0.0000e+000");
d=Math.abs(d);
exp=(int)(Math.log(d*1.0000001)/Math.log(10));
if(d<1.0) exp--;
mant=(int)Math.round(d*Math.pow(10.,(double)(sdigits-1-exp)));
buf=String.valueOf(mant);
out=buf.substring(0,1)+"."+buf.substring(1); //insert point
if(sgn==-1) out="-"+out;
else out=" "+out;
if(exp>=0) out=out+"e+";
else out=out+"e-";
if(Math.abs(exp)>99) out=out+String.valueOf(Math.abs(exp));
else if(Math.abs(exp)>9) out=out+"0"+String.valueOf(Math.abs(exp));
else out=out+"00"+String.valueOf(Math.abs(exp));
return(out);
}
Velocity W(double x, double y) {
Velocity upiv=new Velocity(0.0,0.0);
double r,th;
th=0.0;r=0.0;
if(x!=0.0 || y!=0.0) {
th=Math.atan2(y,x);
if(th<0.0) th+=2.0*Math.PI;
r=Math.sqrt(x*x+y*y);
}
switch (root.mapno) {
case 0: //s=z
upiv.u=x;
upiv.v=y;
upiv.inf=false;
break;
case 1: //s=az^b
if(r>0.0) {
upiv.u=root.aconst*Math.pow(r,root.bconst)*Math.cos(root.bconst*th);
upiv.v=root.aconst*Math.pow(r,root.bconst)*Math.sin(root.bconst*th);
upiv.inf=false;
}
else if(root.bconst>0.0) {upiv.u=0.0;upiv.v=0.0;upiv.inf=false;}
else {upiv.u=0.0;upiv.v=0.0;upiv.inf=true;}
break;
case 2: //s=a(z+b/z)
if(r>0.0) {
upiv.u=root.aconst*x+root.aconst*root.bconst*x/r/r;
upiv.v=root.aconst*y-root.aconst*root.bconst*y/r/r;
upiv.inf=false;
}
else {upiv.u=0.0;upiv.v=0.0;upiv.inf=true;}
break;
case 3: //s=alog(z) - ib
if(r>0.0) {
upiv.u=root.aconst*Math.log(r);
upiv.v=root.aconst*th-root.bconst;
upiv.inf=false;
}
else {upiv.u=0.0;upiv.v=0.0;upiv.inf=true;}
break;
case 4: //s=a(exp(bz)+bz)
upiv.u=root.aconst*Math.exp(root.bconst*x)*Math.cos(root.bconst*y)+root.aconst*root.bconst*x;
upiv.v=root.aconst*Math.exp(root.bconst*x)*Math.sin(root.bconst*y)+root.aconst*root.bconst*y;
upiv.inf=false;
break;
case 5: //s=(z-a)/(az-1) + b
upiv.u=(root.aconst*(r*r-root.aconst*x+1)-x)/((root.aconst*x-1.)*(root.aconst*x-1.)+root.aconst*root.aconst*y*y)+root.bconst;
upiv.v=(root.aconst*root.aconst-1.)*y/((root.aconst*x-1.)*(root.aconst*x-1.)+root.aconst*root.aconst*y*y);
upiv.inf=false;
break;
}
return upiv;
}
Velocity D(double x, double y) {
Velocity dzdw=new Velocity(0.0,0.0);
double r,th,p1,p2;
th=0.0;r=0.0;
if(x!=0.0 || y!=0.0) {
th=Math.atan2(y,x);
if(th<0.0) th+=2.0*Math.PI;
r=Math.sqrt(x*x+y*y);
}
switch (root.mapno) {
case 0: //s=z
dzdw.u=1.0;
dzdw.inf=false;
break;
case 1: //s=az^b
if(r>0.0) {
dzdw.u=1.0/root.aconst/root.bconst*Math.pow(r,1.0-root.bconst);
dzdw.inf=false;
}
else if(root.bconst>1.0) {
dzdw.u=0.0;
dzdw.inf=true;
}
else {
dzdw.u=0.0;
dzdw.inf=false;
}
break;
case 2: //s=a(z+b/z)
dzdw.u=Math.pow(root.aconst*r*r*r*r-root.aconst*root.bconst*(x*x-y*y),2.0)+4.0*x*x*y*y*root.aconst*root.aconst*root.bconst*root.bconst;
if(dzdw.u>0.0) {
dzdw.u=r*r*r*r/Math.sqrt(dzdw.u);
dzdw.inf=false;
}
else {
dzdw.u=0.0;
dzdw.inf=true;
}
break;
case 3: //s=alog(z) - ib
dzdw.u=r/root.aconst;
dzdw.inf=false;
break;
case 4: //s=a(exp(bz)+bz)
p1=Math.exp(root.bconst*x)*Math.cos(root.bconst*y)+1;
p2=Math.exp(root.bconst*x)*Math.sin(root.bconst*y);
p1=p1*p1+p2*p2;
if(p1>0.0) {
dzdw.u=1.0/root.aconst/root.bconst/Math.sqrt(p1);
dzdw.inf=false;
}
else {
dzdw.u=0.0;
dzdw.inf=true;
}
break;
case 5: //s=(z-a)/(az-1) + b
p1=root.aconst*(root.aconst*x*x-root.aconst*y*y-2.*x)+1.;
p2=root.aconst*(root.aconst*2*x*y-2.*y);
dzdw.u=Math.sqrt(p1*p1+p2*p2)/(root.aconst*root.aconst-1);
break;
}
return dzdw;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -