Thread: Making a teapot in C with triangles

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    5

    Making a teapot in C with triangles

    Hi

    i have an assignment where i have to draw a teapot using triangles, and are struggling with the part where i have to color it.

    Here is an link to the assignment https://fronter.com/uit/links/files....gave+3/p4.html

    I have managed to draw the teapot and translated it onto the screen. the part i need help with is making a bounding box for the triangle and coloring it.

    I've attached how my code looks so far.

    I would be grateful for any help i can get, but try to keep it simple because i am completly new to programming
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,557
    You do know that your link requires logging into the site, right?

    How about posting your include files as well?

    Jim

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    5
    Yeah, sorry, just tired.. I will attach it as a pdf, along with the include files.

    The teapot_data file is to big to attach, so i will remove som parts of it and call it teapot_data2. It contains all the triangles that makes the teapot.
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    I can't tell for sure, but it looks like you need an arbitrarily-oriented minimum bounding box1.

    Start by remembering that for a triange
    A = 1/2 b h.
    The height is not known explicitly if you don't have a right triangle, however it's not too hard to calculate if you can find the area of the triangle and use a little bit of geometry: Area of Triangles Without Right Angles.

    If you pick the longest side as your base, and know the area, solving for the height should be trivial. The bounding box will use the base as one side (and be, e.g. the "width" of the rectangle), while the height of the triangle will be the height of the bounding box. The other 3 sides should be fairly easy to figure out from there.

    1 Note, if you want an axis-aligned minimum bounding box, it's fairly easy, the sides are vertical lines through the min and max x coordinates. Similarly, the top and bottom run through the min and max y coordinates.

  5. #5
    Registered User
    Join Date
    Oct 2013
    Posts
    5
    Thank you! I think the axis-aligned bounding box is good enough, and i managed to get a code that works! i will now try and fill the the triangles with color, if you have any hints it would be much appreciated

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    I think what you're looking for is called flood fill.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a teapot using triangles.
    By LEL in forum C Programming
    Replies: 21
    Last Post: 10-15-2013, 11:03 AM
  2. Direct X & C# - Teapot
    By AlexIllsley in forum C# Programming
    Replies: 3
    Last Post: 08-14-2009, 03:52 AM
  3. Normals to triangles
    By disruptivetech in forum Game Programming
    Replies: 5
    Last Post: 04-30-2008, 07:32 PM
  4. Drawing triangles in C#
    By John_L in forum C# Programming
    Replies: 2
    Last Post: 03-15-2008, 08:48 AM
  5. Drawing triangles
    By TonyLFL in forum C++ Programming
    Replies: 7
    Last Post: 06-02-2002, 09:51 AM