⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 surface.java

📁 坦克小战网络版
💻 JAVA
字号:
import java.awt.*;

public class surface{
	private vector[][] x_fixed;
	private vector[][] y_fixed;
	private double x_increasement;
	private double y_increasement;
	private int index;

	public surface(int index){
		x_increasement = 20;
	    y_increasement = 20;
	    x_fixed = new vector[70][70];
	    y_fixed = new vector[70][70];
	    this.index = index;


	 	for(int i = 0, x = -588; i < x_fixed.length; i++, x+=20){
	 		for(int j = 0, y = -750; j < x_fixed[i].length; j++, y+=y_increasement)
				x_fixed[i][j] = createSurface(x, y);
		}

		for(int i = 0, y = -750; i < y_fixed.length; i++, y+=20){
	 		for(int j = 0, x = -588; j < y_fixed[i].length; j++, x+=x_increasement)

				y_fixed[i][j] = createSurface(x, y);
		}
	}

	public void draw(Graphics g){
		g.setColor(Color.gray);

		for(int i = 0; i < x_fixed.length; i++){
			for(int j = 0; j < x_fixed[i].length; j++){
				if(j > 0 && x_fixed[i][j-1]!= null && x_fixed[i][j]!= null)
					g.drawLine(x_fixed[i][j-1].getX(), x_fixed[i][j-1].getY(), x_fixed[i][j].getX(), x_fixed[i][j].getY());
			}
		}
		for(int i = 0; i < y_fixed.length; i++){
			for(int j = 0; j < y_fixed[i].length; j++){
				if(j > 0 && y_fixed[i][j-1]!= null && y_fixed[i][j]!= null)
					g.drawLine(y_fixed[i][j-1].getX(), y_fixed[i][j-1].getY(), y_fixed[i][j].getX(), y_fixed[i][j].getY());
			}
		}
	}

	public vector createSurface(int x, int y){
		if(index == 1)
			return new vector(x,y,0);
		if(index == 2)
			return new vector(x, y,Math.sin(Math.sqrt((double)x*x/1600 + (double)y*y/1600))*30);
		if(index == 3)
			return new vector(x, y, (double)x*x*y*y/100000000*Math.exp(-(double)x*x/10000 - (double)y*y/10000)*700);
		return null;
	}

	public double fx(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return x/1600*(1/(Math.sqrt(x*x/1600 + y*y/1600)))*Math.cos(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return ((double)x*y*y*2/100000000*Math.exp(-(double)x*x/10000-(double)y*y/10000) + (double)x*x*y*y/100000000*x*(-2)/10000*Math.exp(-(double)x*x/10000-(double)y*y/10000))*700;
		return -1;
	}

	public double fy(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return y/1600*(1/(Math.sqrt(x*x/1600 + y*y/1600)))*Math.cos(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return ((double)x*x*y*2/100000000*Math.exp(-(double)x*x/10000-(double)y*y/10000) + (double)x*x*y*y/100000000*y*(-2)/10000*Math.exp(-(double)x*x/10000-(double)y*y/10000))*700;
		return -1;
	}

	public double evaluate(double x, double y){
		if(index == 1)
			return 0;
		if(index == 2)
			return Math.sin(Math.sqrt(x*x/1600 + y*y/1600))*30;
		if(index == 3)
			return x*x*y*y/100000000*Math.exp(-x*x/10000 - y*y/10000)*700;
		return -1;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -