2013-03-25 3 views
16

Ich habe einige Fragen zu Polygonen mit Punkten vom Doppeltyp ... Was ich zu tun habe, erhält Punkte, erzeuge das Polygon und teste dann, ob 1 Betonpunkt innerhalb des Polygons liegt oder nicht .Polygone mit Doppelkoordinaten

so kwnow ich, dass in Java gibt es eine Klasse ist, die so genannte Polygon und wird wie das verwendet: (Dreieck)

int valoresX[] = { 100, 150, 200 }; 
int valoresY[] = { 100, 200, 100 }; 
int n = valoresX.length; 
Polygon city= new Polygon(valoresX,valoresY,n); 

Aber meine "Polygone" hat der "Double" Typ sein, nicht „int "(einfaches Beispiel)

Double valoresX[] = { 1000.10, 150.10, 200.10 }; 
Double valoresY[] = { 100.10, 200.10, 100.10 }; 

In meinem Projekt brauche ich nicht wirklich auf einem Applet oder ähnlich zu malen, ich muß nur berechnen, wenn der Punkt innerhalb oder nicht.

Also meine Frage ist:

jede mögliche Weise Ist Polygone mit Doppel coordenates zu tun, dass, wenn der Punkt (double) calcultate erlauben innerhalb des Polygons ist oder nicht?

Danke für alle !!!

Shudy

Antwort

17

Sie können dies mit Path2D.Double:

Path2D path = new Path2D.Double(); 

path.moveTo(valoresX[0], valoresY[0]); 
for(int i = 1; i < valoresX.length; ++i) { 
    path.lineTo(valoresX[i], valoresY[i]); 
} 
path.closePath(); 

Siehe auch diese Frage:

Implementing Polygon2D in Java 2D

+0

Zunächst einmal vielen Dank für alle, und die schnelle Antwort! Ich werde es versuchen, und sehen, ob es zu meinem Projekt funktioniert;) Danke! Shudy – Shudy

+1

Getestet, und funktioniert wirklich gut !!! Vielen Dank! – Shudy