# Line drawing problem

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

## 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 on other sites
Quote:
 use the X and Y multiplied per Width to create the 2 new points

Can you post the code? And can you clarify what "the quad" is that you're referring to?

##### 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 on other sites
Your English is better than my Italian. [wink] Is PosizioneFine = B and Posizione = A?

If so, the calc looks correct. Are you rendering triangles in order A-B-C and B-D-C?

##### 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 on other sites
Try setting Width to some large number so you can see the individual triangles. That should give you more information.

##### 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 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 on other sites
That would not work...
if XVar and YVar are always 1 if under 1 you will get always the same diagonal 45° line in those cases. :P

Anyway i'll try. :P

##### Share on other sites
Well, my assumption was wrong. Now it works perfectly even at 1 width, with that change you give me lol. :P

Thanks a lot!!!

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631423
• Total Posts
3000005
×