Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- public class Structures {
- public static class Point {
- public double x0; // abscisse du point
- public double y0; // ordonnée du point
- public String toString() {
- return "("+x0+", "+y0+")";
- }
- }
- public static class Rectangle {
- public Point hg; // coin supérieur gauche
- public double l; // largeur
- public double h; // hauteur
- public String toString() {
- return "<"+hg+", "+l+" \u00d7 "+h+">";
- }
- }
- //EXERCICE 8.1
- public static boolean memeAire(Rectangle r1, Rectangle r2) {
- return r1.l*r1.h==r2.l*r2.h;
- }
- //EXERCICE 8.2
- public static void agrandiRec(Rectangle r, int k) {
- // pré-requis: k>0
- // agrandit r d'un facteur k
- r.l=r.l*k;
- r.h=r.h*k;
- }
- //EXERCICE 8.3
- public static Rectangle creeRec(Point p, double l, double h) {
- //delivre un rectangle de coin supérieur gauche p, de largeur l et de hauteur h
- Rectangle r= new Rectangle();
- r.hg=p;
- r.l=l;
- r.h=h;
- return r;
- }
- //EXERCICE 8.4
- public static Rectangle homothetiqueDe(Rectangle r, int k) {
- Point p = new Point();
- if (k>=0) {
- p.x0=r.hg.x0*k;
- p.y0=r.hg.y0*k;
- }
- else {
- p.x0=(r.hg.x0+r.l)*k;
- p.y0=(r.hg.y0-r.h)*k;
- }
- Rectangle rh= creeRec(p, r.l*Math.abs(k), r.h*Math.abs(k));
- return rh;
- }
- //EXERCICE 8.5
- public static Rectangle enveloppe(Rectangle[] er) {
- Point esg = new Point();
- Point eid = new Point();
- Point id;
- esg.x0=er[0].hg.x0;
- esg.y0=er[0].hg.y0;
- id=coinID(er[0]);
- eid.x0=id.x0;
- eid.y0=id.y0;
- for(int i=1; i<er.length; i++) {
- if(er[i].hg.x0<esg.x0) esg.x0=er[i].hg.x0;
- if(er[i].hg.y0>esg.y0) esg.y0=er[i].hg.y0;
- id=coinID(er[i]);
- if(id.x0>eid.x0) eid.x0=id.x0;
- if(id.y0<eid.y0) eid.y0=id.y0;
- }
- return creeRec(esg, eid.x0-esg.x0, esg.y0-eid.y0);
- }
- public static Point coinID(Rectangle r) {
- //rend le coin inférieur droit de r
- Point pid = new Point();
- pid.x0=r.hg.x0+r.l;
- pid.y0=r.hg.y0-r.h;
- return pid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement