Back to index

wims  3.65+svn20090927
Cercle.java
Go to the documentation of this file.
00001 // Cercle.java _ 26/11/98
00002 
00003 package geo ;
00004 
00005 import java.awt.Graphics ;
00006 
00011 public class Cercle extends ObjetRepere
00012 { 
00013 
00018   public double xo ;
00019 
00024   public double yo ;
00025 
00030   public double r;
00031 
00036   public Cercle (pt O, double r, String Nom, Repere R)
00037   { super (Nom, R) ; Cercle (O, r) ; }
00038 
00043   public Cercle (String Nom, Repere R)
00044   { super (Nom, R) ; }
00045 
00050   public Cercle (double xo, double yo, double r, String Nom, Repere R)
00051   { super (Nom, R) ; Cercle (xo, yo, r) ; }
00052 
00057   public Cercle (pt O, pt A, String Nom, Repere R)
00058   { super (Nom, R) ; Cercle (O, A) ; }
00059 
00064   public Cercle (pt A, pt B, pt C, String Nom, Repere R)
00065   { super (Nom, R) ; Cercle (A, B, C) ; }
00066 
00067 
00072    public boolean zone (int X, int Y)
00073    { if (defini)
00074        { double d = R.Abs (X) - xo ; double d1 = R.Ord (Y) - yo ;
00075          d = Math.abs (Math.sqrt (d * d + d1 * d1) - r) * (R.unitex + R.unitey) ;
00076          if (d <= 2.0) return true ; else return false ;
00077        }
00078      return false ;
00079    }
00080 
00085   public void trace (Graphics g)
00086   { if (defini) { int Xo, Yo, RAYONX, RAYONY ;
00087                   Xo = R.Iabs (xo); Yo = R.Iord (yo);
00088                   RAYONX = (int) (R.unitex * r) ;
00089                   RAYONY = (int) (R.unitey * r) ;
00090                   g.drawOval (Xo - RAYONX, Yo - RAYONY, 2 * RAYONX, 2 * RAYONY);
00091                   if (Nom.length () != 0 )
00092                     { int X = R.Iabs (xo + r * 0.7) + 3 ;
00093                       int Y = R.Iord (yo + r * 0.7) - 3 ;
00094                       g.drawString (Nom, X, Y) ;
00095                     }
00096                  }
00097   }
00098 
00103   public void Cercle (pt O, double r)
00104   { xo = O.x; yo = O.y; this.r = r; defini = (r >= 0.0); }
00105 
00110   public void Cercle (double xo, double yo, double r)
00111   { this.xo = xo; this.yo = yo; this.r = r; defini = (r >= 0.0); }
00112 
00117   public void Cercle (pt O, pt A)
00118   { defini = O.defini && A.defini ;
00119     this.xo = O.x ; this.yo = O.y ;
00120     r = A.x - O.x ; double d = A.y - O.y ; r = Math.sqrt (r * r + d * d) ; 
00121   }
00122 
00127   public void Cercle (pt A, pt B, pt C)
00128   { defini = A.defini && B.defini && C.defini ;
00129     if (defini) { double det = A.x * (B.y - C.y) + B.x * (C.y - A.y) + C.x * (A.y - B.y) ;
00130                   defini = (det != 0.0) ;
00131                   if (defini) { double a = A.x * A.x + A.y * A.y ;
00132                                 double b = B.x * B.x + B.y * B.y ;
00133                                 double c = C.x * C.x + C.y * C.y ;
00134                                 xo = (a * (B.y - C.y) + b * (C.y - A.y) + c * (A.y - B.y)) / (det + det) ;
00135                                 yo = (a * (C.x - B.x) + b * (A.x - C.x) + c * (B.x - A.x)) / (det + det) ;
00136        r = (a * (B.y * C.x - C.y * B.x) + b * (C.y * A.x - A.y * C.x) + c * (A.y * B.x - B.y * A.x)) / det ;
00137                                 r = xo * xo + yo * yo - r ;
00138                                 defini = (r >= 0.0) ;
00139                                 if (defini) r = Math.sqrt (r) ;
00140                               }
00141                   }
00142   }
00143 
00144 }