31 lines
640 B
Java
31 lines
640 B
Java
|
|
/**
|
|
* Beschreiben Sie hier die Klasse Gerade.
|
|
*
|
|
* @author (Ihr Name)
|
|
* @version (eine Versionsnummer oder ein Datum)
|
|
*/
|
|
public class Gerade
|
|
{
|
|
double m;
|
|
double c;
|
|
public Gerade(double _m, double _c){
|
|
m = _m;
|
|
c = _c;
|
|
}
|
|
|
|
public Gerade (Punkt P1, Punkt P2){
|
|
// m und c berechnen
|
|
m = (P1.y - P2.y)/(P1.x - P2.x);
|
|
c = P1.y - m * P1.x;
|
|
}
|
|
public Punkt schneide (Gerade h){
|
|
double x = (h.c - c ) / (m - h.m);
|
|
double y = m * x + c;
|
|
return new Punkt(x, y);
|
|
}
|
|
public String toString(){
|
|
return "y = " + m + " * x + " + c;
|
|
}
|
|
}
|