Back to index

wims  3.65+svn20090927
DemiDroite.java
Go to the documentation of this file.
00001 package geo ;
00002 
00003 import java.awt.Graphics ;
00004 import geo.ObjetRepere ;
00005 import geo.pt ;
00006 import geo.Vecteur ;
00007 
00012 public class DemiDroite extends ObjetRepere
00013 {
00014 
00019   public double Ax, Ay ;
00020 
00025   public double Bx, By ;
00026 
00031   public DemiDroite (pt A, pt B, String Nom, Repere R)
00032   { super (Nom, R) ; DemiDroite (A, B) ; }
00033 
00038   public DemiDroite (String Nom, Repere R)
00039   { super (Nom, R) ; }
00040 
00045   public DemiDroite (double Ax, double Ay, double Bx, double By, String Nom, Repere R)
00046   { super (Nom, R) ; DemiDroite (Ax, Ay, Bx, By) ; }
00047 
00052   public DemiDroite (pt A, Vecteur u, String Nom, Repere R)
00053   { super (Nom, R) ; DemiDroite (A, u) ; }
00054 
00059    public boolean zone (int X, int Y)
00060    { if (defini)
00061        { double x = R.Abs (X) ; double y = R.Ord (Y) ;
00062          double a = By - Ay ; double b = Ax - Bx ;
00063          double A = a / R.unitex ; double B = b / R.unitey ;
00064          double d = Math.abs (a * x + b * y + Ay * Bx - Ax * By) / Math.sqrt (A * A + B * B) ;
00065          double xax = x - Ax ; double xbx = x - Bx ; double yay = y - Ay ; double yby = y - By ;
00066          if ((d <= 4.0) && ((xax * xbx <= 0) && (yay * yby <= 0) || (xax * xax + yay * yay >= xbx * xbx + yby * yby)))
00067            return true ;
00068          else return false ;
00069        }
00070      return false ;
00071    }
00072 
00077   public void trace (Graphics g)
00078   { int N, X1, Y1, X2, Y2 ;
00079     X1 = Y1 = X2 = Y2 = 0 ;
00080     double a = By - Ay ; double b = Ax - Bx ; double c = Ay * Bx - Ax * By ;
00081     if (defini) { if (Math.abs (b) >= Math.abs (a)) if (b < 0.0) { X1 = R.Iabs (Ax) ; Y1 = R.Iord (Ay) ;
00082                                                                    X2 = R.XMAX ;
00083                                                                    Y2 = R.Iord (-(a * R.Abs (X2) + c) / b) ;
00084                                                                  }
00085                                                     else         { X1 = 0 ;
00086                                                                    Y1 = R.Iord (-(a * R.Abs (X1) + c) / b) ;
00087                                                                    X2 = R.Iabs (Ax) ; Y2 = R.Iord (Ay) ;
00088                                                                }
00089                                                else if (a > 0.0) { Y1 = 0 ;
00090                                                                    X1 = R.Iabs (-(b * R.Ord (0) + c) / a);
00091                                                                    X2 = R.Iabs (Ax) ; Y2 = R.Iord (Ay) ;
00092                                                                  }
00093                                                     else         { X1 = R.Iabs (Ax) ; Y1 = R.Iord (Ay) ;
00094                                                                    Y2 = R.YMAX;
00095                                                                    X2 = R.Iabs (-(b * R.Ord (Y2) + c) / a) ;
00096                                                                  }
00097                   g.drawLine (X1, Y1, X2, Y2);
00098                   if (Nom.length () != 0) g.drawString (Nom, (X1 + X2) / 2 + 3, (Y1 + Y2) / 2 - 3) ;
00099                 }
00100   }
00101 
00102 
00103 
00104 
00109   public void DemiDroite (pt A, pt B)
00110   { defini = A.defini && B.defini && ((A.x != B.x) || (A.y != B.y)) ;
00111     if (defini) { Ax = A.x ; Ay = A.y ; Bx = B.x ; By = B.y ; }
00112   }
00113 
00118   public void DemiDroite (double Ax, double Ay, double Bx, double By)
00119   { defini = ((Ax != Bx) || (Ay != By)) ;
00120     if (defini) { this.Ax = Ax ; this.Ay = Ay ; this.Bx = Bx ; this.By = By ; }
00121   }
00122 
00127   public void DemiDroite (pt A, Vecteur u)
00128   { defini = ((u.x != 0.0) || (u.y != 0.0)) ;
00129     if (defini) { Ax = A.x ; Ay = A.y ; Bx = A.x + u.x ; By = A.y + u.y ; }
00130   }
00131 
00132 }