Planche 1

Cours 10
Géométrie algorithmique

Jean-Jacques.Levy@inria.fr
http://jeanjacqueslevy.net
tel: 01 39 63 56 89

secrétariat de l'enseignement:
Catherine Bensoussan
cb@lix.polytechnique.fr
Aile 00, LIX
tel: 01 69 33 34 67

http://www.enseignement.polytechnique.fr/informatique/


Planche 2

Plan

  1. Entrée graphiques
  2. Enveloppe convexe
  3. Recherche de points dans des intervalles
  4. Intersection de segments orthogonaux
  5. Intersection de segments

Planche 3

Click -- Double Click


for(;;) {
    while (!g.button())
        ;
    p = getMouse (); 
    while (g.button())
        ;
    action (p.h, p.v);
}

for (;;) {
    while (!g.button())
        ;
    while (g.button())
        ;
    p = getMouse (); 
    action (p.h, p.v);
}
Toute information supplémentaire se trouve en
http://www.enseignement.polytechnique.fr/profs/informatique/Philippe.Chassignet/MACLIB/Java/doc/tree.html
Planche 4

Programmation des événements clavier/souris

Planche 5

Ordre trigonométrique
On cherche à savoir si l'angle
P1P0P2 > 0 ?

En calculant le produit vectoriel
P0 P1 Ù P0 P2. Si l'angle est nul, par convention on compare les normes.

static int ccw (Point p0, Point p1, Point p2) {
  int dx1 = p1.x - p0.x; int dy1 = p1.y - p0.y;
  int dx2 = p2.x - p0.x; int dy2 = p2.y - p0.y;
  if (dx1 * dy2 > dy1 * dx2) return 1;
  else if (dx1 * dy2 < dy1 * dx2) return -1;
  else { 
    if (dx1 * dx2 < 0 || dy1 * dy2 < 0) return -1;
    else if (dx1*dx1 + dy1*dy1 >= dx2*dx2 + dy2*dy2) return 0;
    else return 1;
  }
}

Planche 6

Intersection de segments

static boolean intersect (Line l1, Line l2) {
  return  ccw (l1.p1, l1.p2, l2.p1) * ccw (l1.p1, l1.p2, l2.p2) <= 0
       && ccw (l2.p1, l2.p2, l1.p1) * ccw (l2.p1, l2.p2, l1.p2) <= 0;
}


Planche 7

Pente d'un vecteur

static float theta (Point p1, Point p2) {
  float t; int dx = p2.x - p1.x; int dy = p2.y - p1.y; 
  if (dx == 0 && dy == 0) t = 0;
  else t = (float) dy / (Math.abs(dx) + Math.abs(dy));
  if (dx < 0) t = 2 - t;
  else if (dy < 0) t = 4 + t;
  return t * 90.f;
}
Cette fonction évite le long calcul de Math.atan(dy/dx).


Planche 8

Enveloppe convexe (marche de Jarvis)



Planche 9

Enveloppe convexe (marche de Jarvis)

static int enveloppe (Point[] p) {
  int m = 0; int n = p.length;
  if (n > 0) {
    int min = 0; 
    for (int i = 1; i < n; ++i) if (p[i].y < p[min].y) min =  i;
    float angle1 = 0, angle2 = 360; do {
      Point t = p[m]; p[m] = p[min]; p[min] = t;
      ++m; min = 0;
      for (int i = m; i < n; ++i) {
        float alpha = theta(p[m-1], p[i]);
        if (angle1 < alpha && alpha < angle2) {
            min = i; angle2 = alpha;
        }
      }
      angle1 = angle2; angle2 = theta(p[min], p[0]);
     } while (min != 0);
  }
  return m;
}

Exercice 1Complexité?


Planche 10

Enveloppe convexe (marche de Graham)



Planche 11

Enveloppe convexe (marche de Graham)

static int enveloppe (Point[] p) {
  int m = 0; int n = p.length;
  if (n <= 2) return n;
  else {
    int min = 0; 
    for (int i = 1; i < n; ++i) if (p[i].y < p[min].y) min = i;
    for (int i = 0; i < n; ++i)
      if (p[i].y == p[min].y && p[i].x > p[min].x) min =  i;
    Point t = p[0]; p[0] = p[min]; p[min] = t;
    tri(p); m = 2;
    for (int i = 3; i < n; ++i) {
      while (ccw(p[m], p[m-1], p[i]) >= 0)
        --m;
      ++m;
      t = p[m]; p[m] = p[i]; p[i] = t;
    }
    return m+1;
  }
}

Exercice 2Complexité?


Planche 12

Recherche de points dans des intervalles



static void rechercher (Arbre a, intervalle i) {
  if (a != null) {
    boolean bg = i.x1 <= a.x, bd = a.x <= i.x2;
    if (bg) rechercher (a.gauche, i);
    if (bg && bd) System.out.print (a.x + " ");
    if (bd) rechercher (a.droite, i);
   }
}

Exercice 3Complexité?


Planche 13

Recherche de points dans des intervalles



static void rechercher (Arbre a, Rect r, Boolean d) {
  boolean t1, t2;
  if (a != null) {
    boolean bx1 = r.x1 <= a.p.x, bx2 = a.p.x <= r.x2;
    boolean by1 = r.y1 <= a.p.y, by2 = a.p.y <= r.y2;
    if (d) { b1 = bx1; b2 = bx2; } 
    else { b1 = by1; b2 = by2; }
    if (b1) 
       rechercher (a.gauche, r, !d);
    if (dansRect (a.p, r))
       System.out.print (a.p + " ");
    if (b2) 
       rechercher (a.droite, r, !d);
   }
}

Exercice 4Complexité?


Planche 14

Graphiquement



Planche 15

Intersection de segments orthogonaux



Planche 16

Intersection de segments quelconques (Shamos-Hoey)

Recherche d'au moins 1 intersection:


Planche 17

Intersections de segments quelconques (Bentley-Ottmann, 79)


Planche 18

Intersections de segments quelconques (Bentley-Ottmann, 79)


La vision et la synthèse d'images sont enseignées en Majeure 1 et 2.


Planche 19

Problèmes aux quels on a échappé


Planche 20



N'oubliez pas
les majeures!


Majeure 1: Algèbre et informatique
Majeure 2: Informatique

Travaillez votre
projet info
avec
mesure



This document was translated from LATEX by HEVEA.