Back to index

wims  3.65+svn20090927
Segment.java
Go to the documentation of this file.
00001 package geo ;
00002 
00003 import java.awt.Graphics ;
00004 
00009 public class Segment extends ObjetRepere
00010 {
00011 
00016   public int AX, AY, BX, BY;
00017 
00022   public double Ax, Ay, Bx, By ;
00023 
00028   public Segment (String Nom, Repere R)
00029   { super (Nom, R) ; }
00030 
00035   public Segment (pt A, pt B, String Nom, Repere R)
00036   { super (Nom, R) ; Segment (A, B) ; }
00037 
00042   public Segment (double Ax, double Ay, double Bx, double By, String Nom, Repere R)
00043   { super (Nom, R) ; Segment (Ax, Ay, Bx, By) ; }
00044 
00049   public double Longueur ()
00050   { if (defini) { double u = Bx - Ax ; double v = By - Ay ;
00051                   return Math.sqrt (u * u + v * v) ;
00052                 }
00053     else        return -1.0 ;
00054   }
00055 
00060   public void trace (Graphics g)
00061   { if (defini)
00062       { g.drawLine (AX, AY, BX, BY) ;
00063         if (Nom.length () != 0) g.drawString (Nom, (AX + BX) / 2 + 3, (AY + BY) / 2 - 3) ;
00064       }
00065   }
00066 
00071    public boolean zone (int X, int Y)
00072    { if (defini)
00073        { int A = BY - AY ; int B = AX - BX ;
00074          double d = ((double) Math.abs (A * X + B * Y + AY * BX - AX * BY)) / Math.sqrt ((double) (A * A + B * B)) ;
00075          if ((d <= 4.0) && ((X - AX) * (X - BX) <= 0) && ((Y - AY) * (Y - BY) <= 0))
00076            return true ;
00077          else return false ;
00078        }
00079      return false ;
00080    }
00081 
00086   public void Segment (pt A, pt B)
00087   { defini = A.defini && B.defini ;
00088     if (defini) { AX = A.X ; AY = A.Y ; BX = B.X ; BY = B.Y ;
00089                   Ax = A.x ; Ay = A.y ; Bx = B.x ; By = B.y ;
00090                 }
00091   }
00092 
00097   public void Segment (double Ax, double Ay, double Bx, double By)
00098   { defini = true ;
00099     if (defini) { this.Ax = Ax ; this.Ay = Ay ; this.Bx = Bx ; this.By = By ;
00100                   AX = R.Iabs (Ax) ; AY = R.Iord (Ay) ; BX = R.Iabs (Bx) ; BY = R.Iord (By) ;
00101                 }
00102   }
00103 }