Drawing triangles in C# [Archive] - C Board

PDA

View Full Version : Drawing triangles in C#


John_L
03-14-2008, 03:24 PM
So I whipped up the gesture based drawing stuff myself. But what's the best way to go about drawing Triangles in C#? If I record mouse movements and store the coordinates, I guess I need to draw three lines? But than how do I fill them in with colour? I'll probably write a "triangle" class. But any suggestions or ideas?

Rainbowinblack
03-15-2008, 05:39 AM
You can use Graphics.DrawPoligon and Graphics.FillPoligon
both Method gets an array of Points , if there are 3 points - it'll make a triangles

can you send me the code for the gesture based drawing "stuff"?
i'm trying for a week or so to make something like that ...but i cant find how to redraw the forms...

Thanks

mike_g
03-15-2008, 08:48 AM
If theres a built in method it will be easiest to use that. If you want to code your own filled triangle heres some very rough pseudo code for it. Having your own line drawing algo may help too.

order points from highest to lowest
get xa decrement for each y iteraion
get xb increment for each y iteration
for(y = highest; y > mid; y--)
{
line(xa, y, xb, y);
xa-= xa_inc;
xb+= xb_inc;

}
repeat for mid to base