C Unit 2 M
C Unit 2 M
displayed pixel is never away from a true line by half the pixel unit. A Pascal procedure for a simple
DDA is given below:
Procedure DDA (X1, Y1, X2, Y2: integer);
length : var ;
i : integer;
X, Y, X-incr, Y-incr : real ;
begin
length : = abs (X2– X1) ;
if abs (Y2–Y1) < length then length: = abs (Y2–Y1);
X - incr : = (X2 – X1) /length ;
Y - incr : = (Y2 – Y1) /length ;
X : = X1 + 0.5 ; Y = Y1 + 0.5 ;
for i : = 1 to length do
begin
plot (trunc (X) ; trunc(Y) ;
X : = X + X - incr ;
Y : = Y + Y - incr ;
end;
end.
Example
To draw a straight line from connecting two points (2, 7) and (15, 10)
X1 = 2, X2 = 15 abs(X2 – X1) = 13
Y1 = 7, Y2 = 10 abs(Y2 – Y1) = 3
Length = 13
X incr = (X2–X1/L) =13/13 = 1
Y incr = (Y2–Y1/L) =3/13= 0.23
Initial values of X and Y are
X = 2.5 Y = 7.5
The X and Y are tabulated in Table 1 and Fig. 1 shows a plot of the line.
2
Academic Year: 2022-2023 Regulation IFETCE 2019
It can be noted that lines drawn on a raster display may have a jagged or staircase appearance unless
the lines are vertical or horizontal. This is because the points that are plotted must be pixel grid
points and many of these may not lie on the actual line.
An accurate and efficient raster line-generating algorithm, developed by Bresenham, scans converts
lines using only incremental integer calculations that can be adapted to display circles and other
curves. Figures 2 and 3 illustrate sections of a display screen where straight line segments are to be
drawn. The vertical axes show-scan-line positions, and the horizontal axes identify pixel columns.
Sampling at unit x intervals in these examples, we need to decide which of two possible pixel
positions is closer to the line path at each sample step. Starting from the left endpoint shown in Fig.
2, we need to determine at the next sample position whether to plot the pixel at position (11, 11) or
the one at (11, 12).
Similarly, Fig. 3 shows-a negative slope-line path starting from the left endpoint at pixel position
(50, 50). In this one, do we select the next pixel position as (51,50) or as (51,49)? These questions
are answered with Bresenham's line algorithm by testing the sign of an integer parameter, whose
value is proportional to the difference between the separations of the two pixel positions from the
actual line path. To illustrate Bresenharn's approach, we-first consider the scan-conversion process
for lines with positive slope less than 1. Pixel positions along a line path are then determined by
sampling at unit x intervals. Starting from the left endpoint (x0, y0) of a given line, we step to
each successive column (x position) and plot the pixel whose scan-line y value is closest to
the line path. Assuming we have determined that the pixel at (xk, yk) is to be displayed, we
next need to decide which pixel to plot in column xk+1,.Our choices are the pixels at positions
(Xk+l, yk) and (xk+l, yk+l).
Fig: 2 - Section of a display screen where a straight line segment is to be plotted, starting from the
pixel at column 10 on scan line 11
Fig: 3 - Section of a display screen where a negative slope line segment is to be plotted, starting from
the pixel at column 50 on scan line 50
3
Academic Year: 2022-2023 Regulation IFETCE 2019
At sampling position xk+l, we label vertical pixel separations from the mathematical line
path as d1 and d2 (Fig. 4). The y coordinates on the mathematical line at pixel column
position xk+l is calculated as
y=m(xk+1)+b
Then
d1=y-yk
=m(xk+1)+b-yk
and
d2=(yk+1)-y
=yk+1-m(xk+1)-b
The difference between these two separations is
d1-d2=2m(xk+1)-2yk+2b-1 -----------1
Fig:4 - Distance between pixel positions and the line y coordinates at sampling position xk+1
A decision parameter pk for the kth step in the line algorithm can be obtained by rearranging
Eq. 1 so that it involves only integer calculations. We accomplish this by substituting m =
Δy/Δx, where Δy and Δx are the vertical and horizontal separations of the endpoint positions,
and defining:
pk=Δx(d1-d2)
=2Δy.xk-2Δx.yk+c ------------2
The sign of pk, is the same as the sign of dl–d2, since Δx>0 for our example. Parameter cis
constant and has the value 2Δy + Δx(2b - l), which is independent of pixel position and will
be eliminated in the recursive calculations for pk. If the pixel at yk is closer to the line path
than the pixel at yk+1(that is, dl<d2), then decision parameter pk is negative. In that case, we
plot the lower pixel; otherwise, we plot the upper pixel.
Coordinate changes along the line occur in unit steps in either the x or y directions.
Therefore, we can obtain the values of successive decision parameters using incremental
integer calculations. At step k + 1, the decision parameter is evaluated from Eq. 5as
pk+1=2Δy.xk+1-2Δx.yk+1+c
Subtracting Eq. 2 from the preceding equation, we have
pk+1-pk =2Δy(xk+1-xk)-2Δx(yk+1-yk)
But xk+1, = xk+ 1, so that
pk+1=pk + 2Δy-2Δx(yk+1-yk)
4
Academic Year: 2022-2023 Regulation IFETCE 2019
Where the term yk+1- yk is either 0 or 1, depending on the sign of parameter pk. This recursive
calculation of decision parameters is performed at each integer x position, starting at the left
coordinate endpoint of the line. The first parameter, p0, is evaluated from Eq. 5 at the starting pixel
position (xo, yo) and with m evaluated as Δy/Δx:
We can summarize Bresenham line drawing for a line with a positive slope less than 1 in the
following listed steps. The constants 2Δy and 2Δy - 2Δx are calculated once for each line to be scan
converted, so the arithmetic involves only integer addition and subtraction of these two constants.
6
Academic Year: 2022-2023 Regulation IFETCE 2019
The circle-function tests are performed for the midpositions between pixels near the circle path at
each sampling step. Thus, the circle function is the decision parameter in the midpoint algorithm,
and we can set up incremental calculations for this function as we did in the line algorithm.
Example:
Given a circle radius r = 10, we demonstrate the midpoint circle algorithm by determining positions
along the circle octant in the first quadrant hum x = 0 to x = y. The initial value of the decision
parameter is
p0=1-r=-9
For the circle centered on the coordinate origin, the initial point is (x0,y0) =(0, l0), and initial
increment terms for calculating the decision parameters are:
2x0=0, 2y0=20
Successive decision parameter values and positions along the circle path are calculated using the
midpoint method as
Properties of Ellipses
An ellipse is defined as the set of points such that the sum of the distances from two fixed
positions (foci) is the same for all points (Fig. 7). If the distances to the two foci from any
point P = (x, y) on the ellipse are labeled dl and d2, then the general equation of an ellipse can
be stated as
d1+ d2= constant
Expressing distances d1and d2interms of the focal coordinates F1 = (x1, y1) and F2= (x2,y2),
we have
√((x-x1) 2+(y-y1)2) + √((x-x2)2+(y-y2)2)=constant
By squaring this equation, isolating the remaining radical, and then squaring again, we can
rewrite the general ellipse equation in the form
Ax2+ By2+ Cxy+ Dx+ Ey+ F = 0
Where the coefficients A, B, C, D, E, and F are evaluated in terms of the focal coordinates
and the dimensions of the major and minor axes of the ellipse. The major axis is the straight
line segment extending from one side of the ellipse to the other through the foci. The minor
axis spans the shorter dimension of the ellipse, bisecting the major axis at the halfway
position (ellipse center) between the two foci.
9
Academic Year: 2022-2023 Regulation IFETCE 2019
An interactive method for specifying an ellipse in an arbitrary orientation is to input the two foci and
a point on the ellipse boundary. With these three coordinate positions, we can evaluate the constant
in A. Then, the coefficients in B can be evaluated and used to generate pixels along the elliptical
path.
Ellipse equations are greatly simplified if the major and minor axes are oriented to align with the
coordinate axes. In Fig.8, we show an ellipse in "standard position" with major and minor axes
oriented parallel to the x and y axes. Parameter rx for this example labels the semi major axis, and
parameter ry labels the semi minor axis. The equation of the ellipse shown in Fig.1:42 can be written
in terms of the ellipse center coordinates and parameters rx and ry as
((x-xc)/rx)2+((y-yc)/ry)2=1
Using polar coordinates r and θ,we can also describe the ellipse in standard position with the
parametric equations:
x= xc+rxcosθ
y= yc+rysinθ
Symmetry considerations can be used to further reduce computations. An ellipse in standard position
is symmetric between quadrants, but unlike a circle, it is not symmetric between the two octants of a
quadrant. Thus, we must calculate pixel positions along the elliptical arc throughout one quadrant,
and then we obtain positions in the remaining three quadrants by symmetry (Fig 9).
DDA ALGORITHM
To write an algorithm to generate an ellipse using the Digital Differential Analyzer
Algorithm (DDA).
Equation to the ellipse is
((x-xc)/rx)2+((y-yc)/ry)2=1
where (xc,yc) - center of the ellipse.
rx- x radius of ellipse, ry-y radius of ellipse.
1. START
2. Get the centre (xc,yc),x radius (rx) and y radius (ry) of the ellipse.
3. The polar co-ordinates on an ellipse are
x=xc+rxcosθ
y=yc+r y sinθ
4. Plot the point(x,y) corresponding to the values of θ where 0<=θ<=360
5. STOP
The x- and y-coordinates of the particle can be thought of as functions of a new variable t, and so we
can write x=f(t), y=g(t), where f,g are functions of t. In some physical problems t is thought of as
time. The equations
x=f(t) y=g(t)
are called the parametric equations of the point P(x,y) and the variable tt is called a parameter. It
is often very useful to take a cartesian equation y=F(x) and introduce a parameter t so that the x-
and y-coordinates of any point on the curve can be expressed in terms of this parameter.
Here is a very simple example of a parametrisation. Suppose we begin with the line whose equation
is y=3x−4. We can introduce a new variable tt and write x=t. Then we have y=3t−4. Thus we can
rewrite the equationy=3x−4 in parametric form as x=t, y=3t−4.
11
Academic Year: 2022-2023 Regulation IFETCE 2019
A component can be designed using the curves and shapes which can be mathematically described
e.g. arc, circle, and conics, ellipsoid, hyperbolic parabolic, sphere, and cone, cylinder, linear, conical
- and circular swept surfaces etc. However very often the designer starts with specifying a few points
which roughly describe the shape.
Two approaches are available to designers to model curves and surfaces in such cases:
Interpolation and approximation. The interpolation essentially tries to pass a curve on a surface
called interpolant through all these points. Approximation tries to fit a smoother curve on surface
which may be close to these points but may not actually pass through each of them. Fig.11 illustrates
the difference between interpolation (a) and approximation (b).
One of the popular methods of interpolation is to use the Lagrange polynomial, which is the unique
polynomial of degree n passing through n + 1 points. However, Lagrange polynomial is unsuitable in
modeling of curves because of:
i. Large number of computations involved and
ii. Tendency for the curve to oscillate between data points when the data points are large.
Another approach is to look for a polynomial of fewer degrees than W passing through these
W + 1 data points. This is done by combining polynomials of lesser degree passing through several
consecutive data points and smoothly piecing several such curve segments together by blending. In
general, the modeling of curves is done to satisfy the following:
i. Axis independence
ii. Global and local control
iii. Smoothness of curves
iv. Versatility
v. Continuity between adjoining segments of curve.
13
Academic Year: 2022-2023 Regulation IFETCE 2019
Whereas parametric curves are generally considered to be defined over an infinite range of
parameter values of u, it is always necessary to limit these to a finite interval when modeling shapes
on a computer. The domain u is, therefore taken as 0 < u < = 1 in the discussion that follows:
A spline passes through two end points and satisfies differentially condition at these end points.
These four conditions require a polynomial degree of at least 3. The derivations of cubic splines for
x, y and z are similar. The difference will be only in the end point coordinates and derivatives at the
end points. Therefore only the derivation of x(u) is considered here.
The coefficients of cubic spline polynomials y(u) and z(u) are similarly obtained by replacing x data
by y and z data.
In a vectorial form the parametric cubic curve can be expressed as:
P (u) = au3 + bu2 + cu + d -- Where u∈ (0,1)
3 2 1
P (u) = [u u u ] [ a b c d]T
Let
U = [u3 u2 u1] and A = [a b c d]T
P=UA
Curves are defined by interpolating points and tangents at these points. The parametric
cubic curve can be designed using the four vectors P(0), P(1), P’(0) and P’(1). Each one of these
vectors has three components.
P0 = d
P1 = a + b + c + d
P’(0) = c
P’(1) = 3a + 2b + c
14
Academic Year: 2022-2023 Regulation IFETCE 2019
P = (2u3 –3u2 + 1)P0+ (–2u3 + 3u2 )P1+ (u3– 2u2+u) P’0+ (u3– u2) P’1
Let F1 = 2u3 – 3u2 + 1
F2 = -2u3 + 3u2
F3 = u3 – 2u2 + u
F4 = u3 – u2
then P = F1 P0 + F2 P1 + F3 P’ + F4 P’
Let F = [F1 F2 F3 F4 ] and B = [ P0 P1 P’0 P’1]
Then P = F B
F1, F2, F3, F4, are called blending function or Hermite polynomial basis functions. B is the matrix of
geometric coefficients. F is the blending function matrix. The blending function matrix F can be
written as the product of two matrices.
F=UM
Where
For a given set of end points P0 and P1 and slopes P’0 and P’1 several sets of curves can be
generated by varying the magnitude of the tangent vectors. (unit tangent vector t = Pu / |Pu| ).
Figure 12 shows a cubic spline connecting four points. There are several other formulations of cubic
splines. Ferguson used cubic polynomials for curve and surface design in aircrafts. However, these
methods generally suffer from the fact that they do not allow the user to change the smoothness of
the curve.
15
Academic Year: 2022-2023 Regulation IFETCE 2019
The advantages of Bezier curve over cubic spline is that the direction of the curve at the joints can be
defined and changed simply by specifying the position of the second and third data points. Changing
a control point not only affects the shape of the curve near the control point but has an influence
throughout the curve.
This lack of local control is a major weakness of Bezier curve. Fig. 13 shows Bezier cubic segments
for two sets of values of X.
16
Academic Year: 2022-2023 Regulation IFETCE 2019
( ) ∑ ( )
Where u ∈ [0, 1]
With blending functions: Bi,n (u) = C(n,i) ui (1 – u)n-i
Where n is the binomial coefficient
( ) ( )
And p (u) are the control points and there are n+1 of them defining the vertices of the characteristic
polygon.
This generates what is known as piecewise polynomial. The N (u) blending functions are defined
recursively as:
( )
=0 otherwise
( ) ( ) ( ) ( )
( )
The resulting parametric polynomials are of degree (k - 1). The t are called knot values.
For an open curve there are
The blending functions confine the effects of a control point movement to the immediate locale.
Thus the curve change shape is local and not global as it is for Bezier curves.
When the control points are distinct, this curve is continuous in slope and in curvature between
successive segments but it does not pass through any of the intermediate control points. The cubic β-
spline has the advantage that the control points may be moved without affecting slope and curvature
continuity and only four spans of the overall curve will be affected by the change. Moreover, by
allowing two control points to coincide it is possible to create a curvature discontinuity. A slope
discontinuity, similarly, can be introduced by choosing three successive control points to be
coincident.
It is possible to represent complex curve shapes by considering composite curves constructed from
individual segments, in the case of cubic spline, Bezier and B-spline techniques.
This form of cubic segments uses a third set of basic functions different from the types discussed
earlier. A cubic β-spline curve is a special case of spline curve. The equation for this curve can be
written as:
( ) ∑ ( )
∈ ( )
This generates what is known as piecewise polynomial. The N (u) blending functions are defined
recursively as:
( )
= 0 otherwise
( ) ( ) ( ) ( )
( )
The resulting parametric polynomials are of degree (k - 1). The t is called knot values.
For an open curve there are
The blending functions confine the effects of a control point movement to the immediate locale.
Thus the curve change shape is local and not global as it is for Bezier curves.
When the control points are distinct, this curve is continuous in slope and in curvature between
successive segments but it does not pass through any of the intermediate control points. The cubic β-
spline has the advantage that the control points may be moved without affecting slope and curvature
continuity and only four spans of the overall curve will be affected by the change. Moreover, by
allowing two control points to coincide it is possible to create a curvature discontinuity. A slope
discontinuity, similarly, can be introduced by choosing three successive control points to be
coincident.
It is possible to represent complex curve shapes by considering composite curves constructed from
individual segments, in the case of cubic spline, Bezier and B-spline techniques.
parameter being a weight that allows a subtle form of control which is different in effect to moving a
control vertex. In the simplest form of β-spline control two global parameters (bias and tension) are
introduced which affect the whole curve.
NURBS
A non-uniform β-spline curve is defined on a knot vector where the interior knot spans are not equal.
A rational β-spline is defined by a set of four dimensional control points.
P = (Wi Xi , Wi Yi , Wi Zi , Wi )
The perspective map of such a curve in three dimensional space is called a rational β-spline curve.
Rational β- splines have the same analytical and geometric properties as non-rational β- splines.
Wi associated with each control point is called a weight and can be viewed as an extra shape
parameter. Wi affects the curve only locally and can be interpreted geometrically as a coupling
factor. The curve is pulled towards a control point if W increases.
β- SPLINES
β- splines are obtained from β-splines by introducing two new degrees of freedom: bias and tension.
These can be applied uniformly or non-uniformly.
The design of surfaces may be based on quadrics like ellipsoid, hyperboloid, cone, hyperbolic
cylinder, parabolic cylinder, elliptic cylinder and elliptic paraboloid. A surfacemay be generated by
19
Academic Year: 2022-2023 Regulation IFETCE 2019
sweeping a pattern curve along a spline curve. The swept surfacemay also be linear, conical linear or
circular swept surface.
20
Academic Year: 2022-2023 Regulation IFETCE 2019
The position and derivative data on two adjacent corners effectively define not only the edge curve
which joins them but also the cross slope at each point on the edge. This makes it possible to
combine two or more patches with continuity of position and slope.
The vector coefficients are given by a 4 × 4 matrix of position vectors for sixteen points forming a
characteristic polyhedron. Fig. 15 shows the characteristic polyhedron for a Bezier surface. The four
corner points R (0,0), R (3,0), R (3,3) and R (0,3) lie at the corners of the surface patch itself
whereas remaining points do not lie on the patch. The four points along each edge of the polyhedron
define the four edge curves of the patch. The four interior points determine the cross derivatives at
the corner and cross slopes along the nearest edges to them.
21
Academic Year: 2022-2023 Regulation IFETCE 2019
i. 3-D face: The different faces of an object can be modeled using this command. The X,Y,Z co-
ordinates of each vertex are input one after another to model a face and each of the faces is defined
one after another in this manner.
ii. P face: The P-face command produces a general polygon mesh of a arbitrary topology. Using this
command, it is possible to avoid defining a single vertex several times as is done in 3-D face
command. The user defines all vertices and then defines the faces in terms of the vertices.
iii. Rulesurf: This command creates a polygon representing the ruled surface between two curves.
Figure 16 shows an example of ruled surfaces.
iv. Tabsurf: A polygon mesh representing general tabulated mesh defined by a path curve and a
direction vector (generatrix) is created by this command. Fig. 17 shows a typical surface created by
this command.
v. Revsurf: A surface of revolution is created by rotating a path curve or profile about an axis. The
rotation can be through 360 degrees or part of it.
vi. Edgesurf: This command constructs a Coon’s surface patch using four adjoining curved edges,
an example of edge surf commands is shown in Fig.18.
22