Chapter Seven
Chapter Seven
Representing 3D Object
1
3D Object Representation
• A surface can be analytically generated using
its function involving the coordinates.
• An object can be represented in terms of its y= f(x,z)
vertices, edges and polygons. (Wire Frame,
Polygonal Mesh etc.)
• Curves and surfaces can also be designed using x y z ...
splines by specifying a set of few control
points.
2
Solid Modeling - Polyhedron
• A polyhedron is a connected mesh of simple planar polygons that
encloses a finite amount of space.
• A polyhedron is a special case of a polygon mesh that satisfies the
following properties:
• Every edge is shared by exactly two faces.
• At least three edges meet at each vertex.
• Faces do not interpenetrate. Faces at most touch along a
common edge.
• Euler’s formula : If F, E, V represent the number of faces, vertices
and edges of a polyhedron, then
V + F E = 2.
3
3D Object Representation
• The data for polygonal meshes can be represented in two ways.
• Method 1:
• Vertex List
• Normal List
• Face List (Polygon List)
• Method 2:
• Vertex List
• Edge List
• Face List (Polygon List)
4
Vertices and Faces - E.g. Cube
2 5 4
3
1
1 0
5
6
7
0
2 3
4
Vertex Index
Face Index 5
Data representation using vertex, face and normal lists:
Vertex List Normal List Polygon List
6
Data representation using vertex, face and edge lists:
Vertex List Edge List Polygon List
x[i] y[i] z[i] L[j] M[j] P[k] Q[k] R[k] S[k]
30 30 30 0 1 0 1 2 3
-30 30 30 1 2 4 7 6 5
-30 -30 30 2 3 0 4 5 1
30 -30 30 3 0 1 5 6 2
30 30 -30 4 5 2 6 7 3
-30 30 -30 5 6 3 7 4 0
-30 -30 -30 6 7
30 -30 -30 7 4
0 4
1 5
2 6
3 7
7
Normal Vectors (OpenGL)
glBegin(GL_POLYGON);
glNormal3f(xn,yn,zn);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x3,y3,z3);
glVertex3f(x4,y4,z4);
glEnd();
glEnable(GL_NORMALIZE);
8
Regular Polyhedral (Platonic Solids)
9
Wire-Frame Models
• If the object is defined only by a set of nodes (vertices), and a set of
lines connecting the nodes, then the resulting object representation
is called a wire-frame model.
• Very suitable for engineering applications.
• Simplest 3D Model - easy to construct.
• Easy to clip and manipulate.
• Not suitable for building realistic models.
10
Wire Frame Models - OpenGL
11
GLUT’s primitives
Cube: void glutWireCube ( GLdouble size );
• size Length of each edge
• Solid version: glutSolidCube().
Sphere : void glutWireSphere ( GLdouble radius, GLint slices, GLint stacks );
• radius, centred on (0, 0, 0) in object coordinates.
• slices is the number of subdivisions around the Z axis (like lines of longitude);
• stacks is the number of subdivisions along the Z axis (like lines of latitude).
• Solid version:glutSolidSphere().
Cone: void glutWireCone ( GLdouble base, GLdouble height, GLint slices, GLint stacks );
• draws a cone, with base radius radius, and height height.
• Slices is the number of subdivisions around the Z axis;
• stacks is the number of subdivisions along the Z axis.
• Solid version: glutSolidCone()
Torus: void glutWireTorus ( GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint
rings );
• draws a torus centred on (0, 0, 0) in object coordinates.
• The axis of the torus is aligned with the Z axis.
• innerRadius and outerRadius give the inner and outer radii of the torus respectively;
• nsides is the number of sides in each radial section, and
• rings is the number of radial sections.
• Solid version: glutSolidTorus().
12
GLUT’s primitives…… Platonic solids
• Tetrahedron : void glutWireTetrahedron ( void );
• draws a tetrahedron (4-sided regular object) of radius p3 centred on (0, 0, 0) in
object coordinates.
• Solid version: glutSolidTetrahedron().
• Octahedron: void glutWireOctahedron ( void );
• draws an octahedron (8-sided regular object) of radius 1 centred on (0, 0, 0) in
object coordinates.
• Solid version: glutSolidOctahedron()
• Dodecahedron: void glutWireDodecahedron ( void );
• draws a dodecahedron (12-sided regular object) of radius p3 centred on (0, 0,
0) in object coordinates.
• Solid version: glutSolidDodecahedron().
• Icosahedron: void glutWireIcosahedron ( void );
• draws an icosahedron (20-sided regular object) of radius 1 centred on (0, 0, 0)
in object coordinates.
• Solid version: glutSolidIcosahedron().
Teapot
• Teapot: void glutWireTeapot ( GLdouble scale );
• draws a teapot, scaled by scale.
13
• Solid version: glutSolidTeapot()
Glut-primitives
Wire Cone
Wire Sphere Wire Torus
Solid Cube
Solid Teapot 14
Polygonal Mesh
• Three-dimensional surfaces and solids can be approximated by a set of
polygonal and line elements. Such surfaces are called polygonal meshes.
• The set of polygons or faces, together form the “skin” of the object.
• This method can be used to represent a broad class of solids/surfaces in
graphics.
• A polygonal mesh can be rendered using hidden surface removal algorithms.
15
Solid Modeling
• Polygonal meshes can be used in solid modeling.
• An object is considered solid if the polygons fit together to enclose a
space.
• In solid models, it is necessary to incorporate directional information
on each face by using the normal vector to the plane of the face, and
it is used in the shading process.
16
Solid Modeling - OpenGL
17
Surface Modeling
Y
y = f(x, z)
19
Bezier Curves
0 u 1
m i m i m m!
Bezm , i (u ) u (1 u ) and
i i i !m i !
21
Bezier Curves
Inputs: n control points (xi, yi), i = 0, 1,2, …m
m
r(u ) Bez m i (u ) ri , 0 u 1
i 0 i
where
r (u ) ( x (u ), y (u ))
ri ( xi , yi )
22
Bezier Curve
23
Properties of Bezier
Curve
• Bezier curve is a polynomial of degree one less than the
number of control points
p1 p1
p3
p0
p2
p0
p2
• Bezier curve always passes through the first and last points;
i.e.
, and
x(0) x0 y (0) y0
x(1) xm y (1) ym
25
Properties of Bezier Curve (cont)
• The slop at the beginning of the curve is along the line joining the
first two control points, and the slope at the end of the curve is
along the line joining the last two points.
p1
p2
p0
26
Properties of Bezier Curve (cont)
• Bezier blending functions are all positive and the sum is always 1.
Bez
i 0
m, i (u ) 1
• This means that the curve is the weighted sum of the control points.
27
Properties of Bezier Curve (cont)
• Properties of the basis function
•The blending function is always a polynomial of degree one less
than the number of control points.
•Thus 3 control points result in a parabola, 4 control points a cubic
curve etc.
•Closed curves can be generated by making the last control point
the same as the first control point.
•First order continuity can be achieved by ensuring the tangent
between the first two points and the last two points are the same.
•Adding multiple control points at a single position in space will add
more weight to that point "pulling" the Bézier curve towards it.
28
Example 1: Bezier Curve
• % Bezier curve for n=3.
t=0:.01:1;
x=[1 2 4 3];
y=[1 3 3 1];
px=(1-t).^3*x(1)+3*t.*(1-t).^2*x(2)+3*t.^2.*(1-t)*x(3)+t.^3*x(4);
py=(1-t).^3*y(1)+3*t.*(1-t).^2*y(2)+3*t.^2.*(1-t)*y(3)+t.^3*y(4);
plot(x,y);
29
Example 2: Bezier Curve
% Bezier curve for n=3.
t=0:.01:1;
x=[1 2 4 3];
y=[1 1 3 1];
px=(1-t).^3*x(1)+3*t.*(1-t).^2*x(2)+3*t.^2.*(1-t)*x(3)+t.^3*x(4);
py=(1-t).^3*y(1)+3*t.*(1-t).^2*y(2)+3*t.^2.*(1 t)*y(3)+t.^3*y(4);
plot(x,y);
30
Example 3: Bezier Curve
• % Bezier curve for n=3. closedcurve, 1st and 4th pts same
t=0:.01:1;
x=[1 2 4 1];
y=[1 3 3 1];
px=(1-t).^3*x(1)+3*t.*(1-t).^2*x(2)+3*t.^2.*(1-t)*x(3)+t.^3*x(4);
py=(1-t).^3*y(1)+3*t.*(1-t).^2*y(2)+3*t.^2.*(1-t)*y(3)+t.^3*y(4);
plot(x,y);
31