My class Line should draw itself from point1 (x1/y1) to point2 (x2/y2). Therefore I have used the constructor, but everytime I calculate dy/dx the result is 0.0, but I don't know why. Is it a problem with double?
But except of dx and dy all values are 0.0, when I tested it with:
x1=60
y1=40
x2=200
y2=150
Why?
public Line(int x1, int y1, int x2, int y2) { int dx = x2-x1; int dy = y2-y1; //this is to make dx and dy positive, if they are negative if(dx<0)dx-=2*dx; if(dy<0)dy-=2*dy; //This is for test. The code is much longer than this, but I wanted to find the mistake, so I wanted to see all //results like this: System.out.println("dx: "+dx); System.out.println("dy: "+dy); System.out.println("m: "+dy/dx); System.out.println("arctan dy/dx: "+Math.atan(dy/dx)); System.out.println("arctan to degree: "+Math.toDegrees(Math.atan(dy/dx))); }