Hey Leutz;
habe ein Problem. Ich soll folgende Aufgabe lösen.
1. Entwickle einen Algorithmus, um den Punkt auszugeben, der am weitesten rechts liegt.
2. Löse programmtechnisch folgende Teilaufgaben:
a) berechne alle Ecken des umschließenden Rechtecks eines Polygons
b) ermittle die kürzeste Verbindung der miteinander verbundenen Punkte des Polygons
c) ermittle den Punkt, der am dichtesten am Schwerpunkt liegt.
Gib die Ergebnisse jeweils aus.
jetzt hänge ich an der ersten Aufgabe mit dem weitesten Punkt rechts. Ich finde ja den X-Wert raus, aber wie bekomm ich den dazugehörigen Y?
[JAVA=42]
public class Polygon {
public static void main(String[] args) {
double xmin, ymax,xmax,ymin, rechts;
xmin=0; ymax=0; xmax=0; ymin=0; rechts=0;
double [][] polygon =
{
{0 , 0},
{1 , 4},
{2 , 2},
{3 , 3},
{4 , 1}
};
rechts= polygon[1][0];
for (int i=1;i<polygon.length;i++) {
if (rechts < polygon [1])rechts=polygon[1];
}
System.out.println("Anzahl der Punkte: "+polygon.length);
for (int i=0; i< polygon.length;i++) {
double x = polygon[0];
double y = polygon[1];
if (xmax < polygon[0])xmax = polygon[0]; //Bounting Box rechts oben
if (ymax < polygon[1])ymax = polygon[1]; //Bounting Box rechts unten
if (xmin > polygon[0])xmin = polygon[0]; //Bounting Box links oben
if (ymin > polygon[1])ymin = polygon[1]; //Bounting Box links unten
}
System.out.println("Rechts: "+rechts);
System.out.println("Bounting Box rechts oben X;Y : "+xmax+" ; "+ymax);
System.out.println("Bounting Box rechts unten X;Y : 0.0 ; "+ymax);
System.out.println("Bounting Box links oben X;Y : "+xmin+" ; "+ymax);
System.out.println("Bounting Box links unten X;Y : "+xmin+" ; "+ymin);
}
}
[/code]
habe ein Problem. Ich soll folgende Aufgabe lösen.
1. Entwickle einen Algorithmus, um den Punkt auszugeben, der am weitesten rechts liegt.
2. Löse programmtechnisch folgende Teilaufgaben:
a) berechne alle Ecken des umschließenden Rechtecks eines Polygons
b) ermittle die kürzeste Verbindung der miteinander verbundenen Punkte des Polygons
c) ermittle den Punkt, der am dichtesten am Schwerpunkt liegt.
Gib die Ergebnisse jeweils aus.
jetzt hänge ich an der ersten Aufgabe mit dem weitesten Punkt rechts. Ich finde ja den X-Wert raus, aber wie bekomm ich den dazugehörigen Y?
[JAVA=42]
public class Polygon {
public static void main(String[] args) {
double xmin, ymax,xmax,ymin, rechts;
xmin=0; ymax=0; xmax=0; ymin=0; rechts=0;
double [][] polygon =
{
{0 , 0},
{1 , 4},
{2 , 2},
{3 , 3},
{4 , 1}
};
rechts= polygon[1][0];
for (int i=1;i<polygon.length;i++) {
if (rechts < polygon [1])rechts=polygon[1];
}
System.out.println("Anzahl der Punkte: "+polygon.length);
for (int i=0; i< polygon.length;i++) {
double x = polygon[0];
double y = polygon[1];
if (xmax < polygon[0])xmax = polygon[0]; //Bounting Box rechts oben
if (ymax < polygon[1])ymax = polygon[1]; //Bounting Box rechts unten
if (xmin > polygon[0])xmin = polygon[0]; //Bounting Box links oben
if (ymin > polygon[1])ymin = polygon[1]; //Bounting Box links unten
}
System.out.println("Rechts: "+rechts);
System.out.println("Bounting Box rechts oben X;Y : "+xmax+" ; "+ymax);
System.out.println("Bounting Box rechts unten X;Y : 0.0 ; "+ymax);
System.out.println("Bounting Box links oben X;Y : "+xmin+" ; "+ymax);
System.out.println("Bounting Box links unten X;Y : "+xmin+" ; "+ymin);
}
}
[/code]