Aufgabe 11
Aufgabe 11.a
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class PointF { public float x; public float y; public PointF(float x, float y) { this.x = x; this.y = y; } @Override public String toString() { return "{" + "x=" + x + ", y=" + y + '}'; } } |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class BahnUtil { /** * Gibt die Position bei Drehung um den momentanen Mittelpunkt center an, der sich selbst * bewegen kann und deshalb an die Methode übergeben werden muss * (verwenden Sie die Formeln aus Aufgabe 9) Zum Zeitpunkt t = 0 Sekunden * befindet er sich an der Position (center.x -r, center.y) */ public static PointF getPosition(PointF center, int umlaufdauer, float bahnradius, int time) { float dx = (float) (center.x + (-bahnradius * Math.cos(phi(time, umlaufdauer)))); float dy = (float) (center.y + (bahnradius * Math.sin(phi(time, umlaufdauer)))); return new PointF(dx, dy); } protected static float phi(int t, int tu) { return tu == 0 ? (float) (2f * Math.PI * t) : (float) (2f * Math.PI * t / tu); } } |
Aufgabe 11.b
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 | public abstract class Himmelskoerper { protected PointF position; protected float durchmesser; protected String name; protected Himmelskoerper(String name, PointF position, float durchmesser) { this.name = name; this.position = position; this.durchmesser = durchmesser; } abstract public PointF getPosition(int time); // gibt die Position zur Zeit time an. public String getName() { return name; } @Override public String toString() { return "Himmelskoerper{" + "position=" + position + ", durchmesser=" + durchmesser + ", name='" + name + '\'' + '}'; } } |
Aufgabe 11.c
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 | public abstract class RotierenderHimmelskoerper extends Himmelskoerper { protected Himmelskoerper center; protected int umlaufdauer; protected int bahnradius; protected RotierenderHimmelskoerper(String name, Himmelskoerper center, float durchmesser, int umlaufdauer, int bahnradius) { super(name, new PointF(-durchmesser,0), durchmesser); this.center = center; this.umlaufdauer = umlaufdauer; this.bahnradius = bahnradius; } public Himmelskoerper getCenter() { return center; } public void rotate(int time) { position = getPosition(time); } @Override public PointF getPosition(int time) { return BahnUtil.getPosition(center.position, umlaufdauer, bahnradius, time); } } |
3 4 5 6 7 8 9 10 11 12 13 14 15 | import de.bht.programming1.exercise11.geometrie.PointF; public class Sonne extends Himmelskoerper { protected Sonne(String name, PointF position, float durchmesser) { super(name, position, durchmesser); } @Override public PointF getPosition(int time) { return null; } } |
3 4 5 6 7 8 9 10 11 12 13 | public class Planet extends RotierenderHimmelskoerper { public Planet(String name, Himmelskoerper center, float durchmesser, int umlaufdauer, int bahnradius) { super(name, center, durchmesser, umlaufdauer, bahnradius); } @Override public String toString() { return "Name=" + name + ", Position=" + position + ", Planet=" + center.name + ", Sun Position= " + center.position; } } |
3 4 5 6 7 8 9 10 11 12 13 | public class Trabant extends RotierenderHimmelskoerper { protected Trabant(String name, Himmelskoerper center, float durchmesser, int umlaufdauer, int bahnradius) { super(name, center, durchmesser, umlaufdauer, bahnradius); } @Override public String toString() { return "Name=" + name + ", Position=" + position + ", Planet=" + center.name + ", Planet Position= " + center.position; } } |
3 4 5 6 7 8 9 10 11 12 13 | public class Trabant extends RotierenderHimmelskoerper { protected Trabant(String name, Himmelskoerper center, float durchmesser, int umlaufdauer, int bahnradius) { super(name, center, durchmesser, umlaufdauer, bahnradius); } @Override public String toString() { return "Name=" + name + ", Position=" + position + ", Planet=" + center.name + ", Planet Position= " + center.position; } } |
Aufgabe 11.d Missing.
Aufgabe 11.e
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 | public class Sonnensystem { private static final PrintWriter cout = new PrintWriter(System.out, true); public static void main(String[] args) { Sonne sun = new Sonne("Sonne", new PointF(0, 0), 1); Planet hugo = new Planet("Hugo", sun, 1020, 128, (int) 1e6); Planet otmar = new Planet("Otmar", sun, 3400, 333, (int) 1e7); Trabant luno = new Trabant("Luno", otmar, 98, 9, 6800); Trabant orba = new Trabant("Orba", otmar, 66, 11, 8900); int[] times = new int[]{0, 100, 1000, (int) 1e6, (int) 1e7, -100, -1000, (int) -1e6, (int) -1e7}; for (int i = 0; i < times.length; ++i) { cout.println(times[i]); hugo.rotate(times[i]); cout.println(hugo); otmar.rotate(times[i]); cout.println(otmar); luno.rotate(times[i]); cout.println(luno); orba.rotate(times[i]); cout.println(orba); cout.println(); } } } |
Leave a Reply