Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by dddd ( 7 years ago )
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class Node{
double x,y;
double t;
public Node(double x, double y, double t) {
this.x = x;
this.y = y;
this.t=t;
}
public void write(){
System.out.print("("+x+","+y+")"+"["+t+"C]");
}
public void write_wo_temp(){
System.out.print("("+x+","+y+")");
}
}
class Element{
Node[] ID;
int [] idW;
public Element() {
ID=new Node[4];
ID[0]=new Node(555,555,14);
ID[1]=new Node(555,555,11);
ID[2]=new Node(555,555,142);
ID[3]=new Node(555,555,134);
idW=new int[4];
}
public void write(){
ID[0].write();
ID[1].write();
System.out.println();
ID[2].write();
ID[3].write();
}
public void write_wo_temp(){
System.out.print(idW[0]);
ID[0].write_wo_temp();
System.out.print(idW[1]);
ID[1].write_wo_temp();
System.out.println();
System.out.print(idW[2]);
ID[2].write_wo_temp();
System.out.print(idW[3]);
ID[3].write_wo_temp();
}
}
class Grid {
double h,l;
int nH,nL;
int nh;
int ne;
Element[] elementy;
public Grid(double h,double l, int nH, int nL){
this.h= h;
this.l=l;
this.nH=nH;
this.nL=nL;
nh=nL*nH;
ne=(nL-1)*(nH-1);
elementy=new Element[ne];
for(int i=0;i<ne;i++)
elementy[i]=new Element();
}
public void generate() {
int pom_i=0;
double i=0;
double j=0;
int inH=0;
int inL=0;
int idw=0;
while(pom_i<ne){
if(j==(h)){
i+=l/(nL-1);
j=0;
}
elementy[pom_i].ID[0].x=i;
elementy[pom_i].ID[0].y=j;
i+=l/(nL-1);
elementy[pom_i].ID[1].x=i;
elementy[pom_i].ID[1].y=j;
j+=h/(nH-1);
elementy[pom_i].ID[2].x=i;
elementy[pom_i].ID[2].y=j;
i-=l/(nL-1);
elementy[pom_i].ID[3].x=i;
elementy[pom_i].ID[3].y=j;
pom_i++;
}
/* int iterator_w=0;
int n=0;
int z=0;
while(n<ne){
z=0;
elementy[n].idW[z]=iterator_w;
z++;
iterator_w++;
elementy[n].idW[z]=iterator_w;
iterator_w++;
z++;
elementy[n].idW[z]=iterator_w;
iterator_w++;
z++;
elementy[n].idW[z]=iterator_w;
iterator_w++;
z++;
n++;
iterator_w-=2;
}
*/
int iterator_w=0;
int n=0;
int z=0;
}
public void generateid() {
Element[] temp=new Element[ne];
for(int i=0;i<ne;i++){
temp[i]=new Element();
}
int j=0;
int i=0;
int inH=0;
while(i<ne){
inH++;
if(inH==nH) {
j++;
inH=1;
}
temp[i].idW[0] = j;
temp[i].idW[1] = j + nH;
temp[i].idW[2] = j + nH + 1;
temp[i].idW[3] = j + 1;
elementy[i].idW = temp[i].idW;
j++;
i++;
}
}
public void write(){
for(int i=0;i<ne;i++) {
System.out.print("\n nr elementu:"+(i+1)+"\n");
elementy[i].write();
}
}
public void write_wo_temp(){
for(int i=0;i<ne;i++) {
System.out.print("\n nr elementu:"+(i+1)+"\n");
elementy[i].write_wo_temp();
}
}
}
public class MES_GRID_2 {
public static void main(String[] args) throws FileNotFoundException{
/* odczyt z danych nastepujacy= l h nL nH*/
double l,h;
int nL,nH;
File file = new File("dane.txt");
Scanner in = new Scanner(file);
l = Double.parseDouble(in.nextLine());
h = Double.parseDouble(in.nextLine());
nL=Integer.parseInt(in.nextLine());
nH=Integer.parseInt(in.nextLine());
Grid siatka=new Grid(h,l,nH,nL);
siatka.generate();
siatka.generateid();
siatka.write_wo_temp();
}
}
Revise this Paste