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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package graphe2;
import java.awt.Polygon;
import java.io.*;
public class CourbeMath {
public Polygon MesPolygones[];
public CourbeMath()
{
CalculPoints();
}
public int NbPoly(){ //retourne le nombre de triangles dans le fichier
String chaine="";
String fich ="/home/makarov/four.msh";
File fichier = new File(fich);
//lecture du fichier texte
try{
InputStream ips=new FileInputStream(fichier);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String ligne;
ligne=br.readLine();
chaine+=ligne;
br.close();
}
catch (Exception e){
System.out.println(e.toString());
}
String delims = "[ ]+";
String[] tokens = chaine.split(delims);
int aInt = Integer.parseInt(tokens[1]);
return aInt;
}
private void CalculPoints()
{
MesPolygones = new Polygon[this.NbPoly()];
String fich ="/home/makarov/plot";
File fichier = new File(fich);
int N=this.NbPoly();
try{
InputStream ips=new FileInputStream(fichier);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
int k=0;
for(int i = 0 ; i < 6*N ; i=i+6)
{
int x[] = new int[3];
int y[]= new int[3];
for(int j=0; j<3;j++){
String ligne;
String chaine="";
ligne=br.readLine();
chaine+=ligne;
String delims = "[ ]+";
String[] tokens = chaine.split(delims);
double xInt = Double.parseDouble(tokens[0]);
double yInt = Double.parseDouble(tokens[1]);
xInt=xInt*1000;
yInt=yInt*1000;
x[j]=(int)xInt;
y[j]=(int)yInt;
System.out.println("coordonnees"+x[j]+","+y[j]);
}
br.readLine();
br.readLine();
br.readLine();
MesPolygones[i-k*5]=new Polygon(x,y,3);
k++;
}
br.close();
}
catch (Exception e){
System.out.println(e.toString());
}
}
} |
Partager