I have a 2 dimensional space and a ray in that space.
I need to get the coordinates of the red rectangles in the order of the numbers.
My attempt:
I have the starting of the ray which is a double.
I have a value yaw which is the direction in radians.
The I did this to get the coordinate of the next red square.
double tanyaw = Math.tan(yaw);
if ((int) (x + 1/tanyaw) == (int) x) {
x += 1/tanyaw;
z += Math.signum(tanyaw);
} else {
x += Math.signum(tanyaw);
z += tanyaw;
}
However:
That was with yaw = 3*pi/8
note that the line was made in a drawing program and is only approximatly correct.