Professional Documents
Culture Documents
P=v+Q
Affine Space:
• Affine space = Vector space + point
• Operations allowed:
– Vector-vector addition
– Scalar-vector multiplication
– Point-vector addition
– Scalar-scalar operations
– Point-point subtraction
Example:
.
P
(P-Q)
R
. .Q
(Q-R)
Q Q
not convex
convex
Dot Product:
|u|cos v
Cross Product:
• |Sin| = |u x v| / |u||v|
n=uxv
v
Planes :
• A plane can be defined by a point and two
vectors or by three points P
Q
R u R
P(a,b)=R+au+bv P(a,b)=R+a(Q-R)+b(P-Q)
Formation of triangular plane
u
P0
Three-dimensional primitives
1. Objects are described by their surfaces and can
be thought of as being hallow
2. Objects can be specified through a set of
vertices in 3D.
3. Objects are either composed of or can be
approximated by flat, convex polygons.
Coordinate systems and frames:
• Linear independent: A set of vectors v1, v2, …, vn
is linearly independent if
a1v1+a2v2+.. anvn=0 and iff a1=a2=…an=0.
• If a set of vectors is linearly independent, we
cannot represent one in terms of the others
• If a set of vectors is linearly dependent, at least
one can be written in terms of the others
Dimension: In a vector space, the maximum number
of linearly independent vectors is fixed and is called
the dimension of the space
v1
v3
Here the scalars a1, a2 and a3 are the components of w
with respect to the basis v1, v2, v3.
• We can also represent the vector w as the column
matrix with respect to basis as shown below
w = aT v
a1 v1
where a = a2 and v= v2
a3 v3
v1
w = aT v = [a1 a2 a3] v2 = a1v1+ a2v2 + a3v3
v3
Example
w = 2v1 + 3v2 - 4v3 a=[2 3 –4]T
• Note that this representation is with respect
to a particular basis.
• For example, in OpenGL we start by
representing vectors using the object basis
but later the system needs a representation in
terms of the camera basis.
Note: We usually think of the basis vectors v1, v2, v3
as defining a coordinate system. But actually vectors
have no fixed position, so the following two figures are
equivalent.
v
v
Frames:
• A coordinate system is insufficient to represent points
• If we work in an affine space we can add a single point,
the origin, to the basis vectors to form a frame.
• A frame consists of 2 elements
(i) Basis vectors (B) (ii) a point P0
v2
P0 v1
v3
Representation in a Frame:
u1 = 11v1+12v2+13v3
u2 = 21v1+22v2+23v3 w
u3 = 31v1+32v2+33v3
The above 3 equations can also be expressed as
u1 v1
u2 = M v2
u3 v3
i.e u = M v------------------(1)
i.e w = aT v --------------------(2)
a1 v1
where a = a2 and v= v2
a3 v3
w = bT u --------------------- (3)
b1 u1
where b = b2 and u = u2
b3 u3
v3
• A point P located at (x,y,z) is represented by the
column matrix
𝑥
P = 𝑦 w.r.t basis vectors {v1, v2, v3}
𝑧
where x,y,z are the components of basis vectors
• Vector w is represented as
𝑥
w = 𝑦 w.r.t basis vectors {v1, v2, v3}
𝑧
• Homogeneous coordinates avoid this confusion by using a
4D representation for both points and vectors.
• In homogeneous coordinate representation “0” is
appended for vectors and “1” is appended for points.
• In the frame specified by (P0, v1, v2, v3), any point P can be
written uniquely as
P = a1v1+ a2v2 + a3v3 + P0
v1
v2
P = a1 a2 a3 1 ( i.e P = aT v )
v3
P0
v3 u3
• If (P0, v1, v2, v3 ) & (Q0, u1, u2, u3 ) are two frames,
then we can express the basis vectors & reference
point of the second frame in terms of the first as
u1 = 11v1+12v2+13v3
u2 = 21v1+22v2+23v3
u3 = 31v1+32v2+33v3
Q0 = 41v1+42v2+43v3 + P0
1 1 1 1 1 1 0 1
0 1 1
0 1 1 1
T
M = 0 0 1 (MT ) -1 =
0 0 1
0 0 0 1
0 0 0 1
b=Ta
1 1 0 1 1 0
0 1 1 1 0
= =
0 0 1 0
0 0 0 1 1 1
1 0 0 0
0 1 0
0
M=
0 0 1 0
0 0 0 1
Moving the Camera
1 0 0 0
0 1 0 0
M=
0 0 1 d
0 0 0 1
50
Modeling a colored cube:
• A cube is a simple 3D object.
• A cube is composed of 8 vertices and 6 faces. Each
face is a quadrilateral. Each vertex is shared by 3 faces.
Each edge is shared by 2 faces.
• We start modeling the cube by assuming that the vertices of the
cube are available through an array of vertices
i.e GLfloat vertices [8][3] =
{ {-1.0, -1.0, 1.0},{-1.0, 1.0, 1.0}, {1.0, 1.0, 1.0},{1.0, -1.0, 1.0}
{-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {1.0, 1.0, -1.0}, {1.0, -1.0, -1.0} } ;
5 6
1 2
4 7
0 3
• We can use these list of vertices to specify the faces of the cube.
• For example one face is
glBegin (GL_POLYGON);
glVertex3fv (vertices [0]);
glVertex3fv (vertices [3]);
glVertex3fv (vertices [2]);
glVertex3fv (vertices [1]);
glEnd ();
• Similarly the other five faces of the cube can be define as
(2,3,7,6), (0,4,7,3), (1,2,6,5), (4,5,6,7), (0,1,5,4).
• When we are defining the 3D polygon, we have to be careful
about the order in which we specify the vertices, because each
polygon has two faces(outer & inner).
• Note that vertices are ordered so that we obtain correct outward
facing.
• We call a face outward facing if the vertices are traversed in a
counter-clockwise direction when the face is viewed from the
outside.
• This method is known as the right-hand rule because if you orient
the fingers of your right hand in the direction the vertices are
traversed, the thumb points outward.
• We use the following functions to draw the faces of the cube and to use colors.
GLfloat vertices [8][3] = { {-1.0, -1.0, 1.0},{-1.0, 1.0, 1.0}, {1.0, 1.0, 1.0},
{1.0, -1.0, 1.0} ,{-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {1.0, 1.0, -1.0}, {1.0, -1.0, -1.0} } ;
GLfloat colors [8] [3] = {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
{0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}};
void polygon(int a,int b, int c,int d) void colorcube(void)
{ {
glBegin(GL_POLYGON); polygon(0,3,2,1);
glColor3fv(colors[a]); polygon(2,3,7,6);
glVertex3fv(vertices[a]); polygon(0,4,7,3);
glColor3fv(colors[b]); polygon(1,2,6,5);
glVertex3fv(vertices[b]); polygon(4,5,6,7);
glColor3fv(colors[c]); polygon(0,1,5,4);
glVertex3fv(vertices[c]); }
glColor3fv(colors[d]);
glVertex3fv(vertices[d]);
glEnd();
}
• The above approach is inefficient because we use
many function calls to draw the cube.
• Drawing a cube by its faces in the most straight
forward way requires
– 6 glBegin, 6 glEnd
– 24 glColor
– 24 glVertex
– More if we use texture and lighting
Vertex Arrays:
• OpenGL provides a facility called vertex arrays, that
allows to incorporate the relationships among the
vertices, edges, and faces of geometric objects.
• The advantage of this method is to reduce the number
of function calls.
• Vertex arrays provide a method for storing array data
and this data is provided during the implementation.
• Six types of arrays supported
1. Vertices 2. Colors 3. Color indices
4. Normals 5. Texture coordinates 6. Edge flags
There are 3 steps in using vertex arrays
1. Enable the functionality of vertex arrays using the
following function calls
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
2. Tell OpenGL where and in what format the arrays are
glVertexPointer(3, GL_FLOAT, 0, vertices);
data array
3D points stored as floats data contiguous
• Method 2:
glDrawElements(GL_QUADS, 24,
GL_UNSIGNED_BYTE, cubeIndices);
C0 C3
C01(a) = (1- a) C0 + a C1
C23(a) = (1- a) C2 + a C3
C45(b) = (1- b) C4 + b C5
Affine Transformations
A transformation maps points to other points
and/or vectors to other vectors
v=R(u)
Q=T(P)
• Using homogeneous coordinates, a linear
transformation, v = Cu, can transform the
representation of a given point(or vector) into
another representation
a11 a12 a13 a14
a21 a22 a23 a24
where C =
a31 a32 a33 a34
0 0 0 1
• Any point in affine space is represented by
b1 a1
b2 a2
P= and vector by u =
b3 a3
1 0
Translation, Rotation and scaling
Translation:
• Move (translate, displace) a point to a new
location
• Displacement determined by a vector d
– Three degrees of freedom
– P’=P+d
Rotation:
Consider rotation about the origin by degrees
– radius stays the same, angle increases by
x = r cos (f + )
y = r sin (f + )
x = r cos f
y = r sin f
Scaling
Expand or contract along each axis (fixed point of origin)
x’= bx x
y’= by y
Non-Uniform
Uniform
Euclidean Space:
• A Euclidean space is an extension of a vector
space that adds a measure of size or distance
and allows us to define such things as the
length of a line segment.