How do I create a diagonal line with C, I want to get four coordinates and create the most perfect diagonal line, but I want to draw it pixel by pixel. The problem is I don't know how to do this when the image is not "a square".
What I have till now:
// try one
for (int i = ystart, j = xstart; i < yend && j < xend; i++, j++)
{
printf("%d ", distance);
image[i][j].rgbtRed = 255;
image[i][j].rgbtGreen = 255;
image[i][j].rgbtBlue = 255;
}
// try two
int distance = sqrt(pow(xend - xstart, 2) + pow(yend - ystart, 2));
for (int w = 0, i = ystart, j = xstart; w < distance; w++)
{
image[i][j].rgbtRed = 255;
image[i][j].rgbtGreen = 255;
image[i][j].rgbtBlue = 255;
i++;
j++;
if (i > yend - 1 || j > xend - 1)
{
break;
}
}
// I also have a two-dimensional (the image) array and width and height of the image, the image I'm using is 600x400, completely black and I want a diagonal line based on the parameters of the function