## What's the best way to fill in a triangle?

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

### What's the best way to fill in a triangle?

I just figured out how to do it. My book was talking about rasterization of polygons. Though it does some complicated stuff with vectors and matricies. I didn't figure out how to do it the way the book said, but the chapter/section on culling did lead me to a question. Which in turn, led me to an idea of filling a triangle by sweeping a line. Unfortunately, my design only works if the 2nd point is to the left of the 3rd (By the nature of the For loops).

So are there better ways, and ways that don't leave holes at the edges?

And what is the deffinition of rasterization. The book says everything about rasterization except the definition.
For any grievances posted above, I blame whoever is in charge . . .

burger2227
Veteran
Posts: 2449
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
You did not mention what programming language, but QBasic can use PAINT. It requires an enclosed shape of one border color only.

PAINT(x, y), fillcolor, bordercolor

You also have to place the PAINT coordinates x and y inside of the shape.

Ted
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

k7
Coder
Posts: 41
Joined: Wed Aug 01, 2007 7:38 am
Location: Tasmania, Australia
Contact:
I can't remember the proper syntax of PAINT, but I once did it with it by painting in the centre of the triangle:
PAINT(width/2, height/2), fillcolor, bordercolour.

nkk_kan
Veteran
Posts: 57
Joined: Thu Jun 01, 2006 10:45 am
Location: Gujrat,India,Asia
Contact:
Rasterization or rasterisation is the task of taking an image described in a vector graphics format (shapes) and converting it into a raster image (pixels or dots) for output on a video display or printer.

and you should get good info on this too..

http://en.wikipedia.org/wiki/Rasterisation

because i think this is what you are looking for..

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
I don't want to use paint due to the possibility of a sideways triangle (a line). I forgot to mention, these triangles are in 3D.
For any grievances posted above, I blame whoever is in charge . . .

D.S
Coder
Posts: 38
Joined: Wed Sep 14, 2005 7:37 am
Relsoft's 3d tutorials talk about polygon filling (in the vector article). The math was a little over my head, but it probably wont be for you.

Also, one of his programs uses the PAINT statement to fill a 3d box. You can check that out too.

Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Contact:
Honestly? The best way to fill a triangle is to just use OpenGL.

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
Nodtveidt wrote:Honestly? The best way to fill a triangle is to just use OpenGL.
In FB?
I wouldn't be surprised if it could.
For any grievances posted above, I blame whoever is in charge . . .

Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Contact:
Oh, if you're using FB then you can just use OpenGL anyways. No point in reinventing the wheel.

Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US
Nodtveidt wrote:Oh, if you're using FB then you can just use OpenGL anyways. No point in reinventing the wheel.
Ohhhhhhh. I thought OpenGL was just for C++.
For any grievances posted above, I blame whoever is in charge . . .

Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:
Well, I thibk it has something to do with interpolation and flat bottom and flat top triangles. Check out this article:

http://www.petesqbsite.com/sections/tut ... apter3.htm

If you scroll a bit down, to: 'III. Different Polygon fillers', there is MUCH info on how to make polygon fillers. Solid, but also with interpolating colours, and even environment mapped polygons.

Also look on Petesqbsite > tutorials > Graphics, then look at some of the 3d series (the link I sended you is that from Relsoft).