1 / 11

Interfaces Graphiques

Interfaces Graphiques. Tracer une fonction y = f(x) avec JAVA 2D. x. y. y. Afficher la courbe d’une fonction dans un fenêtre (un JPanel ou un JComponent ). x. F(x) = sin(x). Espace écran : (« Device Coordinate System »). Espace utilisateur (« World Coordinate System »). Entier

emma
Télécharger la présentation

Interfaces Graphiques

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Interfaces Graphiques Tracer une fonction y = f(x) avec JAVA 2D

  2. x y y • Afficher la courbe d’une fonction dans un fenêtre (un JPanel ou un JComponent) x F(x) = sin(x) Espace écran : (« Device Coordinate System ») Espace utilisateur (« World Coordinate System ») Entier Borné Réel Non borné

  3. y x • Afficher la courbe d’une fonction dans une fenêtre (un JPanel ou un JComponent) x y F(x) = sin(x) Espace écran : (« Device Coordinate System ») Espace utilisateur (« World Coordinate System ») Définir la région de l’espace utilisateur à afficher 1 Entier Borné Réel Non borné Appliquer au coordonnées exprimées dans WCS une transformation vers DCS 2

  4. y x xWmaxyWmax . • Définir la région de l'espace utilisateur à afficher x . xWminyWmin y DCS WCS Définition d’une fenêtre dans l’espace utilisateur : XWmin, YWmin coordonnées dans WCS du coin inférieur gauche de la fenêtre XWmax,YWmax coordonnées dans WCS du coin supérieur droit de la fenêtre

  5. y x xWmaxyWmax . . . xdyd • Transformation coordonnées WCS  coordonnées DCS xwyw x hd . xWminyWmin y ld xdyd xwyw DCS WCS = T T dépend de xWin, yWmin, xWmax, yWmax et de ld (largeur) et hd (hauteur) de la région d’affichage

  6. xWmin yWmin 0 hd T xWmax yWmax ld 0 T y . x xWmaxyWmax . . . xdyd • Transformation coordonnées WCS  coordonnées DCS xwyw x hd . . xWminyWmin y ld xdyd xwyw DCS WCS = T

  7. xdld xw - xWminlw = yWmax - ywhw ydhd hw =(yWmax – yWmin) = y x xWmaxyWmax . . . xdyd • Transformation coordonnées WCS  coordonnées DCS xwyw x hd . xWminyWmin y ld xdyd xwyw DCS WCS = T Les proportions doivent être conservées : La position relative de (xd,yd) par rapport à la région d’affichage doit être la mêmeque la position relative de (xw,xw) parrapport à la fenêtre utilisateur lw =(xWmax – xWmin)

  8. hdhw hdhw hdhw hdhw ldlw ldlw ldlw ldlw T xd = xw * - xWmin * xd xw 0 - xWmin * = * yd yw yWmax * 0 yd = - yw * + yWmax * - 1 1 0 1 0 y x xWmaxyWmax . . . xdyd • Transformation coordonnées WCS  coordonnées DCS xwyw x hd . xWminyWmin y ld xdyd xwyw DCS WCS = T xdld xw - xWminlw = yWmax - yw hw ydhd = translation homothétie

  9. hdhw hdhw hdhw hdhw ldlw ldlw ldlw ldlw ld xWmax 0 xWmin = = * 0 yWmax hd yWmin 1 1 1 1 y . x xWmaxyWmax . . . xdyd • Transformation coordonnées WCS  coordonnées DCS xwyw x hd . . xWminyWmin y ld DCS WCS 0 - xWmin * 0 - xWmin * * yWmax * 0 - yWmax * 0 - 0 1 0 0 1 0

  10. Cette transformation est combinée à latransformation courante maintenue par le contexte graphique hdhw hdhw ldlw ldlw Les coordonnées des primitives graphiques (« Shape ») sont ensuite exprimées dans WCSet seront automatiquement transforméelors du rendu. T public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int ld = this.getWidth(); int hd = this.getEight(); double lw = xWmax - xWmin; ... double m00 = ld / lw; ... AffineTransform t = new AffineTransform( m00,0.0,0.0, m11,m02,m12); g2.transform(t); ... g2.setStroke(new BasicStroke(0.0f)); ... g2.draw(aShape); } xd xw 0 - xWmin * = * yd yw yWmax * 0 - 1 1 0 1 0 • Transformation WCS  DCS : prise en charge par Java2D T définie par un objet java.awt.AffineTransform [ x'] = [ m00 m01 m02 ] [ x ] = [ m00x + m01y + m02 ] [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] [ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]

  11. public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int ld = this.getWidth(); int hd = this.getWidth(); double lw = xWmax - xWmin; ... double m00 = ld / lw; ... AffineTransform t = new AffineTransform( m00,0.0,0.0, m11,m02,m12); g2.transform(t); g2.setStroke(new BasicStroke(0.0f)); } • Échantillonnage de la courbe • Prendre garde de ne pas tracerdes primitives géométriques trop petites ( < 1 pixel) • La courbe va être approximée par des segments de droite. • Le pas d’échantillonnage doitêtre fixé en fonction desdimension de l’espace d’affichage double pasX = lw / ld * 3.0; for (double x = xWmin; x <= xWmax; x += pasX) { tracer segment (x,f(x)) (x + pasX, f(x + pasX); }

More Related