Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package main;
  2.  
  3. public class Structures {
  4.    
  5.     public static class Point {
  6.         public double x0; // abscisse du point
  7.         public double y0; // ordonnée du point
  8.         public String toString() {
  9.             return "("+x0+", "+y0+")";
  10.         }
  11.     }
  12.     public static class Rectangle {
  13.         public Point hg; // coin supérieur gauche
  14.         public double l; // largeur
  15.         public double h; // hauteur
  16.         public String toString() {
  17.             return "<"+hg+", "+l+" \u00d7 "+h+">";
  18.         }
  19.     }
  20.     //EXERCICE 8.1
  21.     public static boolean memeAire(Rectangle r1, Rectangle r2) {
  22.         return r1.l*r1.h==r2.l*r2.h;
  23.     }
  24.     //EXERCICE 8.2
  25.     public static void agrandiRec(Rectangle r, int k) {
  26.         // pré-requis: k>0
  27.         // agrandit r d'un facteur k
  28.         r.l=r.l*k;
  29.         r.h=r.h*k;
  30.     }
  31.     //EXERCICE 8.3
  32.     public static Rectangle creeRec(Point p, double l, double h) {
  33.         //delivre un rectangle de coin supérieur gauche p, de largeur l et de hauteur h
  34.         Rectangle r= new Rectangle();
  35.         r.hg=p;
  36.         r.l=l;
  37.         r.h=h;
  38.         return r;
  39.     }
  40.     //EXERCICE 8.4
  41.     public static Rectangle homothetiqueDe(Rectangle r, int k) {
  42.         Point p = new Point();
  43.         if (k>=0) {
  44.             p.x0=r.hg.x0*k;
  45.             p.y0=r.hg.y0*k;
  46.         }
  47.         else {
  48.             p.x0=(r.hg.x0+r.l)*k;
  49.             p.y0=(r.hg.y0-r.h)*k;
  50.         }
  51.         Rectangle rh= creeRec(p, r.l*Math.abs(k), r.h*Math.abs(k));
  52.         return rh;
  53.     }
  54.     //EXERCICE 8.5
  55.     public static Rectangle enveloppe(Rectangle[] er) {
  56.         Point esg = new Point();
  57.         Point eid = new Point();
  58.         Point id;
  59.         esg.x0=er[0].hg.x0;
  60.         esg.y0=er[0].hg.y0;
  61.         id=coinID(er[0]);
  62.         eid.x0=id.x0;
  63.         eid.y0=id.y0;
  64.         for(int i=1; i<er.length; i++) {
  65.             if(er[i].hg.x0<esg.x0) esg.x0=er[i].hg.x0;
  66.             if(er[i].hg.y0>esg.y0) esg.y0=er[i].hg.y0;
  67.             id=coinID(er[i]);
  68.             if(id.x0>eid.x0) eid.x0=id.x0;
  69.             if(id.y0<eid.y0) eid.y0=id.y0;
  70.         }
  71.         return creeRec(esg, eid.x0-esg.x0, esg.y0-eid.y0);
  72.     }
  73.     public static Point coinID(Rectangle r) {
  74.         //rend le coin inférieur droit de r
  75.         Point pid = new Point();
  76.         pid.x0=r.hg.x0+r.l;
  77.         pid.y0=r.hg.y0-r.h;
  78.         return pid;
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement