TNM046: Datorgrafik Triangle and Normal
Sasan Gooran
VT 2013
Vertex and Triangle
Vertex: ( x y z )
Triangle: array of Vertex (vertices)
3D object: array of Triangle (triangles)
Example: Triangle[1] : (10,10,10), (10,20,10), (10,20,20) Triangle[2] : (10,10,10), (10,20,10), (10,10,20)
Not a good approach
3
Vertex and Triangle
Vertex: ( x y z )
Vertex table: array of Vertex
Triangle table: array of integers
Example: Vertex table: (10,10,10) , (10,20,10) , (10,20,20), (10,10,20), …..
Triangle table: (1,2,3) , (1,2,4) , ….
3D object: Vertex table + Triangle table
Now all vertices in the object is in one list (table).
Vertex and Triangle
Example: Present the following object using vertex and
triangle table. The distance from P1, P2 and P3 to the origin (P0) is unity (1).
y z
p0 p1
p2 p3
Triangle 1:
p0p1p3
Triangle 2:
p0p2p3
Triangle 3:
p1p2p3
Vertex table:
p0: (0,0,0) p1: (1,0,0) p2: (0,1,0) p3: (0,0,1) Answer:
Triangle table:
Triangle 0: (0,1,2) Triangle 1: (0,1,3)
5
Vertex and Triangle
Assume triangle 1 (p0p1p3).
p0 = (0,0,0), p1 = (1,0,0), p3 = (0,0,1),
x z
p0 p1
p3
d
0d
1d
2Difference vectors:
d
0= (1, 0, 0) − (0, 0, 0) = (1, 0, 0)
d
1= (0, 0,1) − (1, 0, 0) = (−1, 0,1)
d
2= (0, 0, 0) − (0, 0,1) = (0, 0, −1)
Triangle and Normal
x z
p0 p1
p3
d
0d
1d
2y z
p0 p
p2 p3
Triangle 1:
p0p1p3
d
0×
d
1= (1, 0, 0) × (−1, 0,1) =
ˆx ˆy ˆz
1 0 0
−1 0 1
= (0, −1, 0)
This normal vector points outwards (the object)d
1×
d
2= (−1, 0,1) × (0, 0, −1) = (0, −1, 0) d
2×
d
0= (0, 0, −1) × (1, 0, 0) = (0, −1, 0)
7
Triangle and Normal
x z
p0 p1
p3
d
0d
1d
2Triangle 1:
p0p1p3
N
1=
d
0×
d
1=
d
1×
d
2=
d
2× d
0Three possible starting points For this triangle three lists are possible:
(0,1,3) or (1,3,0) or (3,0,1)
In order to calculate the normal pointing outwards:
Find the vector from the first point to the second (call A1) Find the vector from the second point to the third (call A2)
N
1=
A
1×
A
2points outwards
Triangle and Normal
Triangle table: Let your thumb of the right hand stick out of the object. Pick the first point, then the sense of your fingers gives you the other two points in the right sequence.
y z
p0 p1
p2 p3
Triangle 1:
p0p1p3
Triangle 2:
p0p2p3
Triangle 3:
p1p2p3
Triangle table:
Triangle 0: (0,2,1) Triangle 1: (0,1,3) Triangle 2: (0,3,2) Triangle 3: (1,2,3)
Compare this triangle table with the one on page 4.
9
Triangle and Normal
Therefore the following 3D object can be defined as:
x
y z
p0 p1
p2 p3
Triangle table:
(0,2,1) (0,1,3) (0,3,2) (1,2,3)
Vertex table:
(0,0,0) (1,0,0) (0,1,0) (0,0,1)