algorithms-for-computing-li.../LinearRegressionTool/src/main/java/model/Line.java

177 lines
3.5 KiB
Java

package model;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 12.06.2017.
*/
public class Line {
private final Double MAX = 9999d;
private final Double MIN = -9999d;
private Double m;
private Double b;
private Double x1;
private Double x2;
private Double y1;
private Double y2;
private String id;
/**
* Konstruktor
* @param m Steigung
* @param b y-Achsenabschnitt
* @param id id
*/
public Line(double m, double b, String id) {
this.m = m;
this.b = b;
this.x1 = MIN;
this.y1 = (MIN * m) + b;
this.x2 = MAX * 0.5;
this.y2 = ((MAX * 0.5) * m) + b;
this.id = id;
}
/**
* Konstruktor
* @param m Steigung
* @param b y-Achsenabschnitt
*/
public Line(double m, double b) {
this.m = m;
this.b = b;
this.x1 = MIN;
this.y1 = (MIN * m) + b;
this.x2 = MAX * 0.5;
this.y2 = ((MAX * 0.5) * m) + b;
}
/**
* Konstruktor
* @param x1 x-Koordiante des Startpunkts
* @param x2 x-Koordinate des Endpunkts
* @param y1 y-Koordinate des Startpunkts
* @param y2 y-Koordinate des Endpunkts
*/
public Line(double x1, double x2, double y1, double y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.m = (y2 - y1) / (x2 - x1);
this.b = y2 - (x2 * m);
}
/**
* @return Steigung der Gerade
*/
public Double getM() {
return m;
}
/**
* @param m Steigung der Gerade
*/
public void setM(double m) {
this.m = m;
}
/**
* @return y-Achsenabschnitt der Gerade
*/
public Double getB() {
return b;
}
/**
* @param b y-Achsenabschnitt der Gerade
*/
public void setB(double b) {
this.b = b;
}
/**
* @return id der Gerade
*/
public String getId() {
return id;
}
/**
* @param id id der Gerade
*/
public void setId(String id) {
this.id = id;
}
/**
* @return x-Koordiante des Startpunkts
*/
public Double getX1() {
return x1;
}
/**
* @return x-Koordiante des Endpunkts
*/
public Double getX2() {
return x2;
}
/**
* @return y-Koordiante des Startpunkts
*/
public Double getY1() {
return y1;
}
/**
* @return y-Koordiante des Endpunkts
*/
public Double getY2() {
return y2;
}
/**
* Setzt die Koordianten des Segments. Aus dem Segment wird eine Gerade berechnet.
* @param x1 x-Koordiante des Startpunkts
* @param y1 y-Koordiante des Endpunkts
* @param x2 x-Koordinate des Startpunkts
* @param y2 y-Koordinte des Endpunkts
*/
public void setEndPoints(double x1, double y1, double x2, double y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.m = (y2 - y1) / (x2 - x1);
this.b = y2 - (x2 * m);
}
/**
* Vergleich einzelner Geradern
* @param other zu vergleichende Gerade
* @return <code>true</code> falls die Geraden Gleich sind
*/
public boolean equals(Line other) {
if (other.getM() == this.getM() && other.getB() == this.getB()) {
return true;
} else {
return false;
}
}
}