import javafx.scene.canvas.GraphicsContext; import javafx.scene.text.TextAlignment; import javafx.geometry.VPos; public class Takisti3{ int x1, y1, x2, y2; int r=5; int ringiraadius=20; double takistus; public Takisti3(int ux1, int uy1, int ux2, int uy2, double takistus){ if(ux1==ux2 || uy1==uy2){ x1=ux1; y1=uy1; x2=ux2; y2=uy2; this.takistus=takistus; } else { throw new RuntimeException( "Pole horisontaalne ega vertikaalne"); } } public void joonista(GraphicsContext g){ g.setTextAlign(TextAlignment.CENTER); g.setTextBaseline(VPos.CENTER); g.fillText(String.valueOf(takistus), (x1+x2)/2, (y1+y2)/2); g.strokeOval(x1-r, y1-r, 2*r, 2*r); g.strokeOval(x2-r, y2-r, 2*r, 2*r); g.strokeOval((x1+x2)/2-ringiraadius, (y1+y2)/2-ringiraadius, 2*ringiraadius, 2*ringiraadius); int dx=x2-x1; int dy=y2-y1; double pikkus=Math.sqrt(dx*dx+dy*dy); double yx=dx/pikkus; double yy=dy/pikkus; g.strokeLine(x1+r*yx, y1+r*yy, (x1+x2)/2-ringiraadius*yx, (y1+y2)/2-ringiraadius*yy); g.strokeLine(x2-r*yx, y2-r*yy, (x1+x2)/2+ringiraadius*yx, (y1+y2)/2+ringiraadius*yy); } }