0% found this document useful (0 votes)
2 views58 pages

Lecture 21

Triangles serve as the fundamental drawing primitive in 3D graphics, similar to how pixels function in 2D graphics, and are essential for creating the mesh that defines 3D objects. The document discusses triangle representation methods, including triangle strips and fans, and explains the concept of planes in 3D space, their equations, and how to determine the location of points relative to these planes. Additionally, it covers the intersection of lines and planes, providing mathematical formulations for these operations.

Uploaded by

usmansaeed1512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views58 pages

Lecture 21

Triangles serve as the fundamental drawing primitive in 3D graphics, similar to how pixels function in 2D graphics, and are essential for creating the mesh that defines 3D objects. The document discusses triangle representation methods, including triangle strips and fans, and explains the concept of planes in 3D space, their equations, and how to determine the location of points relative to these planes. Additionally, it covers the intersection of lines and planes, providing mathematical formulations for these operations.

Uploaded by

usmansaeed1512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 58

Computer Graphics

Lecture 21

Triangles and Planes


Taqdees A. Siddiqi
[email protected]
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
 When we draw a polygon..
 Hardware devices really use of fan of triangles
 Triangles “flesh out” a 3D object, connecting them
together to form a skin or mesh that defines the
boundary surface of an object
 The ordering of the vertices goes clockwise aroung he
triangle
Triangles
 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)
 The code that defines triangle with the help of structure
and public constructor:
 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;
}
Triangle Strips and Fans
 Lists of triangles are generally represented in one of
three ways:
 The first is an explicit that or array of triangles. Where
every three elements represent a new triangle.
 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.
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.
 An N-sided polygon can be represented efficiently
using a triangle fan
 Triangles in a triangle strip, instead of sharing a
common element like a fan, only share elements with
the triangle immediately preceding them.
 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
Plane
 Planes are to 3D what lines are to 2D
 Planes are n-1 dimensional hyper planes that can help
us accomplish various tasks.
 Planes are defined as infinitely large, infinitely thin
slices of space, like big pieces of paper.
 Each of the triangles that make up our model, exist in
their own plane
 When we have a plane that represents a slice of 3D
space, we can perform operations like classification of
points, polyogns and clipping.
 How do we represent planes?
Ax + by + cz + d = 0

Equation that defines a plane in 3D


Ax + By + Cz + d = 0
The triplet (a, b , c) represents what is called the normal
of the plane
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.
 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.
 Finally the triplet (x,y,z) is any point that satisfies the
equation
 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
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
 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)
 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
 We just perform a cross product between the two
vectors made up by the three points
 Normal = (p1-p2) x (p3-p2)
 K = normal * p1
 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:
 The normal to the plane these 3 points can be defined
as
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>
 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.
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)
Constructing a plane from a normal and a
point on the plane
 Normalize (n); find a unit vector
 d = -dot product (n, a)
Defining Locality with Relation to a Plane
 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
 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
Intersection Between a line and a plane
This occurs at the point which satisfies both the line and
the plane eqauations
 Line equation
p = org + u * dir (1)
Plane equation
p * normal – k = 0. (2)
Substituting (1) into (2) and rearranging we get :
 (org + u * dir) * normal – k =0
 i.e., u * dir * normal = k –org * normal
 i.e., u = (k – org * normal) / (dir * normal)
 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)

You might also like