OK so here deal: I am trying to make a ray casting engine in java because I got bored but it produces this wonky effect especially when nearing edges(See images). I know there is a cos correction method and I also know regular intervals between rays are evil. I have fixed both of these common issues with the following solutions: The first one sets the ray intervals such that each ray is being cast for a single strip of width on the screen as opposed to a constant increment between angles of rays cast.directionSpray: a double[] storing the spray to be used so that rays are not cast at regular intervals.Ray class: constructor Ray(x,y,d,map) automatically casts a ray from (x,y) in direction d until it hits a block in map. the distance is regularly increased as the ray moves forward and getScan() returns a 1 pixel wide strip of the image of the block the ray has hit.The first method is intended to properly set up directionSpray:public void setFOV(double angle){    directionSpray=new double[w];    double x=Math.cos(angle),y=Math.sin(angle);    double totalDist=y*2;    double dydi=totalDist/w;    for(int i=0;i<w;i++){        directionSpray[i]=Math.atan(y/x);        y-=dydi;    }}This second one is the draw method in the screen class which casts the rays and uses the cos correction formula to fix the distances:public void draw(Graphics g){    for(int i=0;i<w;i++){        Ray cast=new Ray(p.getX(),p.getY(),p.getD()+directionSpray[i],map);        int height=400-(int)(cast.getDist()*Math.cos(directionSpray[i]));        g.drawImage(cast.getScan(),i,(h-height)/2,1,height,null);    }}I don't know why it goes wonky.
Why does my raycaster distort when it does?
rendering;algorithm;ray