/* Klasse Point Version 1.0 Ein Point enthŠlt einen y und x Wert Konstruktor Paramter: float x float y Methoden: makePointIn = generieren eines neuen Punktes wird von cobaea scandens nicht benutzt distanceTo = berechnet Abstand eines neuen Pnktes wird von cobaea scandens nicht benutzt testAusgabeFenster = PrŸft ob sich nPunkt im Ausgabefeld befindet intersection = Gibt Schnittpunkt der Strecke teilPunkt-nPunkt mit dem AusgabeFenster zurŸck */ class Point { float x = 0; float y = 0; Point(float posX, float posY) { x=posX; y=posY; } //----------Methoden------------------------------------------------ //---------generieren eines neuen Punktes von diesem Punkt aus Point makePointIn(float w, float d) // wird nicht benštigt, da immer von Kanntenwinkel abhŠngig { float newXPosition = x +(cos(w)*d); float newYPosition = y +(sin(w)*d); return new Point(newXPosition,newYPosition); } //----------berechnet Abstand zweier Punkte float distanceTo(Point other) { float deltaX = this.x - other.x; float deltaY = this.y - other.y; return sqrt(deltaX*deltaX + deltaY*deltaY); } //-----------PrŸft ob sich nPunkt im Ausgabefeld befindet int testAusgabeFenster () // gibt 1 zurŸck falls Punkt im Ausgabefeld lieget, sonst 0 { int positionPunkt = 0; if (x > ausgabeXpos && x < fensterX-abstand) { if (y > abstand && y < fensterY - abstand) { positionPunkt = 1; } } return(positionPunkt); } //------------Gibt Schnittpunkt der Strecke teilPunkt-nPunkt mit dem AusgabeFenster zurŸck Point intersection (Point teilPunkt) // prŸft 8 Felder ausserhalb des Ausgabefensters { // schneidet mit den Geraden des Fensters, wenn nštig mit beiden Point teilp = teilPunkt; // Punkt ausserhalb des Fensters float x1 = ausgabeXpos; // linke Kannte des Fensters float x2 = fensterX-abstand; // rechte Kannte des Fensters float y1 = abstand; // obere Kannte des Fensters float y2 = fensterY - abstand; // untere Kannte des Fensters float x3 = 0; // x-Koordinate des Schnittpunktes mit dem Ausgabefenster float y3 = 0; // y-Koordinate des Schnittpunktes mit dem Ausgabefenster if (x < x1) { if (y < y1) { x3 = x1; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); if (y3 < y1) { y3 = y1; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } } if (y > y2) { x3 = x1; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); if (y3 > y2) { y3 = y2; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } } if (y > y1 && y < y2) { x3 = x1; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); } } if (x > x2) { if (y < y1) { x3 = x2; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); if (y3 < y1) { y3 = y1; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } } if (y > y2) { x3 = x2; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); if (y3 > y2) { y3 = y2; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } } if (y > y1 && y < y2) { x3 = x2; y3 = teilp.y + (x3 - teilp.x)*(y-teilp.y)/(x-teilp.x); } } if (x > x1 && x < x2) { if (y < y1) { y3 = y1; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } if (y > y2) { y3 = y2; x3 = teilp.x + (x-teilp.x)/(y-teilp.y)*(y3 - teilp.y); } } Point nP = new Point(x3,y3); // gibt Schnittpunkt zurŸck return (nP); } }