Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - Come si disegnano linee spesse?
Forum - Java - Come si disegnano linee spesse?

Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 1:00
Giovedì, 01/01/1970
Volevo sapere se c'è un modo per disegnare su un Graphics linee spesse.
Io ho trovato un modo, non credo sia il migliore :_doubt:, per farlo:
Disegnare due circonferenze e riempire il poligono con i vertici sulle tangenti :idea:.
Codice sorgente - presumibilmente Java

  1. //(x, y) = primo punto
  2. //(lx, ly) = secondo punto
  3. //s = spessore
  4. double d = Math.sqrt(Math.pow((lx - x), 2) + Math.pow((ly - y), 2));
  5. double kx  = (ly - y)*s/2/d;
  6. double ky  = (lx - x)*s/2/d;
  7. int PX[] = {(int)Math.round(x - kx),
  8.                 (int)Math.round(lx - kx),
  9.                 (int)Math.round(lx + kx),
  10.                 (int)Math.round(x + kx)};
  11. int PY[] = {(int)Math.round(y + ky),
  12.                 (int)Math.round(ly + ky),
  13.                 (int)Math.round(ly - ky),
  14.                 (int)Math.round(y - ky)};
  15. g.fillOval(x - s/2, y - s/2, s, s);
  16. g.fillOval(lx - s/2, ly - s/2, s, s);
  17. g.fillPolygon(PX, PY, 4);


Questo è l'unico modo:-?
Se non lo è qualcuno mi può suggerire qualcosa di più funzionale:-?

Grazie in anticipo per le risposte :)

PM
Avatar
Bonny (Member)
Expert


Messaggi: 437
Iscritto: 24/04/2009

Up
1
Down
V
Segnala al moderatore
Postato alle 14:57
Giovedì, 09/06/2011
esiste un metodo della classe Graphics2D che si chiama "setBasicStroke(BasicStroke var)"
a cui devi passare un oggetto di tipo BasicStroke(float n)
vedi esempio:http://www.java2s.com/Code/Java/2D-Graphics-GUI/Basicstrok ...'>http://translate.google.it/translate?hl=it&sl=en&u=http:// ...

pardon è questo il link: http://www.java2s.com/Code/Java/2D-Graphics-GUI/Basicstroke.htm - Bonny - 09/06/11 14:59
PM
Usa i commenti per chiedere spiegazioni o ringraziare le risposte.