bonjour,
j'aurai besoin de tracer une courbe dans un repere orthonormé. je stockerai surement les données (longitude, latitudes) de ma courbes dans un tableau au préalable.
si quelqu'un pourra m'aider je serai très reconnaissant.
merci d'avance.
bonjour,
j'aurai besoin de tracer une courbe dans un repere orthonormé. je stockerai surement les données (longitude, latitudes) de ma courbes dans un tableau au préalable.
si quelqu'un pourra m'aider je serai très reconnaissant.
merci d'avance.
Bonjour!
Tu peux utiliser le package java.awt.geom pour tracer ta courbe. Voici le lien vers la javadoc: Cliques ici
Bien sur il faudra également utiliser Graphics2D afin d'afficher ta courbe. Le mieux est de le faire dans un JPanel séparé afin d'avoir la précision que tu souhaite. Le repaire sera tracé lui aussi séparément mais il faudra prendre soin de l'adapter à l'échelle!
Alternative sans doute moins optimisée:
Je débute en Java donc je me trompe peut-être.^^ Il y a surement une méthode dans l'API Java (sinon dans une autre) qui te permet de tracer à ta place!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public void paint (Graphics g) { Graphics2D g2 = (Graphics2D) g; int nombreDePoints = 10; for (int i = 1; i <= nombreDePoints; i++) { //Insère ici ta méthode pour trouver x1 //Pareil pour y1 //x2 //y2 //Tu as maintenant toutes les coordonées dont tu as besoin pour ton premier tracé. //On trace g2.draw(new Line2D.Double(x1, y1, x2, y2)); //L'action se répêtera alors jusqu'a ce que toute la courbe soit tracée. //Bien sûr, tu peux modifier à ta guise le nombreDePoints! } }
Si c'est juste un graphique que tu veux faire, la bibliothèque de JFreeChart est très facile à utilisé
Dumbl
Bonjour merci bien pour vos réponses ,
je veux tracer comme l'illustration suivante pour permettre de visualiser le niveau de l'eau dans un canal
avec ce qui est en bleu représente le niveau de l'eau qui doit être dynamique c'est a dire doit se varie selon le niveau dans le canal
moi je sais pas comment je vais tracer ce qui est en bleu je suis vraiment perdus
voila mon code :
et la deuxieme classe:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 package plegatfem2d; import java.awt.Color; import java.awt.Graphics; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iterator; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class PFEM2DGuiPanel extends JPanel { /** * */ private static final long serialVersionUID = 1L; private double offsetX, offsetY; // decalage de la vue private double echelle; // echelle de la vue int points [], nbre; int pointsa [], nbrea; final int hauteur = 100; private int posX=-50,posY=-50; public PFEM2DGuiPanel() { super(); this.offsetX = 0; this.offsetY = 0; this.echelle = 100; } public void paintComponent(Graphics g) { int h = this.getHeight(); int w = this.getWidth(); g.setColor(Color.pink); g.fillRect(0, 0, w, h); //tracé des axes int roundOffsetX = (int) Math.round(this.offsetX); int roundOffsetY = (int) Math.round(this.offsetY); g.setColor(Color.red); g.drawLine(w / 3 + roundOffsetX, 0, w / 3 + roundOffsetX, h); g.drawLine(0, 4*h/5 + roundOffsetY, w, 4*h/5 + roundOffsetY); nbre=26; int points[] =new int[nbre]; points[0]=0; points[1]=0; points[2]=40; points[3]=40; points[4]=80; points[5]=80; points[6]=120; points[7]=120; points[8]=160; points[9]=160; points[10]=200; points[11]=200; points[12]=240; points[13]=240; points[14]=280; points[15]=280; points[16]=320; points[17]=320; points[18]=360; points[19]=360; points[20]=400; points[21]=400; points[22]=440; points[23]=440; points[24]=480; points[25]=480; int pointsa[] =new int[nbre]; pointsa[0]=-500; pointsa[1]=-480; pointsa[2]=-460; pointsa[3]=-440; pointsa[4]=-420; pointsa[5]=-400; pointsa[6]=-380; pointsa[7]=-360; pointsa[8]=-340; pointsa[9]=-320; pointsa[10]=-300; pointsa[11]=-280; pointsa[12]=-260; pointsa[13]=-240; pointsa[14]=-220; pointsa[15]=-200; pointsa[16]=-180; pointsa[17]=-160; pointsa[18]=-140; pointsa[19]=-120; pointsa[20]=-100; pointsa[21]=-80; pointsa[22]=-60; pointsa[23]=-40; pointsa[24]=-20; pointsa[25]=00; // Barre. g.setColor(Color.black); int i,j; j=0; i=0; while ((i <nbre-1)&&(j<nbre-1)) { g.drawLine(points[i]+w / 3, pointsa[j]+4*h/5, points[i+1]+w / 3, pointsa[j+1]+4*h/5); i=i+1; j=j+1; } g.drawString("kaoutar",10,20); } public void takeScreenshot() { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File fichier = fc.getSelectedFile(); String nomFichier = fichier.getName().toLowerCase(); if ((nomFichier.endsWith("png")) || (nomFichier.endsWith("jpg"))) { try { BufferedImage bufImage = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_RGB); this.paint(bufImage.createGraphics()); String extension = "png"; if (nomFichier.endsWith("jpg")) { extension = "jpg"; } ImageIO.write(bufImage, extension, fichier); } catch (IOException ex) { ex.printStackTrace(); } } else { JOptionPane.showMessageDialog(this, "Veuillez préciser l'extension du fichier image (png ou jpg)", "Extension fichier manquante", JOptionPane.ERROR_MESSAGE); } } } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package plegatfem2d; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JSeparator; import javax.swing.JToolBar; public class PlegatFem2D_GuiPanel extends JFrame { public PlegatFem2D_GuiPanel(String frameTitle) { super(frameTitle); this.initComponents(); } private void initComponents() { this.pfguipanel = new PFEM2DGuiPanel(); this.pfguipanel.setPreferredSize(new Dimension(1250, 700)); this.add(this.pfguipanel, BorderLayout.CENTER); JToolBar toolbar = new JToolBar(); toolbar.setPreferredSize(new Dimension(100, 40)); toolbar.setFloatable(false); // bouton capture JButton capture = new JButton("capture", new javax.swing.ImageIcon(getClass().getResource("/ressources/icons/snapshot.png"))); capture.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pfguipanel.takeScreenshot(); } }); toolbar.add(capture); toolbar.add(new JSeparator(JSeparator.VERTICAL));//separer les boutons this.add(toolbar, BorderLayout.NORTH);//afich bouton this.pack();//afficher fentre //this.setDefaultCloseOperation(EXIT_ON_CLOSE); } private PFEM2DGuiPanel pfguipanel; /** * Main class. * * @param args the command line arguments */ public static void main(String[] args) { new PlegatFem2D_GuiPanel("Logiciel de Supervision").setVisible(true); } }
votre aide sera un grands secours j'en ai énormément besoin de votre aide
merci d'avance
Partager