Hello everbody,
I’m currently working on a project where I need to find a specific distance between a point and a line.
To do that, I draw the line in green and start scanning each pixel around the point. This can take however long it wants to, I don’t need this part of the code to run fast. However I’m currently doing this by going in a rectangular fashion around the starting point:
int d1 = 1;
int moving_x = floor(supportpoints[i][2]);
int moving_y = floor(supportpoints[i][3]);
int change = +1;
color c = export_graphic.get(moving_x, moving_y);
while ((c >> 8 & 0xFF) - 100 != supportpoints[i][4]) {
for (int count = 0; count < d1; count++) {
moving_x = moving_x + change;
c = export_graphic.get(moving_x, moving_y);
if ((c >> 8 & 0xFF) - 100 == supportpoints[i][4]) {
break;
}
}
if ((c >> 8 & 0xFF) - 100 == supportpoints[i][4]) {
break;
}
for (int count = 0; count < d1; count++) {
moving_y = moving_y + change;
c = export_graphic.get(moving_x, moving_y);
if ((c >> 8 & 0xFF) - 100 == supportpoints[i][4]) {
break;
}
}
if ((c >> 8 & 0xFF) - 100 == supportpoints[i][4]) {
break;
}
d1 = d1 + 1;
change = -change;
}
d1 = floor(dist(floor(supportpoints[i][2]), floor(supportpoints[i][3]), moving_x, moving_y));
But the corners will relatively fast be way further out than the sides compared to a circle with equal distance to the surcomference.
I thought about locating the checked pixel useing sin and cos and an angle and increasing the distance for each revolution, however it’s (for long distances) not garanteed to check each pixel on the screen and since the line I’m looking for is only 1 pixel in width it might be missed.
TLDR: Looking for the closest colored pixel in a circle around a point
Does anybody have an working algorithm or any ideas for this?
Greetings Max
PS: I knnow the flooring at the end is not nice but I will look in to that once the distnace thing is done.