Sign in to follow this  

Line drawing problem

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to implement a thick line drawing and i'm encountering a little problem. (That i think its not aliasing) see the following image that's the result of the algorithm at various angulations : http://img99.imageshack.us/img99/9480/whatzy.png As you see, as we reach the 45° angulation the line begin to look REALLy weird while its fine at more acute angulations, or at 45° precise. This is how I calculate the 4 points of the quad Single L = (Single)Math.Sqrt(Math.Pow((PosizioneFine.X - Posizione.X), 2) + Math.Pow((PosizioneFine.Y - Posizione.Y), 2)); Single X = (PosizioneFine.X - Posizione.X) / L; Single Y = (PosizioneFine.Y - Posizione.Y) / L; And use the X and Y multiplied per Width to create the 2 new points. Any clues?

Share this post


Link to post
Share on other sites
The line to be able of have a width is drawed as a series of 2 triangles with the vertices calculated as follow

A (X,Y,0)
B (XEnd, YEnd, 0)

Single L = (Single)Math.Sqrt(Math.Pow((PosizioneFine.X - Posizione.X), 2) + Math.Pow((PosizioneFine.Y - Posizione.Y), 2));
Single XVAR = (PosizioneFine.X - Posizione.X) / L;
Single YVAR = (PosizioneFine.Y - Posizione.Y) / L;

C (X - (YVAR * Width), Y + (XVAR * Width))
D (XEnd - (YVAR * Width), YEnd + (XVAR * Width))

the triangles are

ABC, BDC

Share this post


Link to post
Share on other sites
Yes, they are B and A and yes i'm drawing them in the correct order (otherwise they would get culled :P)
Well that's strange then. Why it gives those artefacts? ç_ç

Share this post


Link to post
Share on other sites
On higher width 5+, the problem isn't present.
Between 4 and 5 the problem is not much visible.
On 1 or 3 width the problem is there.

For the 1 width I can use directly a simple DirectX line, but for 2 and 3? :P

Share this post


Link to post
Share on other sites
Quote:
For the 1 width I can use directly a simple DirectX line, but for 2 and 3?

At low Widths, Width*sin(angle) and Width*cos(angle) may be less than 1 pixel and you're getting degenerate triangles. You can add a check something like:

if( XVAR < 1 ) XVAR = 1;
if( YVAR < 1 ) YVAR = 1;

That still won't be perfect, but it'll be close.

Share this post


Link to post
Share on other sites
Quote:
if XVar and YVar are always 1 if under 1 you will get always the same diagonal 45° line in those cases.

That's true at angles close to 45. But you're trying to draw floating-point values in an integer world. You have to compensate for displacements of less than a pixel somehow, and it will be a compromise.

if( XVAR < 0.5f ) XVAR = 0;
else if(XVAR < 1 ) XVAR = 1;
.. or something similar


EDIT: simultaneous posts - you're welcome.

Share this post


Link to post
Share on other sites

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this