Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Lecture 21 Triangles and Planes Taqdees A

Similar presentations


Presentation on theme: "Computer Graphics Lecture 21 Triangles and Planes Taqdees A"— Presentation transcript:

1 Computer Graphics Lecture 21 Triangles and Planes Taqdees A
Computer Graphics Lecture 21 Triangles and Planes Taqdees A. Siddiqi

2 Triangles Triangles are to 3D graphics what pixels are to 2D graphics
Every PC hardware accelerator under the sum uses triangles as the fundamental drawing primitive

3 When we draw a polygon.. Hardware devices really use of fan of triangles

4 Triangles “flesh out” a 3D object, connecting them together to form a skin or mesh that defines the boundary surface of an object

5 The ordering of the vertices goes clockwise aroung he triangle

6 Triangles

7 It is impossible to see triangles that face away from us
It is impossible to see triangles that face away from us. (we can find this out by computing the triangle plane normal and performing a dot product with a vector from the camera location to a location on the plane)

8 The code that defines triangle with the help of structure and public constructor:

9 Struct triangle Type v[3];//Array access useful for loops Trriangle() { //nothing } Triangle(type v0, type v1, type v2) { V[0] = v0; v[1]; v[2] = v2; }

10 Triangle Strips and Fans

11 Lists of triangles are generally represented in one of three ways:

12 The first is an explicit that or array of triangles
The first is an explicit that or array of triangles. Where every three elements represent a new triangle.

13 However there are two additional representation design to solve bandwidth while sending triangle to dedicated hardware to draw them. They are called triangle strips and triangle fans.

14 Triangle Fans Triangles fans, conceptually, look like the folding fans you see in souvenir shops. They are a list of triangles that all share a common point.

15

16 An N-sided polygon can be represented efficiently using a triangle fan

17 Triangles in a triangle strip, instead of sharing a common element like a fan, only share elements with the triangle immediately preceding them.

18 The first three elements defines the first triangle
The first three elements defines the first triangle. then each subsequent element is combined with the two elements before it, in clockwise order, to create a new triangle

19

20 Plane

21 Planes are to 3D what lines are to 2D

22 Planes are n-1 dimensional hyper planes that can help us accomplish various tasks.

23 Planes are defined as infinitely large, infinitely thin slices of space, like big pieces of paper.

24 Each of the triangles that make up our model, exist in their own plane

25 When we have a plane that represents a slice of 3D space, we can perform operations like classification of points, polyogns and clipping.

26 How do we represent planes?

27 Ax + by + cz + d = 0 Equation that defines a plane in 3D

28 Ax + By + Cz + d = 0 The triplet (a, b , c) represents what is called the normal of the plane

29 Normal A normal is a unit vector that, conceptually speaking, sticks directly out of a plane. A stronger mathematical definition would be that the normal is a vector that is perpendicular to all of the points that lie in the plane.

30 The d component in the equation represents the distance from the plane to the origin. The distance is computed by tracing a line towards the plane until you hit it.

31 Finally the triplet (x,y,z) is any point that satisfies the equation

32 Finally the triplet (x,y,z) is any point that satisfies the equation
The set of all points (x,y,z) that solve the equation is exactly all the points that lie in the plane

33 Examples of planes Following are two examples of planes. The first has the normal pointing away from the origin, which causes d to be negative Try some sample values for yourself if this doesn’t make sense

34

35 The second has the normal pointing towards the origin, so d is positive. Of course, if the plane goes through the origin, d is zero (the distance from the plane to the origin is zero)

36

37 It’s important to notice that technically the normal (x,y,z) does not have to be unit -length for it to have a valid plane equation. But since things end up nicer if the normal is unit-lenght

38 We just perform a cross product between the two vectors made up by the three points

39

40 Normal = (p1-p2) x (p3-p2) K = normal * p1

41 Note that it is extremely important to keep track of which direction your points are stored in. let’s take 3 points stored in clockwise direction in the x/y plane:

42

43 The normal to the plane these 3 points can be defined as

44 Normal = (p1-p2) x (p3-p2) = (0,-1,0) x (1,-1,0) = <(-1)*0 – 0*(-1), 0*1 – 0*0, 0*(-1) – (-1)*1> = <0,0,1>

45 The z axis. If we were to store the points counter-clockwise the normal calculated would be <0,0,-1>, which is still the z axis but in the “opposite” direction. It’s important to keep track of these things since we often need plane equations to be correct in order to determine which side of a polygon an object (such as the view point) is on.

46 Constructing a plane from three points on the plane
Normal vector = n n = cross product ( (b-a) , (c-a) ) Normalize (n); find a unit vector D = -dot product (n,a)

47 Constructing a plane from a normal and a point on the plane

48 Normalize (n); find a unit vector
d = -dot product (n, a)

49 Defining Locality with Relation to a Plane

50 One of the most important operations planes let you perform is defining the location of a point with respect to a plane. If you drop a point into the equation, it can be classified into three cases: in front of the plane, in back of the plane, or coplanar with the plane

51

52 To perform the back-face cull, just subtract one of the triangle’s points from the camera location and perform a dot product with the resultant vector and the normal. If the result of the dot product is greater than zero, then the view point was in front of the triangle

53

54 Intersection Between a line and a plane

55 This occurs at the point which satisfies both the line and the plane eqauations

56 Line equation p = org + u * dir (1) Plane equation p * normal – k = 0. (2) Substituting (1) into (2) and rearranging we get :

57 (org + u * dir) * normal – k =0
i.e., u * dir * normal = k –org * normal i.e., u = (k – org * normal) / (dir * normal)

58 If (d * normal) = 0 then the line runs parallel to the plane and no intersection occurs. The exact point at which intersection does occur cn be found by plugging the value of parameter u back into the line equation in (1)


Download ppt "Computer Graphics Lecture 21 Triangles and Planes Taqdees A"

Similar presentations


Ads by Google