Thread: Drawing triangles in C#

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    Drawing triangles in C#

    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?

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    14
    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

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    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.

    Code:
    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
    Last edited by mike_g; 03-15-2008 at 08:51 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing HBITMAP into CWnd, Acquired from "screenshot"
    By DeusAduro in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2009, 03:41 PM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  3. How to do double buffing with win32 drawing?
    By Josh Kasten in forum Windows Programming
    Replies: 2
    Last Post: 03-27-2004, 12:02 AM
  4. Need help drawing triangles (C)
    By Belvedeer84 in forum C Programming
    Replies: 6
    Last Post: 10-02-2003, 02:00 PM
  5. Drawing triangles
    By TonyLFL in forum C++ Programming
    Replies: 7
    Last Post: 06-02-2002, 09:51 AM