[gameprogrammer] Re: Vector Graphics (seconded request)

I'm reminded of another problem I encountered (I've been busy with 
school, thus unable to continue work on the project yet), and that was 
with parallel lines.  If I draw one line at exactly one pixel's width 
from point A to point B, then another line (one pixel's width again) 
from/to points exactly on pixel below the previous ones, I SHOULD end up 
with what looks like one line two pixels wide.  However, when I zoom in 
closer to the image, there occur several zoom levels where the alignment 
or precision is insufficient to draw them correctly, and I sometimes see 
a gap of a pixel or more in between the two lines.

My question is how should I be handling this differently in order to 
avoid this problem?  Perhaps should I be drawing all alleged "lines" 
merely as extremely narrow rectangles?  Is that how applications such as 
Illustrator and/or Flash/Shockwave work?

Thanks for the input.

--Scott

Bob Pendleton wrote:
> On Tue, 2004-11-02 at 08:44, Scott Harper wrote:
> 
>>I also have a project (in Java) where I'm trying to create vector 
>>graphics, but my problem is in zooming in and out, I always seem to get 
>>inaccuracies at some level.  Like, if two solid lines butt up against 
>>each other (at a right angle), at SOME level of zooming in and drawing 
>>the lines you can see a space between the two.
>>
>>I wonder, perhaps if this is simply an inaccuracy in Java's standard 
>>Graphics2D routines for drawing/scaling and how the numbers involved get 
>>rounded down to screen coordinates.  
> 
> 
> Yep is is a problem with the nature of all numbers used by computers.
> Nothing specific to Java, but a general problem with trying to represent
> an infinity of different values using a fixed number of bits. No matter
> how many bits you use, at some point it isn't enough.
> 
> 
>>Needless to say I'd rather not have 
>>to implement my OWN drawing routines when there exist ones already.
> 
> 
> Wouldn't help unless you write your own arbitrary precision number
> package and do all the arithmetic using it.
> 
> They way around this is simple. Instead of drawing two line segements
> where you know that the end of one is mathematically on the other line,
> you draw three line segments using a total of 4 points so that the line
> segments are always abutted not matter what error occurs.
> 
>         *
>         |
>         |
>  *------*-------*
> 
> In the diagram the stars represent the points that mark the end points
> of the line segments. Since the central point is shared by 3 line
> segments the line segments will terminate on that point no matter how
> it's location jitters around due to numerical errors.
> 
> If you don't share the point this way, then the end of the vertical line
> may or may not wind up on the same pixel as a the pixel on the vertical
> line where you think it should be.
> 
> Remember, in a computer there are not perfect point and on a screen
> there are no lines. Only approximations. The difference between a
> geometric line and a line on a computer screen is much like the
> difference between a potato and a politician. Some times you find a
> potato that looks like a politician, but politicians are never make into
> french fries. :-) I know that was completely absurd, but... really a
> geometric line is infinitely thin and passes through mathematical points
> that can only be described using infinite precision numbers. Computer
> lines are made up of little squares, called pixels, that are so big you
> can see them with your eyes. And, the position of a pixel on a screen
> can be described in 32 bits, or fewer, hardly infinite precision.
> 
> A good understanding of mathematics really hurts you when you are first
> learning computer graphics. After that, it becomes invaluable.
> 
>               Bob Pendleton
> 
> 
>>Anyway, please answer Florian's question before addressing mine.
>>
>>--Scott
>>
>>Florian Hufsky wrote:
>>
>>>Hi,
>>>
>>>i'm thinking about implementing a 2d vector graphics engine (sdl+opengl).
>>>Before spending hours searching with google, I wanted to ask if there 
>>>are some Standard Resources (eg SVG).
>>>And are there Reference Implementations or something? Maybe someone who 
>>>found out how the FlashPlayer handles stuff.
>>>
>>>Thanks a lot,
>>>Florian Hufsky
>>
>>
>>---------------------
>>To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>>



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: