In 3d modeling, there is some "triangle count" which determines complexity. I am not sure but I think cubes have 12 triangles or somethong. But I see NONE. They have squares, no triangles! Can someone please help me understand what a triangle is? Where in the cube are these 12 "triangles" located?
-
6$\begingroup$ A square can be made of two triangles. A cube can be made out of 12 triangles because it has 6 square faces, and you can decompose each into 2 triangles. Triangles are used in graphics because they are simple, have nice properties, and define a plane uniquely if not degenerate (all vertices lie on a line/in a single point). $\endgroup$– lightxbulbDec 28, 2019 at 9:35
-
$\begingroup$ Seeing how hard it is to get this answered, it seems to me that its not so trivial to deduce the reasoning. Which means the qiestion is worth asking thus worth upvoting. $\endgroup$– joojaaJan 10, 2020 at 6:26
2 Answers
To expand on @Makogan and @lightxbulb's answers/comments:
There are several reasons for using triangles as the basic primitive.
- (Non-degenerate) triangles are guaranteed to be planar. This means that an individual single triangle cannot obscure itself (in terms of hidden surface removal) and thus cannot form an internal silhouette edge (when being rendered) nor, say, cast a shadow on itself.
This is also means that when scan converting a triangle, for each pixel, each attribute (e.g. depth, texture coordinate, shading) can only take a 'single' value. They are guaranteed to be convex. Scan converting/filling convex polygons is far simpler than a general polygon filling algorithm
An arbitrary polygonal mesh can always be easily decomposed into triangles
[Update: As @joojaa pointed out, you could still use quads by either
a) Noting that any triangle can be represented as 3 quads by the addition of four more vertices - one at the centre of the triangle and one on each edge). You need to be careful, though, not to introduce T-Junctions. or
b) Using a degenerate quad to create a triangle - i.e. either collapse an edge by repeating a vertex or (but this may have other problems due to precision) making 3 of the vertices collinear Neither seems, to me at least, as particularly attractive].
If you are concerned about the 'cost' in vertices of supplying two triangles to represent your quad, remember that APIs (and HW) have triangle strips/fans/indexed representations which will, in most cases, eliminate the additional vertex overheads. There is thus little point in adding additional hardware to support 'fast' quad rendering as (a) it wouldn't get used much and (b) is extremely unlikely to be the bottleneck in rendering!
Having said all this, the original Series 1 PowerVR graphics chips (eg PCX1 and PCX2) used a lower-level primitive (the half plane) from which N-sided convex polygons (or in fact N-sided polyhedra - e.g an entire cube was, at most, 6 half-planes) could be constructed. IIRC the driver tried to detect if two consecutive triangles actually formed a planar quad and then replaced them with a more efficient representation. Further, for a quad to be "planar", not only did it need to be geometrically flat but the texture coordinates also had to be 'flat'.
A literal triangle, as in 3 vertices connected by 3 edges.
They are the basic building block for any other shape, any polygon can be represented with a set of triangles (called triangulation).
-
$\begingroup$ Why? Why break up a square into two triangles? $\endgroup$– user11352Jan 8, 2020 at 19:09
-
1$\begingroup$ Because triangles are the 2D simplex. it;s the simplest possible shape in 2D. Having a universal shape that you use to do all your calculations allows for some very powerful assumptions that simplify your logic (and by extension GPU manufacturing) $\endgroup$– MakoganJan 8, 2020 at 19:24
-
$\begingroup$ I understand that they can create everything, but why not use squares on square faces instead of two triangles? Why break it into triangles, and instead use the appropriate polygon? $\endgroup$– user11352Jan 8, 2020 at 19:38
-
$\begingroup$ I am explaining to you, because having a STANDARD shape simplifies computations. If you always have to deal with the same shape, you can simplify and accelerate the logic of projection, rasterization, coloring... which makes for really fast hardware / algorithms $\endgroup$– MakoganJan 8, 2020 at 20:52
-
1$\begingroup$ @Makogan the answer is essentially right. The problem with a any random polygon is that they have a ill defined shape if they are not flat. Since the object is manipulated by vertices there is no guarantee what the actual shape of a quadrangle is. So in practuce devices split quads to triangles on render. They strictly dont have to but do (there are exceptions). However, for the author its easier to show a compound polygon because he does not need to care if he does not want to $\endgroup$– joojaaJan 9, 2020 at 12:36