# Thread: Making a teapot in C with triangles

1. ## 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

2. You do know that your link requires logging into the site, right?

How about posting your include files as well?

Jim

3. 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.

4. 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. 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. I think what you're looking for is called flood fill.

Popular pages Recent additions