Skip to content

Instantly share code, notes, and snippets.

@3c7
Created April 15, 2015 07:57
Show Gist options
  • Save 3c7/68487646f9645d640943 to your computer and use it in GitHub Desktop.
Save 3c7/68487646f9645d640943 to your computer and use it in GitHub Desktop.
Praktomat Übung 2 Aufgabe 1
/**
* Created by Nils on 13.04.2015.
*/
public abstract class Koerper implements Skalierbar {
// Bezugspunkt
public Punkt p;
public void verschiebe(double dx, double dy, double dz) {
this.p = new Punkt(p.x + dx, p.y + dy, p.z + dz);
}
public abstract void skaliere(double a);
public abstract boolean enthaelt(Punkt a);
public abstract double volumen();
public abstract double oberflaeche();
public abstract double durchmesser();
static boolean between(double a, double min, double max) {
if (a >= min && a <= max) return true;
return false;
}
}
/**
* Created by Nils on 13.04.2015.
*/
public class Kugel extends Koerper implements Skalierbar {
// Radius
private double r;
// Konstruktor
public Kugel(Punkt p, double r) {
this.p = new Punkt(p.x, p.y, p.z);
this.r = r;
}
// Methoden
public void skaliere(double a) {
this.r = this.r * a;
}
public boolean enthaelt(Punkt a) {
if (Math.sqrt(Math.pow(this.p.x - a.x,2) + Math.pow(this.p.y - a.y,2) + Math.pow(this.p.z - a.z,2)) <= this.r)
return true;
return false;
}
public double volumen() {
return (4.0 / 3.0) * Math.PI * Math.pow(this.r, 3);
}
public double oberflaeche() {
return 4 * Math.PI * Math.pow(this.r, 2);
}
public double durchmesser() {
return 2 * this.r;
}
}
/**
* Created by Nils on 13.04.2015.
*/
public class Punkt {
protected double x, y, z;
public Punkt(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
}
/**
* Created by Nils on 13.04.2015.
*/
public class Quader extends Koerper implements Skalierbar {
// Breite, Tiefe, Höhe
private double b, t, h;
public Quader(Punkt p, double b, double t, double h) {
this.p = new Punkt(p.x, p.y, p.z);
this.b = b;
this.t = t;
this.h = h;
}
// Methoden
public void skaliere(double a) {
this.b = this.b * a;
this.t = this.t * a;
this.h = this.h * a;
}
public boolean enthaelt(Punkt a) {
if (between(a.x, this.p.x, this.p.x + this.b) && between(a.y, this.p.y, this.p.y + this.t) && between(a.z, this.p.z, this.p.z + this.h))
return true;
return false;
}
public double volumen() {
return this.b * this.t * this.h;
}
public double oberflaeche() {
return 2 * this.b * this.t + 2 * this.b * this.h + 2 * this.t * this.h;
}
public double durchmesser() {
return Math.sqrt(Math.pow(this.b, 2) + Math.pow(this.t, 2) + Math.pow(this.h, 2));
}
}
/**
* Created by Nils on 13.04.2015.
*/
public interface Skalierbar {
void skaliere(double a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment