package Geometria; public class Reta { private Ponto p1,p2; public Reta(double x1,double y1,double x2,double y2) { p1 = new Ponto(x1,y1); p2 = new Ponto(x2,y2); } public Ponto getP1() { return p1; } public Ponto getP2() { return p2; } public static double f(Reta r, double x) { // retorno eŽ y em funcao fr de x // (Y - y1) / (y2-y1) = (X - x1)/(x2 - x1) return ( r.getP1().getY() + ( ( (r.getP2().getY()-r.getP1().getY()) * (x - r.getP1().getX()) ) / (r.getP2().getX()-r.getP1().getX()) ) ); } private static double coefLin(Reta r) { // coeficiente linear: onde esta y quando x eŽ0 // na forma: y + CoefAng x + CoefLin = 0 return f(r,0); } private static double coefAng(Reta r) { // y = x . & onde & = (y2-y1) / (x2-x1) // na forma: 1.y + CoefAng.x + CoefLin = 0 return ( ( r.getP2().getY() - r.getP1().getY() ) / ( r.getP2().getX() - r.getP1().getX() ) ); } private static double D(Reta r1, Reta r2) { return ( coefAng(r2) - coefAng(r1) ); } private static double Dx(Reta r1, Reta r2) { return ( ( coefLin(r1)*coefAng(r2) ) - ( coefLin(r2)*coefAng(r1) ) ); } private static double Dy(Reta r1, Reta r2) { // sempre 1.y return ( coefLin(r1) - coefLin(r2) ); } public static Ponto intercessao (Reta r1, Reta r2) { return new Ponto((Dx(r1,r2)/D(r1,r2)), (Dy(r1,r2)/D(r1,r2))); } public void info() { System.out.println(" Reta com P1 e P2: "); p1.info(); p2.info(); System.out.println("Coef.Lin: "+coefLin(this)); System.out.println("Coef.Ang: "+coefAng(this)); } }