67

Why are triangles always used for drawing surfaces in 3D? Why not a square or some other shape?

royhowie
  • 11,075
  • 14
  • 50
  • 67
seymar
  • 3,993
  • 6
  • 25
  • 30
  • 1
    Just to quickly add a bit, polygons (and more precisely triangles) is not the only way to render 3D surfaces: check out surfels ([http://www.filipvanbouwel.be/master_thesis.php](http://www.filipvanbouwel.be/master_thesis.php)), voxels, etc. – Alexandre Abreu May 23 '11 at 17:28
  • @AlexandreAbreu Your link is dead. – Refael Sheinker Jun 06 '22 at 08:27
  • Bilinear patches (http://shaunramsey.com/research/bp/ramseybilinear.pdf) and Bezier surfaces (https://en.wikipedia.org/wiki/B%C3%A9zier_surface) types of splines are also sometimes used in drawing 3D surfaces. – Shaun Ramsey Mar 02 '23 at 17:42
  • Nvidia has a nice update to my bilinear patch work in 2019 too: (https://research.nvidia.com/publication/2019-03_cool-patches-geometric-approach-raybilinear-patch-intersections) – Shaun Ramsey Mar 02 '23 at 17:43

3 Answers3

96

Triangles can never be non-planar; anything with more than 3 points can be non-planar and thus un-renderable unless converted to triangles.

For example: A square is two triangles that are on the same plane, if all the points that make up the square are co-planar. It takes a lot of calculations to make sure all the points are co-planar, thus all polygons that are greater than 3 points are pre-calculated by decimating them into triangles and tested to make sure all the points are co-planar once, instead of on every frame that gets rendered.

Here is good reference about polygon meshes.

Planar Mesh


(source: softimage.com)

Non-Planar Mesh


(source: softimage.com)

and one more example that might make it clearer


(source: autodesk.com)

The non-planar mesh is degenerate and can't be sorted or rendered correctly in any sane manner. Triangles don't have this problem.

Efficiency

Triangles also are very memory efficient and can be sorted, and rendered extremely fast when using Triangle Strips which only need 1 point to be stored for each additional triangle after the first.

http://upload.wikimedia.org/wikipedia/en/0/03/Triangle_Strip.png

and Triangle Fans which is a special case of a Triangle Strip.


(source: codesampler.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • One more point to be made is that is relatively easy to establish when a ray of light hits a triangle and where the intersection lies. Moreover, the interpolation of color attributes between nodes is relatively easy to do. – John Alexiou Aug 10 '19 at 22:17
  • 3
    Can you please explain why non planar surfaces are un-renderable? And can you please explain what you mean by un-renderable? – penguin99 Feb 09 '22 at 00:50
  • Most of what is said above can be accomplished with planar convex poly meshes except for fans. There's no reason other polys/items can't be rendered and some do. But, if they are not rendered directly in hardware, they are slow. The reality is that hardware acceleration for rasterization was done for triangles and it was a sane choice (more in a second), so we use triangles. Early meshes were literally all over the place in terms of number of edges of a polygon. But, it is easy to turn any convex polygon into triangles, and so as a base primitive, triangles make sense. Compact, planar, simple. – Shaun Ramsey Mar 02 '23 at 17:49
17

Since 3 points are the minimum necessary to define a planar surface any shape can be simulated using many triangles, and efficient algorithms exist to rapidly paint triangles onto the screen.

Geoff
  • 9,340
  • 7
  • 38
  • 48
13

Basically any complex (surface) structure can be represented as a bunch of triangles. The triangle is the most atomic and primitive geometry. Hence it is used as base for almost anything. Nevertheless most 3D engines provide you with more complex primitives like spheres, cones, cylinders, donuts, whatnot. Check your libraries documentation.

Hyperboreus
  • 31,997
  • 9
  • 47
  • 87