1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
public class Quadrillage {
private Complex posHautGauche, posBasDroite;
private int nbLignesHoriz, nbLignesVert;
private Path2D quadrillage;
public Quadrillage(Complex posHautGauche, Complex posBasDroite, int nbLignesHoriz, int nbLignesVert)
{
this.posHautGauche = posHautGauche;
this.posBasDroite = posBasDroite;
this.nbLignesHoriz = nbLignesHoriz;
this.nbLignesVert = nbLignesVert;
quadrillage = new Path2D.Double();
double ecartLignesHoriz = Math.abs((posBasDroite.getImaginary() - posHautGauche.getImaginary()) / (nbLignesHoriz - 1));
double ecartLignesVert = Math.abs((posBasDroite.getReal() - posHautGauche.getReal()) / (nbLignesVert - 1));
for(int l = 0; l < nbLignesHoriz; l++)
{
quadrillage.moveTo(posHautGauche.getReal(), posHautGauche.getImaginary() - l * ecartLignesHoriz);
quadrillage.lineTo(posBasDroite.getReal(), posHautGauche.getImaginary() - l * ecartLignesHoriz);
}
for(int c = 0; c < nbLignesVert; c++)
{
quadrillage.moveTo(posHautGauche.getReal() + c * ecartLignesVert, posHautGauche.getImaginary());
quadrillage.lineTo(posHautGauche.getReal() + c * ecartLignesVert, posBasDroite.getImaginary());
}
}
public void methodeQuiPlante()
{
double[] tab = new double[2];
PathIterator it = quadrillage.getPathIterator(null);
while (!it.isDone())
{
it.next();
it.currentSegment(tab);
}
}
public static void main(String[] args)
{
Quadrillage quadrillage = new Quadrillage(new Complex(1, 5), new Complex(5, 1), 5, 5);
quadrillage.methodeQuiPlante();
} |
Partager