Raster to Vecor Algorythm?

BlitzPlus Forums/BlitzPlus Programming/Raster to Vecor Algorythm?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi there.

I guess that the radar screen thing will work, but I would like you guys to take a look a the algo that I have already implemented.
Also, I would like to explain why it failed.
So, *maybe* you guys could help me find a way to fix this very simplistic algorythm.
(Remember: It´s got to be don on the fly, so the less sin/cos/sqr/floats I use, the better).

[CODE]
Algorythm Make Lines List is
clear Result List
backToFirstVertex <-- false
repeat
L <-- 0
v0x, v0y <-- Find The first Vertex of The Polygon
vx, vy <-- Find Position of Closest Pixel
d0 <-- Find direction of Closest Pixel
d <-- d0
while d is same as d0
vx, vy <-- Find Position of Closest Pixel
d <-- Find direction od Closest Pixel
if (vx, vy) is same as (v0x, v0y)
{
backToFirstVertex <-- true
Exit While
}
add 1 to L
wend
if backToFirstVertex
{
exit repeat
}
forever
;
; Got here, means that it either got back to
; the starting point
; or has changed its original direction
;
Add to Vertex List: v0x, v1x, d, L
return

Algorythm Find Position of Closest Pixel is
if current position plus (0, -1) is not empty
{
result <-- current position plus (0, -1)
}
if current position plus (+1, -1) is not empty
{
result <-- current position plus (+1, -1)
}
if current position plus (+1, 0) is not empty
{
result <-- current position plus (+1, 0)
}
if current position plus (+1, +1) is not empty
{
result <-- current position plus (+1, +1)
}
if current position plus (0, +1) is not empty
{
result <-- current position plus (0, +1)
}
if current position plus (-1, +1) is not empty
{
result <-- current position plus (-1, +1)
}
if current position plus (-1, 0) is not empty
{
result <-- current position plus (-1, 0)
}
if current position plus (-1, -1) is not empty
{
result <-- current position plus (-1, -1)
}
return


Algorythm Find direction of Closest Pixel is
if current position plus (0, -1) is not empty
{
result <-- 0
}
if current position plus (+1, -1) is not empty
{
result <-- 1
}
if current position plus (+1, 0) is not empty
{
result <-- 2
}
if current position plus (+1, +1) is not empty
{
result <-- 3
}
if current position plus (0, +1) is not empty
{
result <-- 4
}
if current position plus (-1, +1) is not empty
{
result <-- 5
}
if current position plus (-1, 0) is not empty
{
result <-- 6
}
if current position plus (-1, -1) is not empty
{
result <-- 7
}
return

[/CODE]

Of course the implementation is more complicated as it has to check if the target position is inside of the (0, 0) - (49, 49) bounding rectangle among other things.

The algorythm above actualy works, but has the undesirable effect of finding the "smallest lines".
This will explain the problem better:

[CODE]
.XXXX.....
.....XXXX.
..........

Would be considered to be two separeted 4 pixel long lines.
See?

Then I figured: well, while the last line´s lenght is same as the previous one, then this line is still the same line.

But I also figured that there are lines that look like this:

.XXXX.....
.....X....
......XXXX
[/CODE]

So, what do you think I could do?
I believe that the answer is not too far from what I am doing, but I just have not been able to pull it off my head :(
Or it could not be that simple, at all...

Any ideas?

Thanks,

Rui Barbosa Jr.