You are on page 1of 289

Laboratory Manuals-II

Production Systems Engineering Chair

Industrial Engineering program

School of Mechanical and Industrial Engineering

Bahir Dar Institute of Technology (BIT)

Numerical and Computational Methods with MATLAB (Ieng 2052)

CAD/CAM (Ieng 4170)

March 2015

1
PART-I

Laboratory Manual for the course


Numerical and Computational Methods
with MATLAB
(Ieng 2052)

2
Introduction

MATLAB is a powerful computing system for handling the calculations involved in scientific
and engineering problems. The name MATLAB stands for MATrixLABoratory, because the
system was designed to make matrix computations particularly easy.
MATLAB is an interactive computing environment that enables numerical computation and data
visualization.The MATLAB environment allows the user to manage variables, import and export
data, perform calculations, generate plots, & develop and manage files for use with MATLAB.

MATLAB has hundreds of built-in functions and can be used to solve problems ranging from the
very simple to the sophisticated and complex ones.

Whether you want to do some simple numerical or statistical calculations, some complex
statistics, solve simultaneous equations, make a graph, or run and entire simulation program,
MATLAB can be an effective tool.

This Lab manual is prepared to assist the students who take the course Numerical and
Computational Methods in solving various complex and tedious mathematical computations by
using MATLAB software.

It is tried to introduce the basics of MATLAB prior to starting the main topics of the course in
order to familiarize the students about MATLAB. An M-File for each method of solving
numerical problems is included in this manual.

1
Contents
Introduction......................................................................................................................................1

Lab 1...............................................................................................................................................6

MATLAB Basics.............................................................................................................................6

Using mat lab...............................................................................................................................6

Scalar Mathematics......................................................................................................................7

Numbers In Mat Lab....................................................................................................................7

Operators in MATLAB................................................................................................................8

Precedence of operations (order of evaluation)...........................................................................9

Format........................................................................................................................................10

Special variables:.......................................................................................................................11

Commands involving variables:.................................................................................................11

Arrays, Vectors and Matrices.....................................................................................................11

The Colon Operator...................................................................................................................14

E X E R C I S E S..........................................................................................................................14

Lab 2.............................................................................................................................................16

MATLAB Built –in Functions.......................................................................................................16

2.1 Elementary Math Built-In Functions...................................................................................16

2.2 Displaying Values and Text.................................................................................................17

2.3 Plotting.................................................................................................................................19

3-D plots.....................................................................................................................................24

EXERCISES..................................................................................................................................27

Lab 3.............................................................................................................................................28

Programming in MATLAB and Conditional statements...............................................................28

Programming in Mat Lab...........................................................................................................28

2
3.2 Relational and Logical Operators........................................................................................32

3.3 Conditional statements.........................................................................................................32

1.The if - end Structure:-........................................................................................................33

2. The if-else-end Structure....................................................................................................36

3. The if-elseif-else- endStructure..........................................................................................37

3.4 Loops....................................................................................................................................40

for -end Loops........................................................................................................................41

While Loops...........................................................................................................................42

Exercise..........................................................................................................................................43

Lab 4.............................................................................................................................................44

Bisection method...........................................................................................................................44

Bisection Method...........................................................................................................................44

Pseudocode for function to implement bisection.......................................................................44

M-file to implement bisection method.......................................................................................45

EXERCISES..................................................................................................................................48

Lab 5.............................................................................................................................................49

Newton-Raphson Method..............................................................................................................49

An M-file to implement the Newton-Raphson method.............................................................51

EXERCISE.................................................................................................................................53

Lab 6.............................................................................................................................................54

Linear Least Square Regression....................................................................................................54

Curve Fitting and Interpolation..................................................................................................54

Linear Least-squares Regression...............................................................................................54

Pseudocode for Linear regression..............................................................................................55

M-file to implement linear regression........................................................................................56

3
EXERCISE....................................................................................................................................58

Lab7..............................................................................................................................................59

Polynomial Interpolation...............................................................................................................59

8.1 Determining Polynomial Coefficients using MATLAB functions: polyfit and polyval.....60

8.2 Newton’s Interpolating Polynomials...................................................................................61

An M-file to implement Newton interpolation..........................................................................61

8.3 Lagrange Interpolating Polynomial.....................................................................................62

An M-file to implement Lagrange interpolation........................................................................63

EXERCISE.................................................................................................................................64

Lab 8.............................................................................................................................................65

Solutions of Systems of Linear Algebraic Equation......................................................................65

Representing Linear Algebraic Equations in Matrix Form........................................................65

8.1 Gauss Elimination................................................................................................................66

An M-file to implement naive Gauss elimination......................................................................67

8.2 LU Factorization..................................................................................................................68

8.3 Cholesky Factorization........................................................................................................70

EXERCISE.................................................................................................................................71

Lab 9.............................................................................................................................................72

Newton-Cotes closed integration formulas...................................................................................72

The Trapezoidal Rule.................................................................................................................72

The Composite Trapezoidal Rule..............................................................................................73

M-file to implement the composite trapezoidal rule..................................................................75

Trapezoidal Rule with Unequal Segments.................................................................................76

M-file to implement the trapezoidal rule for unequally spaced data.........................................77

MATLAB Functions: trapz and cumtrapz.................................................................................78

4
EXERCISE....................................................................................................................................79

Lab 10...........................................................................................................................................80

Romberg integration......................................................................................................................80

M-file to implement Romberg integration.................................................................................80

MATLAB Functions: quad and quadl.......................................................................................81

EXERCISE....................................................................................................................................83

REFERENCES..............................................................................................................................84

5
Lab 1
MATLAB Basics
Objectives

 To describe how to start and exit Mat Lab


 To introduce the students with common Mat Lab desk top tools and the Mat Lab interface
 To describe how we represent Numbers in Mat Lab and how we use operators in Mat Lab
 To introduce about arrays, Vectors and matrixes

1.1 Using mat lab

To start MATLAB from Windows, double-click the MATLAB icon on your Windows
Desktop. When MATLAB starts, the MATLAB desktop opens as shown in Figure 1.1.

Fig 1.1The MATLAB Desktop

The window in the desktop that concerns us most of the time is the Command Window, where
the special >>prompt appears. This prompt means that MATLAB is waiting for a command.

6
You can quit MATLAB at any time with one of the following:
 Select Exit MATLAB from the desktop File menu.
 Enter quit or exit at the Command Window prompt.
Do not click on the close box in the top right corner of the MATLAB desktop. This does not
allow MATLAB to terminate properly and, on rare occasions, may cause problems with your
computer operating software
In MATLAB most of the time, we use the following desktop tools.
1.Command Window:-shows the commands which are executed on the command window as well
as the output result of a MATLAB program.
2.Command History: - in the command history we will find all the commands which are executed
previously in the MATLAB.
3.Work Space:- the work space is basically the memory space of MATLAB which contains all
the variables and their numerical values which were stored in particular program.
4.Curent Directory(folder):- displays the current directory (folder)from where you are taking the
MATLAB file.

1.2 Scalar Mathematics


Scalar mathematics involves operations on single-valued variables. Mat Lab provides support
for scalar mathematics similar to that provided by a calculator.
For more information, type help ops.
The most basic Mat Lab command is the mathematical expression, which has the following
properties:
 Mathematical construct that has a value or set of values.
 Constructed from numbers, operators, and variables.
 Value of an expression found by typing the expression and pressing Enter

1.3 NumbersIn Mat Lab


Mat Lab represents numbers in two form, fixed point and floating point.
Fixed point: Decimal form, with an optional decimal point. For example:
2.6349, -381, 0.00023
Floating point: Scientific notation, representing m × 10e
For example: 2.6349 × 105 is represented as 2.6349e5

7
It is called floating point because the decimal point is allowed to move. The number has two
parts:
 mantissa m: fixed point number (signed or unsigned), with an optional decimal point
(2.6349 in the example above)
 exponent e: an integer exponent (signed or unsigned) (5 in the example).
Mantissa and exponent must be separated by the letter e (or E).
Scientific notation is used when the numbers are very small or very large. For example, it is
easier to represent 0.000000001 as 1e-9.

1.4 Operators in MATLAB

In MATLAB the evaluation of expressions is achieved with arithmetic operators, shown in the
table below.

Examples of expressions constructed from numbers and operators, processed by MATLAB:


>> 3 + 4
ans =
7
>> 3 - 3
ans =
0
>> 4/5
ans =
0.8000
o Prompt >>is supplied by MATLAB, indicates beginning of the command.

8
o ans = following the completion of the command with the Enter key marks the beginning of
the answer.
Operations may be chained together. For example:
>> 3 + 5 + 2
ans =
10
>> 4*22 + 6*48 + 2*82
ans =
540
>> 4 * 4 * 4
ans =
64
Instead of repeating the multiplication, the MATLAB exponentiation or power operator can be
used to write the last expression above as:
>> 4^3
ans =
64
Left division may seem strange: i.e divide the right operand by the left operand. For scalar
operands the expressions 56/8 and 8\56 produce the same numerical result.
>> 56/8
ans =
7
>> 8\56
ans =
7

1.5 Precedence of operations (order of evaluation)

Since several operations can be combined in one expression, there are rules about the order in
which these operations are performed:
1. Parentheses’()’, innermost first
2. Exponentiation (^), left to right

9
3. Multiplication (*) and division (/ or \) with equal precedence, left to right
4. Addition (+) and subtraction (−) with equal precedence, left to right
When operators in an expression have the same precedence the operations are carried out from
left to right. Thus 3 / 4 * 5 is evaluated as ( 3 / 4 ) * 5 and not as 3 / ( 4 * 5 )
Syntax
MATLAB cannot make sense out of just any command; commands must be written using the
correct syntax (rules for forming commands). Compare the interaction above with
>>4 + 6 +
??? 4 + 6 +
I
Error: Expression or statement is incomplete or incorrect.
Here, Matlab is indicating that we have made a syntax error, which is comparable to a misspelled
word or a grammatical mistake in English. Instead of answering our question, MATLAB tells us
that we’ve made a mistake and tries its best to tell us what the error is.

1.6 Format

We Use the format function to control the output format of numeric values displayed in the
Command Window.
Note   The format function affects only how numbers are displayed, not how MATLAB
computes or saves them.
formattype changes the format to the specified type.
The tables below show the allowable values for type, and provides an example for each type.
Command Description example
format short Fixed-point with 4 >> 351/7
decimal digits ans = 50.1429
format long Fixed-point with 14 >> 351/7
decimal digits ans = 50.14285714285715
format short e Scientific notation with 4 >> 351/7
decimal digits ans = 5.0143e + 001
format long e Scientific notation with 15 >> 351/7
decimal digits ans = 5.014285714285715e001
format short g Best of 5 digit fixed or >> 351/7
floating point ans = 50.143

format long g Best of 15 digit fixed or >> 351/7


floating point ans = 50.1428571428571

10
format compact Two decimal digits >> 351/7
ans = 50.14
format bank Eliminates empty lines to allow more lines with information
displayed on the screen
format loose Adds empty lines (opposite of compact)

1.7 Special variables:


• ans: default variable name
• pi: ratio of circle circumference to its diameter, π = 3.1415926...
• eps: smallest amount by which two numbers can differ
• inf or Inf : infinity, e.g. 1/0
• nan or NaN : not-a-number, e.g. 0/0
• date: current date in a character string format, such as 03-Apr-2014.
• flops: count of floating-point operations.

1.8 Commands involving variables:


• who: lists the names of defined variables
• whos: lists the names and sizes of defined variables
• clear: clears all variables, resets default values of special variables
• clear var: clears variable var
• clc: clears the command window, moves the prompt to the top line, but does not affect
variables.
• clf: clears the current figure and thus clears the graph window.

1.9 Arrays, Vectors and Matrices


An array is a collection of values that are represented by a single variable name. One
dimensional arrays are called vectors and two-dimensional arrays are called matrices. Brackets
are used to enter arrays in the command mode. For example, a row vector can be assigned as
follows:
>> a = [1 2 3 4 5]
a =
1 2 3 4 5
A column vector can be entered in several ways.
i. >> b = [ 2 ; 4 ; 6 ; 8 ; 10 ]

11
or
ii. >> b = [2
4
6
8
10]
or, by transposing a row vector with the ‘ operator,
iii. >> b = [2 4 6 8 10]‘
The result in all three cases will be
b =
2
4
6
8
10
A matrix of values can be assigned as follows:
>> A = [1 2 3; 4 5 6; 7 8 9 ]
A =
1 2 3
4 5 6
7 8 9
In addition, the Enter key can be used to separate the rows. For example:
>> A = [ 1 2 3
4 5 6
7 8 9 ]
Finally, we could construct the same matrix by joining the vectors representing each column:
>> A = [ [ 1 4 7 ]' [ 2 5 8 ]' [ 3 6 9 ]']

At any point in a session, a list of all current variables can be obtained by entering the who
command:
>>who

12
Your variables are:
-----------------
or, with more detail, enter the whoscommand:
>>whos
Name Size Bytes Class
----- ------ -------- --------
Note that subscript notation can be used to access an individual element of an array. For
example, the fourth element of the column vector b can be displayed as
>>b ( 4 )
ans =
8
For an array, A(m,n) selects the element in mth row and the nth column. For example,
>> A ( 2 , 3 )
ans =
6
There are several built-in functions that can be used to create matrices. For example, the ones
and zeros functions create vectors or matrices filled with ones and zeros, respectively. Both have
two arguments, the first for the number of rows and the second for the number of columns.
For example, to create a 2 × 3 matrix of zeros:
>> E = zeros(2,3)
E =
0 0 0
0 0 0
Similarly, the ones function can be used to create a row vector of ones:
>> u = ones(1,3)
u =
1 1 1

13
1.10 The Colon Operator
The colon operator is a powerful tool for creating and manipulating arrays. If a colon is used to
separate two numbers, MATLAB generates the numbers between them using an increment of
one:
>> t = 1:5
t =
1 2 3 4 5
If colons are used to separate three numbers, MATLAB generates the numbers between the first
and third numbers using an increment equal to the ;number:
>> t = 1:0.5:3
t =
1.0000 1.5000 2.0000 2.5000 3.0000

EXERCISES

1. Enter the following numbers at the command prompt in scientific notation.


A, 1.234 × 105
B, − 8.765 × 10−4
C,10−15
D, −1012
2.Evaluate the following MATLAB expressions yourself before checking the answers in
MATLAB:
1) 1+2*3
2) 4/2*2
3) 1+2 / 4
4) 1 + 2\4
5) 2*2 ˆ 3
6) -4 ˆ 2
7) 2*3\3
8) 2 ˆ (1 + 2)/3
9) 1/2e-1
14
3.Use MATLAB to evaluate the following expressions. Answers are in brackets.

1
(a) (0.1667)
2 X3

(b) 22×3 (64)

(c) 1.5×10−4 +2.5×10−2 (0.0252; use scientific

Lab 2
MATLAB Built –in Functions
Objectives
 Introducing common Mat Lab built-in Functions

15
 Introducing how to Display Values and texts in Mat Lab
 Introducing about plotting In Mat Lab

2.1 Elementary Math Built-In Functions


MATLAB contains a number of functions for performing computations which require the use of
logarithms, elementary math functions and trigonometric math functions. List of these
commonly used elementary MATLAB mathematical built-in functions are given in Tables
below.
Table2.1:Common math functions

Table2.2: Exponential functions

Table2.3 :Trigonometric and hyperbolic functions

16
2.2 Displaying Values and Text
• There are three ways to display values and text in Matlab,
1. By entering the variable name at the Matlab prompt, without a semicolon.
2. By use of the command disp.
3. By use of the command fprintf.
disp:
There are two general forms of the command disp,
1. disp(variable): Displays value of variable without displaying the variable name.

17
2. disp(string): Displays string by stripping off the single quotes and echoing the characters
between the quotes.
String: A group of keyboard characters enclosed in single quote marks (’). The quote marks
indicate that the enclosed characters are to represent ASCII text.
Example
>>temp=78;
>>disp(temp); disp(’degrees F’)
78
degrees F
fprintf
The general form of this command is:
fprintf(’format string’, list of variables)
The format string contains the text to be displayed (in the form of a character string enclosed in
single quotes) and it may also contain format specifiers to control how the variables listed are
embedded in the format string.
The format specifiers include:

 w.d%f:- Display as fixed point or decimal notation (defaults to short), with a width of w characters
(including the decimal point and possible minus sign, with d decimal places. Spaces are filled in from
the left if necessary. Set d to 0 if you don’t want any decimal places, for example %5.0f. Include
leading zeros if you want leading zeroes in the display, for example %06.0f.
 w.d%e:-Display using scientific notation (defaults to short e), with a width of w characters (including
the decimal point, a possible minus sign, and five forthe exponent), with d digits in the mantissa after
the decimal point. Themantissa is always adjusted to be less than 1.
 w.d%g:- Display using the shorter of tt short or short e format, with width w and d decimal places.
 \n:- Newline (skip to beginning of next line)
The w.dwidth specifiers are optional. If they are left out, default values are used.
Examples:
>>fprintf(’The temperature is %f degrees F \n’, temp)
The temperature is 78.000000 degrees F
>>fprintf(’The temperature is %4.1f degrees F \n’, temp)
The temperature is 78.0 degrees F

18
2.3 Plotting
MATLAB has a powerful graphics system for presenting and visualizing data, which is
reasonably easy to use.
MATLAB has many commands that can be used to create basic 2-D plots, overlay plots,
specialized 2-D plots,3-D plots, mesh and surface plots.
Basic 2-D Plots
Probably the most common form of plot is plot(x, y) where x and y are vectors of the same
length, e.g.
>> x=0:pi/40:4*pi;
>>plot( x, sin(x))
The basic command for producing a simple 2-D plot is:
plot(x values, y values, ‘style option’)
where
• x values and y values are vectors containing the x- and y-coordinates of points on the
graph.
• Style option is an optional argument that specifies the color, line-style and the point-
marker style.

 The different color, line-style and marker-style options are summarized below.

You can also combine several specifieres. For example, if you want to use square green markers
connected by green dashed lines, you could enter:

19
>> x=0:pi/40:4*pi;
>>plot( x, sin(x),'s--g‘)
You can customize the graph a bit with commands such as the following:
>>x=0:pi/40:4*pi;
>>plot(x,sin(x),'s--g')
>>title('plot of x Vs sin(x)')
>>xlabel('value of x')
>>ylabel('value of sin(x)')
Multiple curves can appear on the same graph. if for example we define another vector,
>>z=cos(x);
We can get both graphs on the same axis , distinguished by their line type, using
>>plot( x, y, ’r--’,x , z , ’b:’)
The resulting graph can be seen below, with the red dashed line representing y=sin (x) and the
blue dotted line representing z= cos(x).

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 2 4 6 8 10 12 14

When multiple curves appear on the same axis, it is good idea to create a legend to label and
distinguish them. The command legend does exactly this.

20
>>legend (‘sin(x)’ , ‘cos(x) ’)
1
sin(x)
0.8 cos(x)

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 2 4 6 8 10 12 14

Specialized 2-D Plots

• There are several specialized graphics functions available in MATLAB for 2-D plots.
• The list of functions commonly used in MATLAB for plotting x-y data are given in the
following Table.

For example:

>>area(x, sin(x)) will generate the following area graph.

21
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 2 4 6 8 10 12

Examples
1.Plot the graph of y=log(x), for x=0:10
>>x=1:0.1:10;
>> y=log(x);
>>plot(x,y,'c--*');
>>title('plot of log(x)');
>>xlabel('x');
>>ylabel('log(x)')
plot of log(x)
2.5

1.5
log(x)

0.5

0
1 2 3 4 5 6 7 8 9 10
x

2.Obtain the plot of the functions y= x 2, z= x 3for x=-1 to 1 on the same axis. Label the x and y
axes and create a legend indicating which graph is which.

>> x=-1:.01:1;

22
>> y=x.^2;

>> z=x.^3;

>> plot(x,y,'b-',x,z,'g-');

>>xlabel('value of x');

>>ylabel('value of y and z');

>> legend('x^2','x^3')

1
x2
0.8
x3
0.6

0.4
value of y and z

0.2

-0.2

-0.4

-0.6

-0.8

-1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
value of x

3-D plots
• MATLAB has a variety of functions for displaying and visualizing data in 3-D,either as
lines in 3-D, or as various types of surfaces.

23
• Some of commonly used functions in 3-D graphics are listed below.

command Description
plot3 Plots three-dimensional graph of the trajectory of a set of three parametric
equations x(t),
y(t), and z(t) can be obtained using plot3(x,y,z).
meshgrid If x and y are two vectors containing a range of points for the evaluation of a
function,
[X,Y] = meshgrid(x, y) returns two rectangular matrices containing the x and y
values at
each point of a two-dimensional grid.
surf Produces a three-dimensional perspective drawing. Its use is usually to draw
surfaces, as
opposed to plotting functions, although the actual tasks are quite similar. The
output of
surfwill be a shaded figure. If row vectors of length n are defined by x = r cos θ
and y =
rsin θ, with 0 ≤ θ ≤ 2π, they correspond to a circle of radius r. If r􀁇 is a column
vector
equal to r = [0 1 2]’; then z = r*ones(size(x)) will be a rectangular, 3 × n, arrays
of 0’s
and 2’s, and surf(x, y, z) will produce a shaded surface bounded by three circles;
i.e., a
cone.
grid grid on adds grid lines to a two-dimensional or three-dimensional graph; grid off
removes
them
mesh(X,Y,z If X and Y are rectangular arrays containing the values of the x and y coordinates
) at each
point of a rectangular grid , and if z is the value of a function evaluated at each of
these
points, mesh(X,Y,z) will produce a three-dimensional perspective graph of the
points.
The same results can be obtained with mesh(x,y,z) can also be used.

plot3
The function plot3 is the 3-D version of plot. The command plot3(x, y, z) draws a 2-D projection
of a line in 3-D through the points whose coordinates are the elements of the vectors x, y and z.

24
For example, the command:

>>plot3(rand(1,10), rand(1,10), rand(1,10))

Generates 10 random points in 3-D space, and joins them with lines, as shown in Figure below.

0.8

0.6

0.4

0.2

0
1
1
0.8
0.5 0.6
0.4
0.2
0 0

Example for meshgrid and surf graphs

>>[X,Y]=meshgrid(-3:0.1:3,-3:0.1:3);

>>z=3*(1-X).^2.*exp(-(X.^2)-(Y+1).^2)-10*(Y/5-X.^3-
Y.^5).*exp(-X.^2-Y.^2)-1/3*exp(-(X+1).^2-Y.^2);

>>surf(z) peaks

>>xlabel('X')
10
>>ylabel('Y')
5
>>zlabel('Z')
0
Z

>>title('peaks')
-5

-10
80
60 80
40 60
40
20 20
Y 0 0
X

Examples
(a) Using plot3 Plot the parametric space curve of

x ( t ) = t , y ( t ) = t 2 ,z ( t ) = t 3; 0 ≤ t ≤ 1.0

25
(b) Drawthesurface z = x 2- y 2; for0 ≤ x ≤ 5, 0 ≤ y ≤ 5

(c) The initial heat distribution over a steel plate is given by the function
2 2
u(x, y) = 80 y 2 e−x −0.3 y ,

Plot the surface u over the grid defined by−2.1 ≤ x ≤ 2.1, −6 ≤ y ≤ 6,

Solution

(a) 1

>> t=0:0.0001:1; 0.8

0.6

>> x=t;y=t.^2;z=t.^3; 0.4

0.2
>> plot3(x,y,z),grid
0
1
1
0.8
0.5 0.6
0.4
0.2
0 0

(b)

>> [x,y]=meshgrid(0:0.25:5);
30

>> z=x.^2-y.^2; 20

10

>> mesh(z) 0

-10

-20

-30
30
25
20
20
15
10 10
5
0 0

100

80

60

40

(c) 20

0
100
26
30
50 20
10
0 0
>> [x,y]=meshgrid(-2.1:0.15:2.1,-6:0.15:6);

>> u=80.*(y.^2).*(exp((-x.^2)-0.3.*(y.^2)));

>>surf(u)

EXERCISES

1. Use the linspace function to create a row vector called meshPoints containing exactly
1000values with values evenly spaced between -1 and 1. Do not print all 1000 values!

2. What expression will yield the value of the 95th element of meshPoints? What is this value?

3. Double-click on the variable meshPoints in the \Current workspace" windowpane to view it


as a vector and confirm its length is 1000.

4. Produce a plot of a sinusoid on the interval [-1,1] using the command


plot(meshPoints,sin(2*pi*meshPoints))

Lab 3
Programming in MATLAB and Conditional statements
Objectives

27
 To know the types of programs in mat lab
 To have a basic understanding of Conditional Statements
 if-end
 if-else-end,
 if-elseif-else-end

3.1 Programming in MatLab

In Matlab, programs may be written and saved in files with a suffix .m called M-files. There
aretwo types of M-file programs: functions and scripts.

Function Programs

Begin by clicking on the new document icon in the top left of the Matlab window (it looks like
an empty sheet of paper). In the document window type the following:

function y = myfunc(x)
y = 2*x.^2 - 3*x + 1;

Save this file as: myfunc.minyour working directory. This file can now be used in the command
window just like any predefined Matlab function; in the command window enter:
>> x = -2:.1:2; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Produces a vector ofx values.
> y = myfunc(x); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Produces a vector ofy values.
>plot(x,y)

Note that the fact we used x and y in both the function program and in the command window
was just a coincidence. In fact, it is the name of the filemyfunc.mthat actually mattered, not what
anything in it was called. We could just as well have made the function

function nonsense = yourfunc(inputvector)


nonsense = 2*inputvector.^2 - 3*inputvector + 1;

Let us see a simple example . The text below is saved in a file called log3.m and it is used to
calculate the base three logarithm of a positive number.

function [a]=log3(x)

28
%[a]=log3(x)-calculate the base 3 logarithm of x.
a= log(abs(x)./log(3));
%End of function
Using this function within MatLab to compute log3(5), we get
>> b=log3(5)

b =

1.4650

The text file can be created In variety of ways, for example using the built-in MatLab editor
through the command edit or your favorite (external)text editor (note pad or word pad in
Microsoft windows).You must make sure that the file name has the extension ”.m”!

Every MatLab function begins with a header, which consists of the following:

a, The word function,

b, The output(s) in brackets,(the variable a in the above example)

c, The equal sign,

d, The name of the function, which must much the function file name(log3 in the above
example )and

e, The input(s) (the variable x in the above example).

Any statement that appears after a ”%” sign on a line is ignored by MatLab and plays the role of
comments in the subroutine.

Comments are essential when writing long functions or programs, for clarity.

Functions can have multiple inputs and/or multiple outputs. Next let’s create a function that has
1input and 3 output variables. Open a new document and type:

function [x2 x3 x4] = mypowers(x)


x2 = x.^2;
x3 = x.^3;
x4 = x.^4;

Save this file as mypowers.m. In the command window, we can use the results of the program to
make graphs:
> x = -1:.1:1
29
> [x2 x3 x4] = mypowers(x);
> plot(x,x,’black’,x,x2,’blue’,x,x3,’green’,x,x4,’red’)

Example 1
1. Use the Editor to create and save (in the current MATLAB directory) the function file f.m as
follows:

function y = f(x)

y = xˆ3 + x - 3;Then;findthevalue of f(2),f(10)and f(-1)

Script Programs

Matlab uses a second type of program that differs from a function program in several ways,
namely:

• There are no inputs and outputs.

• A script program may use and change variables in the current workspace (the variables
used by the command window.)

Below is a script program that accomplishes the same thing as the function program plus the
commands in the previous section:

x2 = x.^2;
x3 = x.^3;
x4 = x.^4;
plot(x,x,’black’,x,x2,’blue’,x,x3,’green’,x,x4,’red’)

Type this program into a new document and save it as mygraphs.m. In the command window
enter:
> x = -1:.1:1;
>mygraphs
Note that the program used the variable x in its calculations, even though x was defined in the
command window, not in the program.

30
Many people use script programs for routine calculations that would require typing more than
one command in the command window. They do this because correcting mistakes is easier in a
program than in the command window.

Example 2: Quadratic root finding script

Create the file named qroots.m in your present working directory using a text editor to solve the
quadratic equation f(x)= x 2+ 5 x +6

Solution

% qroots: Quadratic root finding script


format compact;
a=1;
b=5;
c=6;
x = -b/(2*a);
y = sqrt(b^2-4*a*c)/(2*a);
s1 = x+y
s2 = x-y

To execute the script M-file, simply type the name of the script file qroots at the Matlab prompt:

>>qroots
s1 =
-2
s2 =

-3

3.2 Relational and Logical Operators

A relational operator compares two numbers by finding whether a comparison statement is true
or false.

31
A logical operator examines true/false statements and produces a result which is true or false
according to the specific operator.

MATLAB has six relational operators and three logical operators as shown in Table below.

Logical operators

3.3 Conditional statements


A conditional statement is a command that allows MATLAB to make a decision of whether to
execute a group of commands that follow the conditional statement, or to skip these commands.

In a conditional statement a conditional expression is stated. If the expression is true, a group of


commands that follow the statement is executed. If the expression is false,the computer skips the
group.

Examples:

if a < b

if c >= 5

32
if a == b

if a ~= 0

if (d<h)&(x>7)

if (x~=13)l(y<0)

N.B All the variables must have assigned values.

Conditional statements can be a part of a program written in a script file or a function file. As
shown below, for every if statement there is an end statement. The if statement is commonly
used in three structures, if-end, if-else-end, and if-elseif-else-end, which are described next.

1.Theif - end Structure:-


If the conditional expression in the if statement is true (1), the program continues to execute the
commands that follow the if statement all the way down to the end statement. If the conditional
expression is false (0), the program skips the group of commands between the if and the end, and
continues with the commands that follow the end.

Figure :The structure of the if -end conditional statement.

Example1

Write a script file that demonstrates the use of the if-end statement in which:-

-The user is asked to enter three grades.

33
- Calculates the average of the grades.

- If the average is less than 60, a massage:‘ The student did not pass the course’. is
printed.

The script file will be as follow.

score = input('Enter (as a vector) the scores of the


three tests ');

ave_grade = (score(1) + score(2) + score(3))/3;

disp('The average grade is:')

disp(ave_grade)

ifave_grade< 60

disp('The student did not pass the course.')

end
Saving the script file in the previous slide as average.m and executing in the Command Window:

>>average

Enter (as a vector) the scores of the three tests [78 61 85]

The average grade is:

74.6667

>>average

Enter (as a vector) the scores of the three tests [60 38 55]

The average grade is:

51

The student did not pass the course.

Example 2

34
A worker is paid according to his hourly wage up to 40 hours, and 50% more for overtime. Write
a program in a script file that calculates the pay to a worker. The program asks the user to enter
the number of hours and the hourly wage. The program then displays the pay.

Solution

The program in a script file is shown below. The program first calculates the pay by multiplying
the number of hours by the hourly wage. Then an if statement checks whether the number of
hours is greater than 40. If yes, the next line is executed and the extra pay for the hours above 40
is added. If not, the program skips to the end.

t = input('please enter the number of hours worked');


h = input('please enter the hourly wage in $ ');
Pay = t*h;
if t>40
Pay=Pay+(t - 40)*0.5*h;
end
fprintf('The worker''s pay is $%5.2f\n',Pay)

Application of the program

>>workerspay

please enter the number of hours worked35

please enter the hourly wage in $ 8

The worker's pay is $280.00

>>workerspay

please enter the number of hours worked50

please enter the hourly wage in $ 10

The worker's pay is $550.00

35
2. The if-else-endStructure

This structure provides a means for choosing one group of commands, out of a possible two
groups, for execution. The first line is an if statement with a conditional expression. If the
conditional expression is true, the program executes group 1 of commands between the if and the
else statements and then skips to the end.

If the conditional expression is false, the program skips to the else, and then executes group 2 of
commands between the else and the end.

Figure: The structure of the if - else - end conditional statement.

Example

Write a script file that demonstrates the use of the if-else-end statement in which :

 The user is asked to enter three grades.

 Calculates the average of the grades.

 If the average is less than 60, a massage: ‘The student did not pass the course.’ is printed.

 Otherwise, a massage:’ The student passed the course. ‘is printed.

We can edit the previous script by simply adding else statement as follow

36
score = input('Enter (as a vector) the scores of the three
tests ');
ave_grade = (score(1) + score(2) + score(3))/3;
disp('The average grade is:')
disp(ave_grade)
ifave_grade< 60
disp('The student did not pass the course.')
else
disp('The student passed the course.')
End
Executing the script file in the command window we will find the following
>>average

Enter (as a vector) the scores of the three tests [65 80 83]

The average grade is:

76

The student passed the course.

>>average

Enter (as a vector) the scores of the three tests [60 40 55]

The average grade is:

51.6667

The student did not pass the course.

3. The if-elseif-else- endStructure

This structure includes two conditional statements (if and elseif) which make it possible to select
one out of three groups of commands for execution.

The first line is an if statement with a conditional expression. If the conditional expression is
true, the program executes group 1 of commands between the if and the elseif statement and then
skips to the end. If the conditional expression in the if statement is false, the program skips to the
elseif statement.

If the conditional expression in the elseif statement is true the program executes group 2 of
commands between the elseif and the else and then skips to the end.

37
If the conditional expression in the elseif statement is false the program skips to the else and
executes group 3 of commands between the else and the end.

Figure: The structure of the if-elseif-else- end conditional statement.

Example

Write a script file that demonstrates the use of the if-elseif-else-end statement.

 The program calculates the tip in a restaurant according to the amount of the bill.

 If the bill is less than 10$ the tip is $1.80.

 Between $10 and $60 the tip is 18% of the bill.

 Above $60 the tip is 20% of the bill.

The script file and some examples are given below.

bill = input('Enter the amount of the bill (in dollars): ');


if (bill <= 10)
tip = 1.8;
elseif (bill > 10)&(bill <= 60)
tip = bill*0.18;

38
else
tip = bill*0.2;
end
disp('The tip is (in dollars):')
disp(tip)

Saving the script file as dollar.m, let us see some demonstration of the program.

>>dollar

Enter the amount of the bill (in dollars): 15

The tip is (in dollars):

2.7000

>>dollar

Enter the amount of the bill (in dollars): 6

The tip is (in dollars):

1.8000

>>dollar

Enter the amount of the bill (in dollars): 100

The tip is (in dollars):

20

3.4 Loops

A loop is another method to alter the flow of a computer program.In a loop, the execution of a
command, or a group of commands, is repeated several times consecutively.

39
for -end Loops
In for-end loops the execution of a command, or a group of commands, is repeated a
predetermined number of times.

Figure :The structure of a for-end loop.

A simple example of a for-end loop (in a script file) is:

For k= 1:3:10
x = k^2
End

Saving the file as exa.mWhen this program is executed in the command window, the loop is
executed four times.
>>exa

x =

x =

16

x =

49

x =

100

EXAMPLE 1:

Write a for loop to compute the sum of the squares of all integers from 2 to 20:

22 +32 +4 2+……..+202.

40
Solution

Sum = 0; %initialize sum

for n = 2:20

Sum = Sum + n^2;

end

Sum %This will display the final sum

When this loop is entered into the command window, the only output one sees is:

Sum = 2869

EXAMPLE 2:

Suppose that $1000.00 is left to sit in a bank account that pays 8% interest per year, compounded
annually. What is the account balance after 30 years?

Solution

Balance = 1000; %initialize Balance

for year = 1:30

Balance = (1.08)*Balance;

end

Balance %This will display the final Balance

Here is the output when these commands are entered:

Balance = 10062.66

While Loops
The while loop is used when the looping process terminates because a specified condition is
satisfied, and thus the number of passes Is not known in advance.

The typical structure of a while loop is:

while logical expression

statements

end
41
MatLabfirsts tests the truth of the logical expression.A loop variable must be included in the
logical expression.

For a while loop to function properly, the following two conditions must occur:

o The loop variable must have a value before the while statement is executed.

o The loop variable must be changed somehow by the statements.

The statements are executed once during each pass, using the current value of the loop
variable.The looping continues until the logical expression is false.

Here is a simple example of a while loop:

x = 5;

while x < 25

disp (x)

x = 2*x-1;

end

The results displayed by the disp statement are 5, 9, and 17.

The loop variable x is initially assigned the value 5, and it has this value until the statement x =
2*x –1 is encountered the first time. The value then changes to 9.

Before each pass through the loop, x is checked to see whether its value is less than 25.

If so, the pass is made. If not, the loop is skipped and the program continues to execute any
statements following the end statement.

A principal application of while loops is,when we want the loop to continue as along as a certain
statement is true. Such a task is often more difficult to do with a for loop. For example:

x = 1;

while x ~= 5

disp (x)

42
x = x + 1;

end

The statements between the while and the end are executed once during each pass, using the
current value of the loop variable x.

The looping continues until the condition, x ~= 5 is false.

The results displayed by the dispstatement are 1, 2, 3, and 4.

EXERCISE

Suppose, starting at his 25th birthday, Michael deposits $5000 at the beginning of everyyear into
a retirement annuity that pays 9% interest per year, compounded annually He wants to
retirewhen his annuity first reaches or exceeds $1 million. In how many years will he be able to
retire with thisplan?

Solution
Balance = 5000; %initialize Balance
year = 0; %initialize year counter
while Balance < 1000000
Balance = (1.09)*Balance + 5000;
year = year + 1; %update year counter
end
year, Balance %This will display the year and the
corresponding balance that first broke $1 million.

When this code is entered, the following output results: year = 34.00, Balance = 1078553.77
Thus, Michael will be able to retire at age 59, with a nest egg of $1,078,553.77.

Lab 4
Bisection Method
Objective

43
 Producing an M-file for bisection method for finding the root of a non-linear equation in
Mat Lab

Finding The Root of a Non-linear Equation In MatLab

Bisection Method

An M-file to implement bisection is displayed in the following script. It is passed the function
(func) along with lower (xl) and upper (xu) guesses. In addition, an optional stopping criterion
(es) and maximum iterations (maxit) can be entered.

The function first checks whether there are sufficient arguments and if the initial guesses bracket
a sign change. If not, an error message is displayed and the function is terminated.

It also assigns default values if maxitandesare not supplied. Then a while...break loop is
employed to implement the bisection algorithm until the approximate error falls below esor the
iterations exceed maxit.

Pseudocode for function to implement bisection

FUNCTION Bisect (xl, xu, es, imax, xr, iter, ea)


iter= 0
DO
xrold= xr
xr=(xl +xu) / 2
iter=iter+1
IF xr0 THEN
ea=ABS((xr- xrold) / xr) * 100
END IF
test =f(xl) * f(xr)
IF test <0 THEN
xu= xr
ELSE IF test >0 THEN
xl=xr
ELSE
ea= 0
END IF
IF ea<es OR iterimax EXIT
END DO
Bisect = xr

44
END Bisect

M-file to implement bisection method


function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin)
% bisect: root location zeroes
% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...):
% uses bisection method to find the root of func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = desiredrelative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by func
% output:
% root = real root
% fx = function value at root
% ea = approximate relative error (%)
% iter = number of iterations
ifnargin<3,error('at least 3 input arguments required'),end
test = func(xl,varargin{:})*func(xu,varargin{:});
if test>0,error('no sign change'),end
ifnargin<4|isempty(es), es=0.0001;end
ifnargin<5|isempty(maxit), maxit=50;end
iter = 0; xr = xl; ea = 100;
while (1)
xrold = xr;
xr = (xl + xu)/2;
iter = iter + 1;
ifxr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
if test < 0
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
ifea<= es | iter>= maxit,break,end
end
root = xr; fx = func(xr, varargin{:});

Example

(a) Use bisection method to find the first root of the function f (x) = -12-21x+18 x 2−2.75 x 3.

45
(use initial guesses of xl = −1 and xu = 0 and a stopping criterion of 1%).

Solution

>>fx=@(x)-12-21.*x+18.*x^2-2.75.*x^3;

>> [root fxeaiter]=bisect(fx,-1,0,0.01)

root =

-0.4147

fx =

5.2128e-004

ea =

0.0074

iter =

15

(b) Locate the first nontrivial root of sin(x) = x 2 where x is in radians. Use a graphical technique
and bisection with the initial interval from 0.5 to 1. Perform the computation until εais less than
εs= 2%.

Solution
>>fx=@(x)x^2-sin(x);
>>[root fxeaiter]=bisect(fx,0.5,1,0.02)
root =
0.8768
fx =
1.1678e-004
ea =
0.0139
iter =
12
(c)determine the real roots of f(x)=-2+7x-5x2+6x3:using bisection to locate the lowest root.
Employ initial guessesofxl=0 and xu=1 and iterate until the estimated error eafalls below a level of
es=10%.

46
Solution
>>fx=@(x)-2+7*x-5*x^2+6*x^3;
>> [root fxeaiter]=bisect(fx,0,1,0.1)

root =

0.3333

fx =

-4.6115e-004
ea =

0.0733
iter =

12

(d)Determine the real roots of f(x)=-26+82.3x-88x2+45.4x3-9x4+0.65x5 using bisection to


determine the highest root toes=10%.employ initial guesses of xl=0.5 and xu=1

Solution

>>fx=@(x)-26+82.3*x-88*x^2+45.4*x^3-9*x^4+0.65*x^5;

>> [root fxeaiter]=bisect(fx,0.5,1,0.1)

root =

0.5796
fx =
0.0051
ea =
0.0842
iter =
10
EXERCISES

1. Find the root of e(-x)*(x2+5x+2)+1=0 in the interval [0,-1]


2. Find the root of e(-x) = 3log(x) in the interval [0.5,1.5]

47
3. Find the root of x-e(-x) = 0 using a graphical technique and bisection method within the
interval [0,1] after 8 iterations.
4. Determine the positive real root of ln(x^2) = 0.7
(a)Graphically,

(b) Using 3 iterations of the bisection method, with initial guesses of xl = 0.5 and xu = 2,

Lab 5
Newton-Raphson Method
Objective

48
 Producing an M-file for Newton-Raphson Method

Newton-Raphson Method

Perhaps the most widely used of all root-locating formulas is the Newton-Raphson method
(Fig.A). If the initial guess at the root is xi , a tangent can be extended from the point
[xi , f (xi )]. The point where this tangent crosses the x axis usually represents an
improvedestimate of the root.
The Newton-Raphson method can be derived on the basis of this geometrical interpretation.
As in Fig. A, the first derivative at x is equivalent to the slope:
f (x i)−0
f’(xi)= x i−x i+1

which can be rearranged to yield

xi+1 = xi –(f (xi )/ f’(xi ))

which is called the Newton-Raphson formula.

Fig .A. Graphical depiction of the Newton-Raphson method. A tangent to the function of xi [that
is,f‘(x)] is extrapolated down to the x axis to provide an estimate of the root at xi+1.

49
An algorithm for the Newton-Raphson method can be easily developed .Note thatthe program
must have access to the function (func) and its first derivative (dfunc). These can be simply
accomplished by the inclusion of user-defined functions to compute these quantities.
Alternatively, as in the algorithm in the following script file, they can be passed to the function
as arguments.

Pseudocode for function to implement Newton raphson

FUNCTION Newtraph (xl, xu, es, imax, xr, iter, ea)


iter= 0
DO
xrold= xr
xr =xr - f (xr)/df(xr);
iter=iter+1
IF xr0 THEN
ea=ABS((xr- xrold) / xr) * 100
END IF
test =f(xl) * f(xr)
IF test <0 THEN
xu= xr
ELSE IF test >0 THEN
xl=xr
ELSE
ea= 0

END IF

IF ea<es OR iterimax EXIT

END DO

Newtraph= xr

END Newtraph

An M-file to implement the Newton-Raphson method

function[root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,varargin)

50
% newtraph: Newton-Raphson root location zeroes
% [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,p1,p2,...):
% uses Newton-Raphson method to find the root of func
% input:
% func = name of function
% dfunc = name of derivative of function
% xr = initial guess
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by function
% output:
% root = real root
% ea = approximate relative error (%)
% iter = number of iterations
ifnargin<3,error('at least 3 input arguments required'),end
ifnargin<4|isempty(es),es=0.0001;end
ifnargin<5|isempty(maxit),maxit=50;end
iter = 0;
while (1)
xrold = xr;
xr = xr - func(xr)/dfunc(xr);
iter = iter + 1;
ifxr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
ifea<= es | iter>= maxit, break, end
end
root = xr;

EXAMPLES
1.Determine the positive root of f (x) = x10 − 1 using the Newton- Raphson method and an initial
guess of x = 0.5.
51
Solution

>>fx=@(x)x^10-1;

>>dfx=@(x)10*x^9;

>> [root eaiter]=newtraph(fx,dfx,0.5)

root =

ea =

2.5776e-007

iter =

43

But if we need only the root we can use the following format:

>>fx=@(x)x^10-1;

>>dfx=@(x)10*x^9;

>>newtraph(fx,dfx,0.5)

ans =

1
2. Use the Newton- Raphson method to determine a root of f (x) = −0.9x2+1.7x + 2.5
usingx0= 5. Perform the computation until εais less than εs= 0.01%.
Solution
>>fx=@(x)-0.9*x^2+1.7*x+2.5;

>>dfx=@(x)-1.8*x+1.7;

>> [root eaiter]=newtraph(fx,dfx,5,0.0001)

root =

52
2.8601

ea =

9.9139e-006

iter =

3.Determine the highest real root of f (x) = x3− 6x2+11x − 6.1Using the Newton-Raphson method
(three iterations,xi= 3.5).
>>fx=@(x)x^3-6*x^2+11*x-6.1;

>>dfx=@(x)3*x^2-12*x;

>> [root ea]=newtraph(fx,dfx,3.5,3)

root =

2.3552

ea =

1.5903

EXERCISE

1. Approximate the only solution to the equation x= cos(x) with initial guess x=1
2. f(x) = x-2+lnx has a root near x =1.5. Use newton-raphson method to obtain a better
method.

Lab 6
Linear Least Square Regression
Objective
 To use linear least square regression M-file for curve fitting

53
6.1 Curve Fitting and Interpolation
Discrete data sets or tables of the form
x1 x2 … x3 xn
y1 y2 … y3 yn
are commonly involved in technical calculations. The source of the data may be
experimentalobservations or numerical computations. There is a distinction betweeninterpolation
and curve fitting. In interpolationweconstruct a curve through the datapoints. Indoing so,wemake
the implicit assumption that the datapoints are accurateand distinct.Curve fitting is applied to
data that contain scatter (noise), usuallydue tomeasurement errors. Herewe want tofind a smooth
curve that approximates the datain some sense. Thus the curve does not have to hit the data
points. This differencebetween interpolation and curve fitting is illustrated in Figure below.

6.2 Linear Least-squares Regression


Regression describes the relationship between two variables in the situation where one variable
can be used to explain or predict the other.The regression line is a straight line that describes how
a dependent variable y changes as an Independent variable x changes.
The least-squares regression line of y on x is the line that minimizes sum of squared errors.Given
pairs of observations (x1,y1)….. (xn, yn), the regression line is given by:
y = ao + a1x
Where :ao&a1 are the intercept and slope and
Can be calculated as:
n Ʃx i y i− Ʃx i Ʃy i
ao=y¯ − a1x ¯ and a1= 2 ¿2
nƩ xi −( Ʃ xi )

54
The slope of the line indicates how much y changes for a unit change in x.r2 (the square of the
correlation) is the fraction of the variation in the values of y that is explained by the least squares
regression on x.
An algorithm for linear regression can be easily developed as shown in the following M-File.The
required summations are readily computed with MATLAB’s sum function. The routine displays
the intercept and slope, the coefficient of determination, and a plot of the best-fit line along with
the measurements.
Pseudocode for Linear regression
SUB Regress(x, y, n, al, a0, syx, r2)
sumx=0: sumxy= 0: st=0
sumy= 0: sumx2 = 0: sr=0
DOFOR i= 1, n
sumx=sumx+ xi
sumy=sumy+yi
sumxy= sumxy+xi*yi
sumx2 = sumx2 +xi*xi
END DO
xm= sumx/n
ym=sumy/n
a1 =(n*sumxy- sumx*sumy)/(n*sumx2 - sumx*sumx)
a0 =ym-a1*xm
DOFOR i= 1, n
st=st+(yi-ym)2
sr=sr+ (yi-a1*xi -a0)2
END DO
syx= (sr/(n -2))0.5
r2 = (st-sr)/st
END Regress

M-file to implement linear regression


function [a, r2] = linregr(x,y)
% linregr: linear regression curve fitting

55
% [a, r2] = linregr(x,y): Least squares fit of straight
% line to data by solving the normal equations
% input:
% x = independent variable
% y = dependent variable
% output:
% a = vector of slope, a(1), and intercept, a(2)
% r2 = coefficient of determination
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
x = x(:); y = y(:); % convert to columnvectors
sx = sum(x); sy = sum(y);
sx2 = sum(x.*x); sxy = sum(x.*y); sy2 = sum(y.*y);
a(1) = (n*sxy-sx*sy)/(n*sx2—sx^2);
a(2) = sy/n—a(1)*sx/n;
r2 = ((n*sxy—sx*sy)/sqrt(n*sx2—sx^2)/sqrt(n*sy2—sy^2))^2;
% create plot of data and best fit line
xp = linspace(min(x),max(x),2);
yp = a(1)*xp+a(2);
plot(x,y,'o',xp,yp)
gridon

Example
1, Fit a straight line to the values in table below.

xi 10 20 30 40 50 60 70 80

yi 25 70 380 550 610 1220 830 1450


1600

1400

1200

1000

800

Solution 600

400
56
200

-200
10 20 30 40 50 60 70 80
>>x=[10 20 30 40 50 60 70 80];

>>y=[25 70 380 550 610 1220 830 1450];


>>[a r2]=linregr(x,y)
a =
19.4702 -234.2857
r2 =
0.8805
Where a is vector of slope 19.4702 and intercept -234.2857
And r2 = coefficient of determination

2.Use least-squares regression to fit a straight line to

x 0 2 4 6 9 11 12 15 17 19

y 5 6 7 6 9 8 8 10 12 12

Along with the slope and intercept, Plot the data and the regression line.

Solution

>> x=[0 2 4 6 9 11 12 15 17 19];


>> y=[5 6 7 6 9 8 8 10 12 12];
>> [a r2]=linregr(x,y)
a =
0.3591 4.8881
r2 =
0.8929

57
12

11

10

4
0 2 4 6 8 10 12 14 16 18 20

EXERCISE

Consider the following data on 12 trees. The age of the tree and their size is given bellow. Fit the
given data to know the relationship between the size and age of the tree.

58
Lab7
Polynomial Interpolation
Objectives
 To Determining Polynomial Coefficients using MATLAB functions: polyfit and polyval
 Producing M-files for new Newton’sinterpolating polynomials
 Producing M-files for new Lagrangeinterpolating polynomials

Polynomial Interpolation
Interpolation is a method of constructing new data points within the range of a discrete set of
known data points. We will frequently have occasion to estimate intermediate values between
precise data points.The most common method used for this purpose is polynomial interpolation.
General formula for an (n−1)th-order polynomial can be written as:
f (x) = a1 + a2x + a3x2 + ・・・ + anxn−1
For n data points, there is one and only one polynomial of order (n − 1) that passes through all
the points.For example, there is only one straight line (i.e., a first-order polynomial) that
connects two points.Similarly, only one parabola connects a set of three points.
Examples of interpolating polynomials:
(a) first-order (linear) connecting two points,
(b) second-order (quadratic or parabolic) connecting three points, and
(c) third-order (cubic)connecting four points.

MATLAB represents polynomial coefficients in a different manner than the above


equation.Rather than using increasing powers of x, it uses decreasing powers as in:
f (x) = p1 n-1 + p2 x n-2 + ・・・ + pn−1 x + pn

59
8.1 Determining Polynomial Coefficients using MATLAB functions: polyfit and
polyval

For the case where the number of data points equals the number of coefficients, polyfit performs
interpolation.That is, it returns the coefficients of the polynomial that pass directly through the
data points.For example, it can be used to determine the coefficients of the parabola that passes
through the last three density values from the following Table.

>>format long
>> T = [300 400 500];
>> D= [0.616 0.525 0.457];
>> p = polyfit(T,D,2)
p=
0.000001150000000 -0.001715000000000 1.026999999999995
We can then use the polyval function to perform an interpolation as follow:
>> I= polyval(p,350)
I=
0.56762500000000

8.2 Newton’s Interpolating Polynomials

The general form of Newton’s Interpolating Polynomials is used to fit an (n − 1)th-order


polynomial to n data points. The (n − 1)th-order polynomial is:
fn−1(x) = b1 + b2(x − x1) + ・・・ + bn(x − x1)(x − x2)・・・(x − xn−1)

60
 

It is straightforward to develop an M-file to implement Newton interpolation.The first step is to


compute the finite divided differences and store them in an array. The differences are then used
in conjunction with Eq.
fn−1(x) = f (x1) + (x − x1) f [x2, x1] + (x − x1)(x − x2) f [x3, x2, x1]+ ・・・ + (x − x1)(x − x2)
・・・ (x − xn−1) f [xn, xn−1, . . . , x2, x1]
to perform the interpolation.

An M-file to implement Newton interpolation.


functionyint = Newtint(x,y,xx)
% Newtint: Newton interpolating polynomial
% yint = Newtint(x,y,xx): Uses an (n - 1)-order Newton
% interpolating polynomial based on n data points (x, y)
% to determine a value of the dependent variable (yint)
% at a given value of the independent variable, xx.
% input:
% x = independent variable
% y = dependent variable
% xx = value of independent variable at which
% interpolation is calculated
% output:
% yint = interpolated value of dependent variable
% compute the finite divided differences in the form of a
% difference table
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
b = zeros(n,n);
% assign dependent variables to the first column of b.
b(:,1) = y(:); % the (:) ensures that y is a column vector.
for j = 2:n
fori = 1:n-j+1
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i));
end

61
end
% use the finite divided differences to interpolate
xt = 1;
yint = b(1,1);
for j = 1:n-1
xt = xt*(xx-x(j));
yint = yint+b(1,j+1)*xt;
end

Example
1. Employ a second-order Newton polynomial to estimate ln 2 using the points ln 1 = 0 , ln
4 =1.386294 ,ln 6 = 1.791759 and ln 5 =1.609438
Solution
>>format long
>>x = [1 4 6 5]';
>>y = log(x);
>>Newtint(x,y,2)
ans =
0.628768578908414

8.3 Lagrange Interpolating Polynomial

The general Lagrange interpolating polynomial formula is:


n
f n−1( x )=∑ Li ( x ) f ( xi)
i=1

where the L’s are the weighting coefficients and represented as:
n
x−xj
∏ xi−xj
j=1
j≠1

Where n= the number of data points and  -designates the ‘’product of’’.

It is straightforward to develop an M-file based on the above two equations.The function is


passed two vectors containing the independent (x) and the dependent (y) variables. It is also
passed the value of the independent variable where you want to interpolate (xx). The order of the
polynomial is based on the length of the x vector that is passed. If n values are passed, an
(n− 1)th order polynomial is fit.

62
An M-file to implement Lagrange interpolation.
functionyint = Lagrange(x,y,xx)
% Lagrange: Lagrange interpolating polynomial
% yint = Lagrange(x,y,xx): Uses an (n - 1)-order
% Lagrange interpolating polynomial based on n data points
% to determine a value of the dependent variable (yint) at
% a given value of the independent variable, xx.
% input:
% x = independent variable
% y = dependent variable
% xx = value of independent variable at which the
% interpolation is calculated
% output:
% yint = interpolated value of dependent variable
n = length(x);
if length(y)~=n, error('x and y must be same length'); end
s = 0;
fori = 1:n
product = y(i);
for j = 1:n
ifi ~= j
product = product*(xx-x(j))/(x(i)-x(j));
end
end
s = s+product;
end
yint = s;

Example
Predict the density of air at 1 atm pressure at a temperature of 15 °C based on the first four
values from Table below.

63
Solution

>>format long

>>T = [-40 0 20 50];

>>d = [1.52 1.29 1.2 1.09];

>>density = Lagrange(T,d,15)

density =

1.221128472222222

EXERCISE

1. Use Newton’s interpolating polynomial to determine y at x = 8.

x 0 1 2 5.5 11 13 16 18

y 0.5 3.134 5.3 9.9 10.2 9.35 7.2 6.2

2. The following data for the density of nitrogen gas versus temperature come from a table that
was measured with high precision. Use fifth-order polynomial to estimate the density at a
temperature of 330 K.
T, K 200 250 300 350 400 450

Density (kg/m3)1.708 1.367 1.139 0.967 0.854 0.759

64
Lab 8
Solutions of Systems of Linear Algebraic Equation
Objective

 To produce M-files for solving linear algebraic equations


o Gauss Elimination
o LU Factorization
o Cholesky Factorization

Solutions of Systems of Linear Algebraic Equation

Linear algebraic equations have a general form of:


a11x1 + a12x2 +・・・+a1nxn= b1
a21x1 + a22x2 +・・・+a2nxn= b2
  . . . .
. . . .
. . . .
an1x1 + an2x2 +・・・+annxn= bn
Where the a’s are constant coefficients, the b’s are constants, the x’s are unknowns, and n is the
number of equations.

Representing Linear Algebraic Equations in Matrix Form

Matrices provide a concise notation for representing simultaneous linear equations. For example,
a 3 × 3 set of linear equations,
a11x1 + a12x2 + a13x3 = b1
a21x1 + a22x2 + a23x3 = b2
a31x1 + a32x2 + a33x3 = b3
Can be expressed as:
[A]{x} = {b}
Where:
[A] is the matrix of coefficients:
{b} is the column vector of constants:
{b}T = [b1 b2b3]
And {x} is the column vector of unknowns:

65
{x}T=[ x1x2x3]

8.1 Gauss Elimination

The approach is designed to solve a general set of nequations:

a11x1 + a12x2 +・・・+a1nxn= b1 ………..(1)


a21x1 + a22x2 +・・・+a2nxn= b2 ………...(2)
  . . . .
. . . .
. . . .
an1x1 + an2x2 +・・・+annxn= bn…………(3)

The first phase is designed to reduce the set of equations to an upper triangular system. The
initial step will be to eliminate the first unknown x1 from the second through the nth equations.
To do this, multiply Eq.1 by a21/a11 to give:

This equation can be subtracted from Eq. 2 to gives:

The procedure is then repeated for the remaining equations.Perform a similar elimination for the
remaining equations to yield

The above equation can now be solved for xn:

An M-file to implement naive Gauss elimination.


function x = GaussNaive(A,b)
% GaussNaive: naive Gauss elimination

66
% x = GaussNaive(A,b): Gauss elimination without
pivoting.
% input:
% A = coefficient matrix
% b = right hand side vector
% output:
% x = solution vector
[m,n] = size(A);
if m~=n, error('Matrix A must be square'); end
nb = n+1;
Aug = [A b];
% forward elimination
for k = 1:n-1
fori = k+1:n
factor = Aug(i,k)/Aug(k,k);
Aug(i,k:nb) = Aug(i,k:nb)-factor*Aug(k,k:nb);
end
end
% back substitution
x = zeros(n,1);
x(n) = Aug(n,nb)/Aug(n,n);
fori = n-1:-1:1
x(i) = (Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);
end

Example
Use Gauss elimination to solve

3x1 − 0.1x2 − 0.2x3 = 7.85

0.1x1 + 7x2 − 0.3x3 = −19.3

0.3x1 − 0.2x2 + 10x3 = 71.4

Solution

>>A=[3 -0.1 -0.2;0.1 7 -0.3;0.3 -0.2 10];

67
>>b=[7.85;-19.3;71.4];

>>x=GaussNaive(A,b)

x =

3.0000

-2.5000

7.0000

8.2 LU Factorization

MATLAB has a built-in function lu that generates the LU factorization. It has the general syntax:

[L,U] = lu(X)

WhereL and U are the lower triangular and upper triangular matrices, respectively.

Example

Use MATLAB to compute the LU factorization and find the solution for the same linear system
analyzed in the previous example.

Solution

The coefficient matrix and the right-hand-side vector can be entered as

>> A =[3 -0.1 -0.2;0.1 7 -0.3;0.3 -0.2 10];

>> b = [7.85; -19.3; 71.4];

Next, the LU factorization can be computed with

>> [L,U] = lu(A)

68
L =

1.0000 0 0

0.0333 1.0000 0

0.1000 -0.0271 1.0000

U =

3.0000 -0.1000 -0.2000

0 7.0033 -0.2933

0 0 10.0120

To generate the solution, we first compute

>> d = L\b

d =

7.8500

-19.5617

70.0843

And then use this result to compute the solution

>> x = U\d

x =

3.0000

-2.5000

7.0000

69
8.3 Cholesky Factorization

MATLAB has a built-in function chol that generates the Cholesky factorization. It has the
general syntax,
U = chol(X)
whereU is an upper triangular matrix so that U'*U = X. The following example shows how it can
be employed to generate both the factorization and a solution for the matrix.
Example:Compute the Cholesky factorization for the symmetric matrix given below using
MatLab.

6 15 55

[
[A]= 15 55 225
55 225 979 ]
Also obtain a solution for a right-hand-side vector that is the sum of the rows of [A]. Notethat for
this case, the answer will be a vector of ones.
Solution
The matrix is entered in standard fashion as
>> A = [6 15 55; 15 55 225; 55 225 979];

A right-hand-side vector that is the sum of the rows of [A] can be generated as

>> b = [sum(A(1,:)); sum(A(2,:)); sum(A(3,:))]


b=
76
295
1259

Next, the Cholesky factorization can be computed with

>> U = chol(A)
U=
2.4495 6.1237 22.4537
0 4.1833 20.9165
0 0 6.1101

70
We can test that this is correct by computing the original matrix as

>> U'*U
ans =
6.0000 15.0000 55.0000
15.0000 55.0000 225.0000
55.0000 225.0000 979.0000

To generate the solution, we first compute


>> d = U'\b
d=
31.0269
25.0998
6.1101
And then use this result to compute the solution
>> x = U\d
x=
1.0000
1.0000
1.0000

EXERCISE
1. Determine the LU factorization without pivoting using Mat Lab for the following matrix
8 5 1

[ ]
[A] = 3 7 4
2 3 9

2. Solve the following set of equations with LU factorizationwith pivoting:


3x1 − 2x2 + x3 = −10
2x1 + 6x2 − 4x3 = 44
−8x1 − 2x2 + 5x3 = −26

3.Compute the Cholesky factorization of

71
9 0 0

[
[A] = 0 25 0
0 0 16 ]
Lab 9
Newton-Cotes closed integration formulas
Objectives

 Knowing how to implement composite Newton-Cotes formulas using Mat Lab:


o Trapezoidal rule
o Simpson’s 1/3 rule

What Is Integration?

According to the dictionary definition, “to integrate means “to bring together, as parts, into a
whole; to unite; to indicate the total amount. . . .” “Mathematically, definite integration is
represented by:

I=∫ fx dx
a

which stands for the integral of the function f (x) with respect to the independent variable x,
evaluated between the limits x = a to x = b.

As suggested by the dictionary definition, the “meaning” of the above equation is the total value,
or summation, of f(x) dx over the range x = a to b. In fact, the symbol ∫is actually a stylized
capital S that is intended to signify the close connection between integration and summation.

The Trapezoidal Rule


The trapezoidal rule is the first of the Newton-Cotes closed integration formulas. It corresponds
to the case where the polynomial in the following equation is first-order:

The result of the integration is

72
Geometrically, the trapezoidal rule is equivalent to approximating the area of thetrapezoid under
the straight line connecting f (a) and f (b) in the following Figure.

Recall from geometrythat the formula for computing the area of a trapezoid is the height times
the average of the bases. In our case, the concept is the same but the trapezoid is on its side.
Therefore, the integral estimate can be represented as:

I = width × average height

Or,

I = (b − a) × average height …… Eqn. a

where, for the trapezoidal rule, the average height is the average of the function values at the end
points, or [ f (a) + f (b)]/2.

The Composite Trapezoidal Rule

One way to improve the accuracy of the trapezoidal rule is to divide the integration interval
froma to b into a number of segments and apply the method to each segment (see Figure below).
The areas of individual segments can then be added to yield the integral for the entire interval.
The resulting equations are called composite, or multiple-segment, integration formulas.

73
The figure shows the general format and nomenclature we will use to characterize composite
integrals. There are n + 1 equally spaced base points (x0, x1, x2, . . . ,xn). Consequently, there are
n segments of equal width:
b−a
h= n ……………. Eqn.1
If a and b are designated as x0 and xn, respectively, the total integral can be represented
As:
x1 x2 xn

I=∫ f ( x ) dx+∫ f ( x )dx +… ∫ f ( x) dx


x0 x1 xn−1

Substituting the trapezoidal rule for each integral yields

Eqn.2

or grouping terms:

Eqn.3

or, using Eq. (1) to express Eq. (3) in the general form of Eqn.a above.

74
Eqn. 4

A simple algorithm to implement the composite trapezoidal rule can be written as in the
following M-file. The function to be integrated is passed into the M-file along with the limits of
integration and the number of segments. A loop is then employed to generate the integral
following Eqn 4.

M-file to implement the composite trapezoidal rule.


function I = trap(func,a,b,n,varargin)
% trap: composite trapezoidal rule quadrature
% I = trap(func,a,b,n,pl,p2,...):
% composite trapezoidal rule
% input:
% func = name of function to be integrated
% a, b = integration limits
% n = number of segments (default = 100)
% pl,p2,... = additional parameters used by func
% output:
% I = integral estimate
ifnargin<3,error('at least 3 input arguments required'),end
if ~(b>a),error('upper bound must be greater than lower'),end
ifnargin<4|isempty(n),n=100;end
x = a; h = (b - a)/n;
s=func(a,varargin{:});
fori = 1 : n-1
x = x + h;
s = s + 2*func(x,varargin{:});
end
s = s + func(b,varargin{:});
I = (b - a) * s/(2*n);

75
Example

Estimate the integral of the function f (x) = 0.2 + 25x − 200x2 + 675x3 − 900x4 + 400x5 from

x = 0 to 0.8the composite trapezoidal rule. The exact value is 1.640533.

Solution

fx=@(x)0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5;

>> I = trap(fx,0,0.8,10)

I =

1.6150

Trapezoidal Rule with Unequal Segments


To this point, all formulas for numerical integration have been based on equispaced data points.
In practice, there are many situations where this assumption does not hold and we must deal with
unequal-sized segments. For example, experimentally derived data are often of this type. For
these cases, one method is to apply the trapezoidal rule to each segment and sum the results:

Eqn.5

where hi = the width of segment i. Note that this was the same approach used for the composite
trapezoidal rule. The only difference between Eqs. (2) and (5) is that the h’sin the former are
constant.

A simple algorithm to implement the trapezoidal rule for unequally spaced data can be written as
in the following M-file. Two vectors, x and y, holding the independent and dependent variables
are passed into the M-file. Two error traps are included to ensure that (a) the two vectors are of
the same length and (b) the x’s are in ascending order. A loop is employed to generate the
integral. Notice that the subscripts are modified from those of Eq. (5) to account for the fact that
MATLAB does not allow zero subscripts in arrays.

76
M-file to implement the trapezoidal rule for unequally spaced data
function I = trapuneq(x,y)
% trapuneq: unequal spaced trapezoidal rule quadrature
% I = trapuneq(x,y):
% Applies the trapezoidal rule to determine the integral
% for n data points (x, y) where x and y must be of the
% same length and x must be monotonically ascending
% input:
% x = vector of independent variables
% y = vector of dependent variables
% output:
% I = integral estimate
ifnargin<2,error('at least 2 input arguments required'),end
if any(diff(x)<0),error('x not monotonically ascending'),end
n = length(x);
if length(y)~=n,error('x and y must be same length'); end
s = 0;
for k = 1:n-1
s = s + (x(k+1)-x(k))*(y(k)+y(k+1))/2;
end
I = s;

Example: The information in Table below was generated using the same polynomial employed
in the previous example. Use Mat Lab to determine the integral for thesedata.Recall that the
correct answer is 1.640533.

77
Solution

>> x = [0 .12 .22 .32 .36 .4 .44 .54 .64 .7 .8];


>> y = 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5;
>>trapuneq(x,y)
ans =
1.5948

MATLAB Functions: trapz and cumtrapz

MATLAB has a built-in function that evaluates integrals for data in the same fashion as the

M-file presented above. It has the general syntax

z = trapz(x, y)

where the two vectors, x and y, hold the independent and dependent variables, respectively.

Here is a simple MATLAB session that uses this function to integrate the data from the above
table:

>> x = [0 .12 .22 .32 .36 .4 .44 .54 .64.7 .8];

>> y = 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5;

>>trapz(x,y)

ans =

1.5948

In addition, MATLAB has another function, cumtrapz, that computes the cumulativeintegral. A
simple representation of its syntax is

z = cumtrapz(x, y)

where the two vectors, x and y, hold the independent and dependent variables, respectively, and
z = a vector whose elements z(k) hold the integral from x(1) to x(k).

78
EXERCISE
1. Integrate the function f(x) = 1/x from [e,2e] using trapezoidal rule.
2. Integrate the function f(x)=ex2in the interval [o,1]
3. The function

f (x) = e−x

can be used to generate the following table of unequally spaced data:

Evaluate the integral from a = 0 to b = 0.6 using the trapezoidal rule,

79
Lab 10
Romberg integration
Objective

 To introduce anM-file for Romberg integration.


 Knowing how to use MATLAB’s built-in functions quad and quadl to integrate
functions.

Romberg Integration

The M-file for Romberg integration can be developed as shown below. By using loops, this
algorithm implements the method in an efficient manner. Note that the function uses another
function trap to implement the composite trapezoidal rule evaluations.

M-file to implement Romberg integration

function [q,ea,iter]=romberg(func,a,b,es,maxit,varargin)
% romberg: Romberg integration quadrature
% q = romberg(func,a,b,es,maxit,p1,p2,...):
% Romberg integration.
% input:
% func = name of function to be integrated
% a, b = integration limits
% es = desired relative error (default = 0.000001%)
% maxit = maximum allowable iterations (default = 30)
% pl,p2,... = additional parameters used by func
% output:
% q = integral estimate
% ea = approximate relative error (%)
% iter = number of iterations
ifnargin<3,error('at least 3 input arguments required'),end
ifnargin<4||isempty(es), es=0.000001;end

80
ifnargin<5||isempty(maxit), maxit=50;end
n = 1;
I(1,1) = trap(func,a,b,n,varargin{:});
iter = 0;
whileiter<maxit
iter = iter+1;
n = 2^iter;
I(iter+1,1) = trap(func,a,b,n,varargin{:});
for k = 2:iter+1
j = 2+iter-k;
I(j,k) = (4^(k-1)*I(j+1,k-1)-I(j,k-1))/(4^(k-1)-1);
end
ea = abs((I(1,iter+1)-I(2,iter))/I(1,iter+1))*100;
ifea<=es, break; end
end
q = I(1,iter+1);

Example: Use Romberg integration to evaluate the integral of f (x) =0.2 + 25x − 200x2+ 675x3−
900x4+ 400x5 from a = 0 to b = 0.8.

Solution
>> f=@(x) 0.2+25*x-200*x^2+675*x^3-900*x^4+400*x^5;
>>romberg(f,0,0.8)
ans =
1.6405

MATLAB Functions: quad and quadl

MATLAB has two functions, both based on algorithms developed by Gander and
Gautschi(2000), for implementing adaptive quadrature:

 quad. This function uses adaptive Simpson quadrature. It may be more efficient for low
accuracies or nonsmooth functions.

81
 quadl. This function uses what is called Lobatto quadrature. It may be more efficient for
high accuracies and smooth functions.

The following function syntax for the quad function is the same for the quadlfunction:

q = quad(fun, a, b, tol, trace, p1, p2, . . .)

where fun is the function to be integrated, a and b = the integration bounds, tol= the desired
absolute error tolerance (default = 10−6), trace is a variable that when set to a nonzero value
causes additional computational detail to be displayed, and p1, p2, . . .are parameters that you
want to pass to fun. It should be noted that array operators.*,./ and .^ should be used in the
definition of fun. In addition, pass empty matrices for tolor trace to use the default values.

Example: Use quad to integrate the following function:


1 1
f ( x )= 2
+ 2
( x −q) ( x−r) +0.04
-s
between the limits x = 0 to 1. Note that for q = 0.3, r = 0.9, and s = 6, this is the builtinhumps
function that MATLAB uses to demonstrate some of its numerical capabilities.
The humps function exhibits both flat and steep regions over a relatively short x range.
Hence, it is useful for demonstrating and testing routines like quad and quadl. Note that the
humps function can be integrated analytically between the given limits to yield an exact integral
of 29.85832539549867.

Solution

First, let’s evaluate the integral in the simplest way possible, using the built-in version of humps
along with the default tolerance:

>>format long
>>quad(@humps,0,1)
ans =
29.85832612842764

Thus, the solution is correct to seven significant digits.


82
Next, we can solve the same problem, but using a looser tolerance and passing q, r, and s as
parameters. First, we can develop an M-file for the function:

function y = myhumps(x,q,r,s)
y = 1./((x-q).^2 + 0.01) + 1./((x-r).^2+0.04) - s;
Then, we can integrate it with an error tolerance of 10−4 as in
>>quad(@myhumps,0,1,le-4,[],0.3,0.9,6)
ans =
29.85812133214492
Notice that because we used a larger tolerance, the result is now only accurate to five
significantdigits. However, although it would not be apparent from a single application, fewer
function evaluations were made and, hence, the computation executes faster.

EXERCISE

1. Evaluate the following integral using (a) Romberg integration (εs = 0.5%), (b) MATLAB
quad function:
8
4 3 2
I =∫ −0.055 x + 0.86 x −4.2 x +6.3 x +2 dx
0

2. Evaluate the following integral with (a) Romberg integration (εs = 0.5%), (b) MATLAB
quad and quadl functions:
3
2x
I = ∫ x e dx
0

83
REFERENCES

1. JaanKiusalaas, Numerical Methods in Engineering with MATLA, Cambridge


University Press, 2005
2. Steven C. Chapra,Applied Numerical Methodswith MATLAB® for Engineers and
Scientists, Third Edition, The McGraw-Hill Companies, 2012
3. Brian D. HahnandDaniel T. Valentine, Essential MATLAB® for Engineers and
Scientists, Third edition,Elsevier Ltd.2007
4. Rao V. Dukkipati, MATLAB an introduction with Applications, New Age
International (P) Ltd,2010
5. Stephen J. Chapman, MATLAB Programing for engineers, Book ware company,
second edition, 2008
6. S.R. Otto and J.P. Denier, An Introduction toProgramming andNumerical Methodsin
MATLAB,Springer-Verlag London Limited, 2005

84
PART-II

Laboratory Manual for the course


CAD/CAM (Ieng 4170)

85
Contents

INTRODUCTION
LAB SESSION 90
Getting started with AutoCAD.................................................................................................................91
1.1 Starting Autocad.................................................................................................................................91
1.2The Auto Cad Interface.......................................................................................................................91
1.2.1 Changing the Workspace.............................................................................................................92
1.2.2 Auto CAD Interface Elements.....................................................................................................93
1.3 Opening a Drawing, new drawing, save a drawing and exiting Auto Cad........................................98
1.3.1 Opening a drawing.......................................................................................................................98
1.3.2 New Drawings.............................................................................................................................98
1.3.3 Saving Drawings..........................................................................................................................99
1.3.4 Exiting AutoCAD......................................................................................................................100
1.4 Setting the drawing units limits........................................................................................................100
1.5 Basic Draw Commands....................................................................................................................101
Lab Exercise 1: 105
LAB SESSION 2
Basic Draw Command Continued 107
2.1 Construction Line.............................................................................................................................107
2.2 Polyline Command...........................................................................................................................109
2.3 Drawing Rectangles..........................................................................................................................113
2.4 Drawing Polygons............................................................................................................................116
2.5 Drawing Circles................................................................................................................................117
2.6 Drawing Arcs....................................................................................................................................119
2.7 Splines..............................................................................................................................................120
2.8 Ellipses.............................................................................................................................................121
Lab Exercise 2: 124
LAB SESSION 3
Modify/Editing commands 127
3.1 Editing Commands...........................................................................................................................127

86
3.1.1 Copying and Moving Objects....................................................................................................128
3.1.2 Resizing commands...................................................................................................................137
Lab Exercise 3 147
LAB SESSION 4
Blocks,Hatching, Region and Text 151
4.1 Blocks...............................................................................................................................................151
4.2 Hatching...........................................................................................................................................154
4.3 Regions.............................................................................................................................................156
4.4 Text...................................................................................................................................................157
Lab Exercise 4 161
LAB SESSION 5
Layers Dimensioning and Change Properties 164
5.1 Layers...............................................................................................................................................164
5.2 DIMENSIONING.............................................................................................................................167
5.3 Object Properties Manager...............................................................................................................175
Lab Exercise 5 177
LAB SESSION 6
Orthographic Projection, Sectionning and Isometric Drawing 180
6.1 Orthographic projection....................................................................................................................180
6.2 Sectional views.................................................................................................................................183
6.3 Isometric Drawings..........................................................................................................................186
Lab Exercise 6 191
LAB SESSION 7
3-Dimensional Drawings 200
7.1Introduction:......................................................................................................................................200
7.23D Modeling work space...................................................................................................................200
7.3Solid editing tools..............................................................................................................................200
Poly solid tool.....................................................................................................................................201
The Extrude tool.................................................................................................................................205
Revolve tool........................................................................................................................................207
Box tool ...........................................................................................................................................209

87
Cone tool.............................................................................................................................................210
Cylinder tool.......................................................................................................................................211
Sphere Tool.........................................................................................................................................211
Torus tool............................................................................................................................................211
Wedge tool..........................................................................................................................................211
Sweep tool...........................................................................................................................................215
Loft tool..............................................................................................................................................216
Lab Exercise 7 218
LAB SESSION 8
View Ports and Blocks 223
8.1 View Ports........................................................................................................................................223
8.2 Creating 3D Model Libraries............................................................................................................231
Lab Exercise 8 236
LAB SESSION 9
Solid Editing Tools 238
9.1 3D Array Tool..................................................................................................................................238
9.2 3D Mirror Tool.................................................................................................................................240
9.3 3D Rotate Tool.................................................................................................................................243
9.4 Slice Tool..........................................................................................................................................244
9.5 Section Tool......................................................................................................................................245
9.6 Helix Tool.........................................................................................................................................247
Lab exercise 9 249
LAB SESSION 10
3D Modeling Template, Rendering and Light effect.............................................................................252
10.1 setting up a New 3D Template.......................................................................................................252
10.2 Pallets.............................................................................................................................................255
10.3 Applying Materials.........................................................................................................................258
10.4Render tools and dialogs.................................................................................................................260
The Lights Tools.....................................................................................................................................261
Lab exercise 10 262
LAB SESSION 11

88
Solid Editing Tools 265
Extrude face Tool...................................................................................................................................265
Move Face Tool......................................................................................................................................267
Offset Face Tool.....................................................................................................................................270
Tapper Face Tool....................................................................................................................................270
Copy Face Tool......................................................................................................................................270
Color Face Tool......................................................................................................................................271
Lab Exercise 11 273
LAB SESSION 12
Printing and Plotting 276
Creating Layout......................................................................................................................................276
Layout Setting........................................................................................................................................277
Lab Exercise 12 282
References 283

89
INTRODUCTION

Auto CAD is an acronym for Automated Computer Aided Design/Drafting. Cad allows you to
accomplish Design and Drafting activities using Computer. Cad is a tool that can be used:-

 To make rough idea drawings, also it is more suited to creating accurate finish drawing
and rendering
 To create a two dimensional or three dimensional computer model of the product or
system for further analysis and testing by other computer programs.

In this lab manual an attempt is made to include all the basic AutoCAD tools that are necessary
for the students to know at this stage. It is also tried to put step by step execution of each
examples .there are plenty of exercises at the end of each lab session in order to help this manual
user to practice the concepts explained theoretically in each lab session.

This lab manual is expected to enable the students (all the manual users) to understand the
application of AutoCAD in drafting different Engineering drawings (mechanical Engineering
drawings) both in 2D and 3D. Though most of the examples and exercises used in this manual
focused on mechanical engineering area, the concepts can be extend to drafting different
drawings for different engineering fields and to understand all the basics of Auto CAD.

90
Lab Session 1

GETTING STARTED WITH AUTOCAD


Objectives:-

The objective of this lab session is to enable the students:

 How to start Auto Cad


 To be familiar with the Auto Cad interface
 Opening a Drawing, creating new drawing, save a drawing and exiting/quitting AutoCad
 To be familiar with one of basic draw commands (line command)
o Methods of specifying distance in Auto Cad
o How to measure Angle in Auto Cad

1.1 Starting AutoCAD


There are two common methods to start AutoCad:
i. From the start menu choose programs. Then choose Autodesk next choose AutoCAD
200’X’ and again AutoCAD 200’X’
ii. Double click on AutoCAD 200’X’ short cut icon on the desktop if there is AutoCAD
200’X’ short cut icon on your Desktop
1.2 The Auto Cad Interface
Since Autodesk company start to release its first AutoCAD software in 1982 as version
Autocad1.0, there are different versions of AutoCad released by the company. The company
releases its product each year with some modifications and addition of new features. There
are different versions of Auto Cad such as AutoCad1.0, AutoCad1.1,AutoCad R9, AutoCad
2000 and AutoCad 2015. The interfaces for AutoCad 2000 up to 2008 are almost the same
and AutoCad versions of 2009 up to 2015 (the latest version) have a similar interface. When
we open AutoCad we will see the following interface:

91
Fig 1.1 AutoCAD 2009 Interface

1.2.1 Changing the Workspace


Before we start, make sure we all see the same AutoCAD interface, so if you don’t see the same
interface as we see in this image, follow the following steps:
Step 1:Click the workspace button in your AutoCAD
Step 2:Then select the ‘2D Drafting and Annotation’.

Fig 1.2 2D drafting and annotation work space

92
1.2.2 AutoCAD Interface Elements
The workspace in AutoCAD is divided into 2 distinct areas. The drawing area covers most of the
screen and toolbars are attached above and below the drawing area. They include:
1. AutoCAD drawing area:This is where you will draw your AutoCAD objects.

Fig 1.3 The AutoCAD drawing area

2. Application button:The large, red A at the top, left-hand corner of the screen is the
application button. AutoCAD will show you the AutoCAD menu. This is where we can
access tools related to applications, such as saving files, printing files and to exiting the
program.

Fig1.4 The application Button

93
3. Quick-Access Toolbar: This toolbar sits next to the application button and contains
common commands like "Save" and "Open."

Fig 1.5The Quick-Access Tool Bar

4. Auto CAD Ribbon:Located below the quick-access toolbar, the ribbon is comprised of a
series of tabs (e.g., "Home," "Insert," "Annotate," "View," etc.) that contain groups of
standard commands and tools. This is where you can access AutoCAD tools and settings.

Fig 1.6 The AutoCAD ribbon

94
5. Ribbon Tabs:AutoCAD Ribbon has several tabs. Each tab holds AutoCAD tools based on
your drawing task. For example, we can use drawing tools and modify tools in home tab.
But when we need to add text and dimensions, we need to open the Annotate tab. When
we need to insert blocks, we need to move to insert tab.

Fig 1.7 Ribbon Tabs

6. Ribbon Panel:In each tab have several panels. These panels have similar AutoCAD tools
inside them.

Fig 1.8 The ribbon Panel

95
7. Command Line:We can activate tools and change the tool settings by typing in command
line. Command line is also providing information what you should do next.This is where
the software communicates with you.

Fig 1.9The command line

8. Drafting Settings:This command provides some of the drawing aids to create the drawing
at a faster pace.

Fig 1.10 The drafting setting Command

96
 Grid (F7)
The grid command displays a dot grid with in the current view ports and drawing limits. The grid
command allows you to set your X,Y values and visibility. The grid is used only for reference
and will not show up within a hard copy plot. The grid and snap share the same base point and
rotate .Their spacing is often the same but it can be set to different values. To set up:

 Right click on Grid button and select setting or


 Tools menu, drafting settings, Snap and grid button
 Snap (F9)
Snap spacing restricts cursor movement to specific intervals .When you turn on snap mode ,the
cursor “snaps” to spaced coordinates as if they were cursor managements. You can rotate snap
and grid alignment or set snap grid to isometric mode to simulate 3D view in 2D space. To set
up:
 Right click on Snap button and select Setting or
 Tools menu, drafting settings,Snap and grid button
 Ortho (F8)
Ortho on and off mode, forces the movement of the cursor in horizontal or vertical directions
only. This drafting setting is very useful while using direct distance entry method or for drawing
straight lines.
 Polar (F10)
When the polar tracking mode is active movement of cursor at pre-selected angle will trigger a
polar angle direction track.To set up:

 Right click on Polar button and select setting or


 Tools menu, drafting settings, Polar button
 Object snaps (Osnap) (F3)
Object snap lets you snap to specific geometric points of existing objects in the drawing .For
instance ,you may wish to end a line to the mid of an existing line ,in which case you would snap
to the midpoint of the existing line. You can specify a variety of object snap modes. To set up:

 Right click on Osnap button and select setting or


 Tools menu, drafting setting, Object Snap button, Object Snaps

We will see more interface elements as we move forward.

97
1.3 Opening a Drawing, new drawing, save a drawing and exiting AutoCad

1.3.1 Opening a drawing

In order to open an existing drawing, use the following steps:

1. Choose File, OPEN. or

2. Press CTRL + O. or

3. Click the OPEN icon. or

4. Type OPEN at the command prompt.

Command: OPEN

5 Press ENTER

6. Double Click the desired directory to find the drawing to open.

7. Click the drawing name to open and Click the OK button.

1.3.2New Drawings

In order to open a new drawing, use the following steps:

1. Choose File, New. or

2. Press CTRL + N or

3. Click the New icon. or

4. Type NEW at the Command prompt.

Command: NEW

5. Choose one of the options for creating a new drawing and Click the OK button.

7. Save the drawing as another name.

98
Fig 1.11 The select template dialog box

1.3.3 Saving Drawings

SAVE and SAVE AS:Saves the most recent changes to a drawing. The first time an
unnameddrawing is saved the “Save As” dialog box appears. AutoCAD saves itsdrawings as
files with extensions ending in .DWG.
1. Choose File, Save or Saveas. Or
2. Type SAVE or SAVEAS at the command prompt.
Command: SAVE or SAVEAS
3. Press ENTER
4. Type a new drawing name or keep the existing drawing name.
5. Click the OK button
QUICK SAVE: The QSAVE command is equivalent to clicking Save on the File menu.If the
drawing is named, AutoCAD saves the drawing using the file format specified on the Open and
save tab of the Options dialog box and does not request a file name. If the drawing is unnamed,
AutoCAD displays theSave Drawing As dialog box (see SAVEAS) and saves the drawing with
the file name and format you specify.
1. Press CTRL + S. or

2. Click the Save icon. Or


3. Type QSAVE at the command prompt,
Command: QSAVE
99
1.3.4 Exiting AutoCAD

After we finish working on Auto Cad and saving the files we want, we have to properly exit
from Auto Cad. We can exit Auto Cad by clicking the red close bottom on the right top corner of
the screen. But usually it is not recommended to exit software by this method since it will create
a problem on our computer operating system. Therefore in order to properly exit from Auto Cad
we can follow the following steps:
1. Choose File, Exit. or
2. Type QUIT or EXIT at the command prompt.
Command: QUIT or EXIT
3. Press ENTER
4. Click Yes to save changes or No to discard changes.
1.4 Setting the drawing units limits
To set the units, choose the type of units you want in the Units step of the Advanced Setup
Wizard.Choose a precision in the Precision drop-down list box and then click Next.
To set drawing units without the wizard, choose Format →Units to open the Drawing Units
dialog box, shown in the figure below. The left side of the Drawing Units dialog box enables you
to choose which unit type you want to use. In the Precision box in the Length section, click the
arrow and a list of precision options drops down. Click the one you want. You can also set the
units that AutoCAD uses when inserting the drawing into another drawing using the Design
Center.

Fig 1.12 The drawing unit dialog box


100
Drawing Limits
The drawing limits are the outer edges of the drawing, specified in X, Y units. You need to set
only the width and length of the drawing. Together, these two measurements create an invisible
bounding rectangle for your drawing. Limits enable you to specify the area of your drawing, also
called the limits.
Inorder to set your drawing limits type LIMITS on the command entry. The following prompt
will appear.
Specify lower left corner or [ON/OFF] < 0.0000, 0.0000>:
Almost universally, the lower-left limit is 0,0, which is the default. Therefore, the upper-right
cornerreally defines the drawing size. Then after you give the lower left corner Auto cad asks
you to provide the upper right corner.
Specify upper right corner<9.0000, 12.0000>
Then type the upper-right corner coordinate that you want and press Enter. The size of
yourdrawing should be equal to the size of the outer extents of what you are drawing plus a
margin for a title block and perhaps for annotation and dimensioning. If you want to show more
than one view of an object, as is common in both architectural and mechanical drawings, you
need to take this into account.
To decide on the upper-right corner of your drawing limits (the width and length of your
drawing); you need to consider what the drawing units mean for you.
Generally, the smallest commonly used unit is used, often inches or millimeters. Therefore, if
you are drawing an object that is approximately 300 mm in the X direction by 400 mm in the Y
direction, this translates to a top-right corner of 300,400.

1.5 Basic Draw Commands

Line Command :It is the most basic of all the drawing objects .The initial form point can be
picked using the screen cursor or by entering an X, Y co-ordinate, followed by a two point
location.

We can activate the line command by using the following methods.

Draw toolbar

101
Draw menu Line
Command line entry Line
Alias L
To specify distance in AutoCAD we have two methods:

i. Direct Distance entry


ii. Co-ordinate enter

i. Direct distance entry


This is the simplest way to place series of lines without entering co-ordinate values. You
determine your next point by moving the cursor in the direction you want to go and inter the
required distance from your current position.
Steps to draw a rectangle with size (20*10) using line command with direct distance entry.

1. Start the line command and specify the first point (anywhere on the screen)
2. Move the cursor in the direction you want to draw the line (make it horizontal better to work
in Ortho mode) enter the dimension 20
3. Move the cursor in vertical direction and enter 10
4. Move the cursor in horizontal opposite direction to the previous horizontal line
5. Select Close from the command line C and click enter

ii. Co- ordinate enter

The AutoCAD system provides you with a variety of methods to locate a point on the drawing
screen in order to carry out a particular action, for instance, to locate the end point of a line or to
move one object to new location.

102
There are three methods of Co-Ordinate entry:

a. Absolute Co-Ordinate Entry

Imagine your screen is like a piece of graph paper and all your coordinates are taken from one
datum base point, the lower left corner ,X0,Y0. A co-ordinate position specified from the
keyboard will be taken relative to this X0, Y0 position (0, 0).

For instance point A shown in the figure below is 20 units in the X and 20 units in Y axis from datum 0,
0, whilst point B shown is 20 units far from point A in Y direction.

Steps to draw the given figure using Absolute co-ordinate system:

Activate the line command using draw toolbar, draw menu or by typing “L” on the command
line.
Command: _line Specify first point: 20, 20 enter(A)
Specify next point or [Undo]: 20, 40 enter (B)
Specify next point or [Undo]: 40, 40enter(C)
Specify next point or [Close/Undo]: 40, 50enter (D)
Specify next point or [Close/Undo]: 55, 50enter (E)
Specify next point or [Close/Undo]: 55, 40enter (F)
Specify next point or [Close/Undo]: 75, 40 enter (G)
Specify next point or [Close/Undo]: 75, 20enter (H)
Specify next point or [Close/Undo]: c enter(A)

b. Relative Co-Ordinates Entry

Allows you to specify the X,Y co-ordinate of the end points of your next line relative to your
current position .In order to inform AutoCAD that you wish to use a relative co-ordinate entry ,
you must type the @ symbol prior to your next co-ordinate position.The format is :@X,Y

For instance point A shown is 20 units in the X and 20 units in Y axis from datum 0,0, whilst
point B shown is 20 units far from point A in Y direction.
Procedures to draw the given figure using relative co-ordinate system

Activate the line command using draw toolbar, draw menu or by typing “L” on the command line
Command: _line Specify first point: click anywhere in the drawing area (A)

103
Specify next point or [Undo]: @0, 20 enter (B)
Specify next point or [Undo]: @20, 0enter (C)
Specify next point or [Close/Undo]: @0, 10 enter (D)
Specify next point or [Close/Undo]: @15, 0 enter (E)
Specify next point or [Close/Undo]: @0, -10 enter (F)
Specify next point or [Close/Undo]: @20, 0 enter (G)
Specify next point or [Close/Undo]: @0, -20enter (H)
Specify next point or [Close/Undo]:@ -55,0orc enter (A)
c. Polar Co-Ordinate Entry

You can use polar co-ordinate to specify your next line point as a distance and angular direction
from your current position. Again, in order to inform AutoCAD that you wish to use a relative
co-ordinate entry, you must type the @ symbol prior to your next Co-Ordinate position.
The format is: @Distance < Angle .In AutoCad degrees are measured counter clock wise
starting at 3 o’clock.

Procedures to draw the given figure using Polar co-ordinate system

Activate the line command using draw toolbar, draw menu or by typing “L” on the command line

Command: _line Specify first point: click anywhere in the drawing area (A)
Specify next point or [Undo]: @20<90 enter (B)
Specify next point or [Undo]: @20<0enter (C)
Specify next point or [Close/Undo]: @10<90enter (D)
Specify next point or [Close/Undo]: @15<0 enter (E)
Specify next point or [Close/Undo]: @10<270 enter (F)
Specify next point or [Close/Undo]: @20<0 enter (G)
Specify next point or [Close/Undo]: @20<270enter (H)
Specify next point or [Close/Undo]: @55<180orc enter (A)

104
LAB EXERCISE 1:
Try to draw the following figure using the line command and the concepts that youhave relent so
far. You have to open new drawing file for each figure and save it as Ex-1, Ex-2, Ex-3 and the
like.

105
Lab Session 2

BASIC DRAW COMMANDS CONTINUED


Objective:-

 Familiarize the students with other basic Draw Commands (How to draw Construction line,
Poly line, Rectangle, Arc, Circle, Revision Cloud, Spline, Ellipse and Elliptical Arc)

2.1 Construction Line


Sometimes you want to create a line that is used solely for the purpose of reference.
For example, you might want to do the following:

106
o Draw two lines from the midpoints of two perpendicular lines so that you can use their
intersection as the center for a circle.
o Draw a line from one object to another to visually indicate the relationship between the
two objects.
o Show the relationship between equivalent parts of a model shown in front and right-side
views.
o Draw a line through the center of an object shown in cross-section so that you can show
dimensions from the center line to the edge of an object.
You could use regular lines for these purposes. However, construction lines (also known as
xlines) are unique in that they extend infinitely in both directions. This makes them especially
useful for seeing the relationships among various objects in your drawing.
Of course, construction lines are not actually infinite. However, they extend to the edge of the
drawing area on your screen, and if you zoom out to see more of your drawing, they expand so
that they always extend to the edge of the screen. AutoCAD’s object snap tracking sometimes
eliminates the need for construction lines; nevertheless, sometimes you can work more easily
having a line visible for several commands and then erasing it.
If you zoom to show the extents of your drawing, AutoCAD ignores the xlines and shows you
just the extents of the regular objects in your drawing.

The XLINE command offers several ways to create construction lines. Start the command by
choosing Construction Line from the Draw toolbar. You see the following prompt: Specify a
point or[Hor/Ver/Ang/Bisect/Offset]:
Below are lists the possible options. AutoCAD continues to prompt you for more points so that
you can continue to draw construction lines—much like the LINE command. Press Enter to end
the command.
XLINE Command Options

OptionDescription

SpecifyA point
This option enables you to define the xline with two points. At the first
prompt, specify a point. At the Specify through point: prompt, specify
another point. The first point becomes the base point for subsequent

107
construction lines that you can draw by specifying other through points.
Hor y one point. It is useful for drawing a series of horizontal construction
lines.

Ver
To draw a construction line parallel to the Y axis, type v then enter to
specify the Vertical option. AutoCAD responds with the Specify through
Ang
point: prompt. Specify one point.

Type a then press enter (for Angle). AutoCAD responds with the Enter
angle of xline (0) or [Reference]: prompt. If you enter an angle, AutoCAD
asks for a through point.
Or you can type r then press enter and select a line as a reference, and then
provide an angle and a through point. AutoCAD then calculates the angle
of the construction line from the angle of the reference line. Useful for
drawing a series of construction lines at a specified angle.

To draw a
construction
line parallel to
the X axis, Bisect
type h then
press enter to
specify the
Horizontal
option. Offset
AutoCAD
responds with
the Specify
through point:
prompt.Specif

108
type b then press enter.AutoCAD responds with the Specify angle vertex
point: prompt. Choose any point that you want the construction line to
pass through. Then,at the Specify angle start point: prompt, choose a point
that defines the base of the angle. At the Specify angle end point: prompt,
choose a point that defines the end of the angle.

To draw a construction line parallel to a line, type o then press enter. You
can specify the offset distance by typing in a number or use the Through
To draw a option to pick a point through which the construction line should pass.
construction Either way, the next step is to select a line.
line that If you specified an offset distance, AutoCAD displays the Specify side to
bisects offset: prompt. Respond by picking a point on the side of the selected line
(divides in on which you want the construction line to appear.
half) an angle,

2.2 Polyline Command

Polylines are single objects that combine line segments and arcs. In certain situations, it is useful
to be able to edit an entire set of lines and arcs as one object. Polylines can have a width, which
can vary from the start point to the endpoint. Polylines ensure that all the vertices of a closed
area actually meet, which is very helpful if you want to hatch the area. They are also very useful
for 3D drawing. In short, polylines are a neat, clean way to draw. The RECTANG and
POLYGON commands create polylines.Some examples of polylines:

Using the PLINE command

To draw a polyline,use one of the following methods:

109
Draw toolbar: 
Draw menu: Polyline
Command entry: pl
One of the above methods starts the PLINE command.
AutoCAD responds with the Specify start point: prompt. Specify the start point.
Then AutoCAD responds with the Specify next point or
[Arc/Close/Halfwidth/Length/Undo/Width]: prompt. It offers the following options:
o Arc:Enables you to draw arcs. This option opens up a set of arc suboptions, which are
explained next, after this list.
o Close:Closes a polyline by drawing a line from the endpoint of the last line segment to the
start point of the polyline. This option appears only after you have picked a second point.
o Halfwidth:Defines half the width of the polyline—the distance from the center of the
polyline to its edge. AutoCAD asks you for the starting halfwidth and the ending
halfwidth, enabling you to create polylines that are tapered.
o Length:Specifies the length of the next line segment. AutoCAD draws the line segment in
the same direction as the last line segment or tangent to the last arc.
o Undo:Undoes the last line segment.
o Width:Defines the width of the polyline. AutoCAD asks you for the starting width and
the ending width.
o Specify next point:Enables you to create a line segment. This is the default option.

Like the LINE command, PLINE continues to prompt you for more points, repeating the entire
prompt each time. When you are done, press Enter to end the command.

If you choose Arc, AutoCAD responds with the Specify endpoint of arc
or[Angle/CEnter/CLose/Direction/Halfwidth/Line/Radius/Second pt/ Undo/Width]: prompt.
While this may seem overwhelming, most of the options are similar to the ARC command
options. The arc options are as follows:
o Angle: Specifies the included angle.
o Center: Specifies the arc’s center.

110
o Close: Closes the polyline by drawing a line from the endpoint of the last arc to the start
point of the polyline.
o Direction: Specifies the direction of the arc from the start point.
o Halfwidth: Defines half the width of the polyline—the distance from the center of the
polyline to its edge. AutoCAD asks you for the starting halfwidth and the ending
halfwidth.
o Line: Returns you to the main polyline prompt so you can draw line segments.
o Radius: Specifies the arc’s radius.
o Second pt:Specifies the second point of the arc.
o Undo:Undoes the last arc.
o Width: Defines the width of the polyline. AutoCAD asks you for the starting width and
the ending width.
o Specify endpoint of arc:Specifies the endpoint of the arc. This is the default.

AutoCAD creates an arc tangent to the previous arc (continuing in the same direction).PLINE
continues to display the arc submenu until you use the Line suboption or end the command
bypressing Enter.

Example :Use a polyline command to draw the following profile.

Left-clickthe Polyline tool icon or type Pl on the command entry. The command line shows:
Command: _pline Specify start point: 50,220
Current line width is 0

111
[Prompts]: w (Width)
Specify starting width _ 0 _ : 0.5
Specify ending width _ 0.5 _ : right-click
Specify next point or [prompts]: 120,220
Specify next point or [prompts]: a (Arc)
Specify endpoint of arc or [prompts]: s (second pt)
Specify second point on arc: 150,200
Specify end point of arc: 180,220
Specify end point of arc or [prompts]: l (Line)
Specify next point or [prompts]: 250,220
Specify next point or [prompts]: 250,190
Specify next point or [prompts]: a (Arc)
Specify endpoint of arc or [prompts]: s (second pt)
Specify second point on arc: 240,170
Specify end point of arc: 250,150
Specify end point of arc or [prompts]: l (Line)
Specify next point or [prompts]: 250,150
Specify next point or [prompts]: 250,120
Command:
And so on until the outline in the above Figure is completed.

Editing polylines with the PEDIT command

Because polylines can be quite complex, AutoCAD has a special command to edit them, PEDIT.
To edit a polyline, choose Modify→ Object→ Polyline. Or you can type PEDIT on the
command entry. AutoCAD responds with the Select polyline or[Multiple]: prompt. Select a
polyline and AutoCAD responds with the Enter an option[Close/Join/Width/Edit
vertex/Fit/Spline/Decurve/Ltype gen/Undo]: prompt. The options are as follows:
o Close:Closes an open polyline. If necessary, it adds a segment to connect the
endpoint to the start point. If the polyline is already closed, this prompt becomes
Open. Open creates a break between the first and last segments of the polyline.
o Join:Joins touching lines, arcs, or other polylines to the polyline.

112
o Width:Enables you to specify one width for the entire polyline.
o Edit Vertex:Provides a set of suboptions for editing vertices. These are explained
after this list.
o Fit:Turns the polyline into a curve that passes through the vertices.
o Spline:Creates a curve using the vertices as control points. The curve does not
usually actually pass through the vertices. This is not the mathematically exact spline
that the SPLINE command produces.
o Decurve:Returns a Fit or Spline curve to its original vertices.
o Ltype gen:Turns on continuous linetype generation for the selected polyline.
o Undo:Undoes the most recent edit.
You can change any line or arc into a polyline. Start PEDIT and choose a line or arc. AutoCAD
responds: Object selected is not a polyline. Do you want to turn it into one? <Y>. Press Enter to
accept the default. AutoCAD turns the object into a polyline. You can use this technique to turn a
series of connected lines and arcs into a polyline. First, turn one of the objects into a polyline as I
just explained. Then use the Join option and select the other objects individually or by a selection
window. When you finish object selection, AutoCAD tells you how many segments were added
to the polyline. In order to create a polyline in this way, the individual lines and arcs must
connect exactly end to end.

2.3 Drawing Rectangles


You can start arectangle command by using one of the following.

Draw toolbar: 

Draw menu: Rectangle

Command entry: recor rectangle

AutoCAD responds with the Specify first corner point or


[Chamfer/Elevation/Fillet/Thickness/Width]: prompt.

The options are as follows:

113
o First corner point:Specifies a corner point of the rectangle.If you Specify the first corner of a

rectangle,again you willhave the following prompt:Specify other corner point or


[Area/Dimensions/Rotation]:

 Other Corner Point:Creates a rectangle using the specified points as


diagonally opposite corners.

 Area:Creates a rectangle using the area and either a length or a width. If the
Chamfer or Fillet option is active, the area includes the effect of the chamfers
or fillets on the corners of the rectangle.

Enter area of rectangle in current units <100>: Enter a positive value

Calculate rectangle dimensions based on [Length/Width] <Length>: EnterL


or w

Enter rectangle length <10>: Enter a non-zero value

Or

Enter rectangle width <10>: Enter a non-zero value

Specify other corner point or [Area/Dimensions/Rotation]: Move the cursor to


display one of four possible locations for the rectangle and click the one that
you want

 Dimensions:Creates a rectangle using length and width values.

Specify length for rectangles <0.0000>Enter a non-zero value

Specify width for rectangles <0.0000>Enter a non-zero value

Specify other corner point or [Area/Dimensions/Rotation]: Move the cursor to


display one of four possible locations for the rectangle and click the one that
you want

114
Once you have specified the length and width, four possible rectangles are
possible, as shown in the figure. As you move your mouse cursor around the
first corner you specified, AutoCAD displays these rectangles. Click when
you see the one you want.

Once you set the dimensions, they remain as defaults for future rectangles that
you draw. As a result, you can use the Dimensions option to quickly draw a
number of identical rectangles.

When you specify the first corner, a length, and a width, chooses which of
four possible rectangles you want.

 Rotation:Creates a rectangle at a specified rotation angle.

Specify rotation angle or [Points] <0> Specify an angle by entering a value,


specifying a point, or entering p and specifying two points

Specify other corner point or [Area/Dimensions/Rotation]: Move the cursor to


display one of four possible locations for the rectangle and click the one that
you want

o Chamfer:Sets the chamfer distances for the rectangle.

Specify first chamfer distance for rectangles <current>: Specify a distance or press
ENTER

Specify second chamfer distance for rectangles <current>: Specify a distance or press
ENTER

The values become the current chamfer distances for subsequent RECTANG commands.

o Elevation:Specifies the elevation of the rectangle.

115
Specify the elevation for rectangles <current>: Specify a distance or press ENTER

The value becomes the current elevation for subsequent RECTANG commands.

o Fillet:Specifies the fillet radius of the rectangle.

Specify fillet radius for rectangles <current>: Specify a distance or press ENTER

The value becomes the current fillet radius for subsequent RECTANG commands.

o Thickness:Specifies the thickness of the rectangle.

Specify thickness for rectangles <current>: Specify a distance or press ENTER

The value becomes the current thickness for subsequent RECTANG commands.

o Width:Specifies the polyline width of the rectangle to be drawn.

Specify line width for rectangles <current>: Specify a distance or press ENTER

The value becomes the current polyline width for subsequent RECTANG commands.

2.4 Drawing Polygons


AutoCAD’s POLYGON command enables you to draw multisided closed figures with equal side
lengths. AutoCAD can draw polygons with anything from 3 to 1,024 sides. To draw a polygon,
choose one of the following.

Draw toolbar: 
Draw menu: Polygon
Command entry: pol
Then the following prompt will be displayed.
Enter number of sides <current>:Enter a value between 3 and 1024 or press ENTER
Specify center of polygon or [Edge]:

o Center, Inscribed/Circumscribed: Specify center of polygon or [Edge]: Use one of the point
fixing methods

116
Define the center point of an imaginary circle, which passes through the edges or endpoints
of the polygon.
Enter an option [Inscribed in circle/Circumscribed about circle] <1>: I
Specify radius of circle: Specify radius of the imaginary circle
Using inscribed option AutoCAD draws the polygon, such that the vertices of the polygon lie
on the circumference of an imaginary circle constructed by AutoCAD with radius and center
point specified.
Enter an option [Inscribed in circle/Circumscribed about circle] <1>: C
Specify radius of circle: Specify radius of the imaginary circle
Using circumscribed option AutoCAD constructs the polygon such that the side of base is
tangential to all imaginary circle constructed by AutoCAD with radius and center point
specified.
o Edge: Using the edge method to create the polygon, you define the side of base by fixing two
points and
AutoCAD constructs the rest of polygon; here the user has control over the exact size and
orientation of the polygon.
Command: _pol
Command: _polygon Enter number of sides <6>: Enter a positive integer Specify center of
polygon or [Edge]: E
Specify first endpoint of edge: Use one of the pointfixing methods Specify second endpoint
of edge:
Use one of the point fixing methods
If you type a number for the radius, the bottom edge of the polygon is horizontal. However, if
you pick a point for the radius with your mouse, you can specify the orientation of the
polygon. Rotate the mouse cursor around the center, and you see the polygon rotate. Pick
when you like what you see.
If you type a number for the radius, the bottom edge of the polygon is horizontal. However, if
you pick a point for the radius with your mouse, you can specify the orientation of the
polygon. Rotate the mouse cursor around the center, and you see the polygon rotate. Pick
when you like what you see.

117
2.5 Drawing Circles

Draw toolbar: 

Draw menu: Circle

Command entry: C or Circle

You can create circles in several ways. The default method is to specify a center and radius.
AutoCAD also provides 3 more methods to draw circles which are discussed below.
Command: _circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: Use one of the point fixing
methods or enter an option

o Center, Radius/Center, Diameter: This allows drawing a circle based on the center point
and radius or diameter. The radius or diameter can be specified by fixing a point or by
entering a value. The distance between the specified point and the center, is the radius or
diameter, as the case may be.

Specify radius of circle or [Diameter]: Enter radius value or enter D for Diameter option

o 3Points: A circle can be fixed by specifying any 3 circumferential points using this
option.

118
Command: _circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _3p
Specify first point on circle: Use one of the point fixing methods
Specify second point on circle: Use one of the point fixing methods
Specify third point on circle: Use one of the point fixing methods

o Points:Specify 2 diametrically opposite points to draw a circle using this method.


Command: _circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _2p
Specify first end point of circle's diameter: Use one of the point fixing methods
Specify second end point of circle's diameter: Use one of the point fixing methods

o Tangent, Tangent, Radius: Select this to draw a circle of given radius. The circle will be
fixed tangential to both the selected objects.
Command: _circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr
Specify point on object for first tangent of circle: Select an object
Specify point on object for second tangent of circle: Select an object
Specify radius of circle <1.0000>: Enter a value.

2.6 Drawing Arcs

119
Draw toolbar: 

Draw menu: Arc

Command entry: A or Arc

ARC command allows you to create an arc segment. Arcs created by AutoCAD are circular arcs
which form a part of a circle. There are different methods of creating an arc, as illustrated below.
The default method is to specify the circumference with three points.Except for 3 point arcs, arcs
are drawn in a Counter Clockwise direction.
3 point arc Start, center, chord length start, center, end

Start, end, radius Start, center, included angle Start, end, direction

2.7 Splines

Draw toolbar: 

Draw menu: Spline

120
Command entry: Spline

A spline is a smooth curve that is defined by a series of points. The SPLINE command provides
a more precise representation of a spline than the Spline option of the PLINE command. By
default, the curve passes through each point you define.

To create a spline, choose Spline from the Draw menu. AutoCAD responds with the Specify first
point or [Object]: prompt. Use the Object option to convert a polyline that you have created with
PEDIT’s Spline option into a true spline. (It won’t look any different, but its internal definition
changes.) Otherwise, specify the first point for the spline.
If you choose a point, AutoCAD displays the Specify next point: prompt so you can pick a
second point. Once you do so, AutoCAD responds with the Specify next point or [Close/Fit
tolerance] <start tangent>: prompt. Use these options as follows:
o Close:Closes the spline by connecting the last point with the first in a continuous
(tangent) curve. AutoCAD asks for a tangent direction. You can specify a direction by
picking a point (watch the spline image change as you move the cursor) or pressing Enter
to accept the default tangent direction.
o Fit Tolerance:Specifies how closely the spline comes to the points you pick. The default,
0, creates a spline that passes through each point. If you want the curve to have latitude of
0.5 units from the points, set the tolerance to 0.5.
o Specify next point:The default is to continue to enter points. Press Enter to end point
selection.
o Start tangent:When you press Enter to complete point selection, AutoCAD prompts you
for start and ending tangent directions. You can press Enter at both prompts to accept the
default tangents based on the curve’s current shape. You can see the effect of other
tangent points by moving the cursor and watching the image change.
2.8 Ellipses

121
Draw toolbar: 
Draw menu: Ellipse
Command entry: El

To draw an ellipse, choose Ellipse from the Draw toolbar or use one of the above methods. In
addition to the information AutoCAD explicitly requests in the prompts, you need to know the
angle of the first axis you define. Not all ellipses are horizontal or vertical. You control this
when you stipulate the second point of the first axis.
The second axis is automatically perpendicular to the first axis. The Ellipse Arc button is new on
the
Draw toolbar. It simply executes the ELLIPSE command with the Arc option.
To draw an elliptical arc, choose Ellipse Arc from the Draw toolbar. When you draw an elliptical
arc,
AutoCAD introduces a helpful but sometimes confusing feature: While you are defining the arc
angles, AutoCAD redefines 0 degrees along the major axis. This helps you define the included
angle in an orientation that relates to the ellipse, rather than the usual orientation where 0 degrees
is to the right.
Creates an ellipse or an elliptical arc
AutoCAD helps drawing a perfect ellipse or elliptical curve using this command. There are two
different ways in defining an ellipse: (a) you define the full length of one axis and half-length of
the other axis, (b) define the center point of the ellipse (the point where to axes intersect with
each other) and half-length of other two axes.
Command: _ellipse
Specify axis endpoint of ellipse or [Arc/Center]: Use one of the point fixing methods or enter an
option
Axis Endpoints
Draw > Ellipse > Axis, End
This is the first step towards defining the first axis. The two end points of the axis are specified.
When the first point is specified in the above option, it prompts for the second point.
Specify other endpoint of axis: Use one of the point fixing methods

122
Here, there is not distinction of major or minor axes of an ellipse. Depending on the distance you
specify one could be the major axis of an ellipse and the other could be the minor axis.
AutoCAD doesn't make any difference between these two.
After the first axis of the ellipse is defined, AutoCAD gives you two options to define the length
of the other axis. The first one is to define half-length| of the other axis
Specify distance to other axis -or- flotation]: Specify a distance

This defines the second axis as the distance from the center of the ellipse (midpoint of the first
axis that you defined earlier) in a direction perpendicular to the first axis.
The Rotation option defines the major to minor axis ratio of the ellipse by rotating an imaginary
circle about the first axis you defined by the given rotation angle. The higher the value, the
greater is the ratio of minor to major axis. Entering 0 defines a circle. Rotation around major
axis: Specify a point or enter a value (0-89.4)
Specify distance to other axis or [Rotation]: R Specify rotation around major axis: Specify an
angle

Draw > Ellipse > Center


You can start from the center point of an ellipse. After the definition of the center point,
AutoCAD proceeds in a similar way we learned above.
Command: ellipse
Specify axis endpoint of ellipse or [Arc/Center]: C
Specify center of ellipse: Specify a distance
Specify endpoint of axis: Specify a distance
Specify distance to other axis or [Rotation]: Specify a distance or angle

Draw > Ellipse > Arc


It creates an elliptical arc. AutoCAD constructs an imaginary ellipse using the methods we
discussed above. Then the parameters about the arc are prompted for user input. The following
sequence shows how a simple elliptical arc could be constructed.
123
Elliptical arc by start and end angles
Command: _ ellipse
Specify axis endpoint of ellipse or [Arc/Center]: a
Specify axis endpoint of elliptical arc or Center]: Use one of the point fixing methods
Specify other endpoint of axis: Use one of point fixing methods
Specify distance to other axis or [Rotation]: Specify a distance
Specify start angle or [Parameter]: Specify an angle or enter an option
Specify end angle or [Parameter/Included angle]: Specify an angle or enter an option

To specify start angle, you could enter a numeric value, in which case, AutoCAD measures the
angle from the angle of the first axis you defined. Parameter requires the same input as start
angle.
Specify start angle or [Parameter]: p
Specify start parameter or [Angle]: Enter a value or specify an angle
Specify end parameter or [Angle/Included angle]: Enter a value or specify an angle
Specify end parameter or [Angle/Included angle]: Enter a value or specify an angle
LAB EXERCISE 2:

#1.Using polyline commands draw the following. (Set the unit to inch)
# 2. Draw the following figure using line and Arc commands.

124
#3.The following figure shows a rectangle in the formof a square with hexagons along eachedge.
Using the Dimensions prompt of theRectangle tool construct the square. Then,using the Edge
prompt of the Polygon tool,add the four hexagons. Use the Object Snapendpoint to ensure the
polygons are in theirexact positions. (Units mm)

125
# 4.With the Line and Arc tools, construct # 5.With the Ellipse tool, construct the
theoutline shown in the following figures. drawingshown below.(each ellipse minor
axis=30)

# 6.With the Line, Circle and Ellipse # 7.Using the Circle tool, construct the
toolsconstruct the drawing shown bellow. following circles.

126
# 8.Construct the drawing shown in below using the Line and Arc tools. Then change allwidths
of lines and arcs to a width of 2 withPolyline Edit.

# 9.Using the Line tool construct the two lines at thelength and angle as given in the figure
below. Then, withthe Ttrprompt of the Circle tool, add the circle asshown.

10.Draw the following figure using line and tangent to the circle and change the units to
circle commands. (Turn on tangent from inches).
Osnap settings to draw the lines that are
# 11. Draw the following figure using
rectangle and circle commands.

127
#12. Using line, arc rectangle and circle commands draw the following figure. (Unit in mm)

Lab Session 3

MODIFY/EDITING COMMANDS
Objective

 Modifying the object that we draw using draw command and to be familiar with
editing/modifying commands.

Editing Commands

Editing commands or modify commands are used to edit objects that are made using draw
commands. We can erase, copy, mirror, offset etc once we draw an object. The Editing/Modify

128
tools are among those most frequently used. The tools arefound in the Home/Modify panel. A
click on the arrow in the Home/
Modify panel brings down a further set of tool icons. Theycan also be selected from the Modify
toolbar or from theModify drop-down menu.We will see each modify command step by step.

Erase objects
The first editing tool in the modify toolbar is ERASE. This allows you to remove the selected
objects from the AutoCAD drawing.
Command: _erase,
Select objects: Pick an object to delete
Select Objects: Pick an object or press Esc to terminate the command.

Copying and Moving Objects


Three commands enable you to copy objects in very specific ways. MIRROR creates a mirror
image.
ARRAY creates a rectangular or circular pattern of an object. OFFSET creates parallel objects.
Although these commands make copies of objects, they produce a result that would be difficult
or impossible to produce simply by using the COPY command. The ALIGN command moves
objects by aligning them with other objects in the drawing.

Copy command
The copy command enables you to copy objects with a specified distance in a specified direction.
You can create multiple copies of a single object using this command.

Example:Construct the Figure bellow using Polyline. Do not include the dimensions.

129
Now Call the Copy tool (left-click on its tool icon in the Home/Modify panel, pick Copy from
the Modify toolbar, or enter cpor copy at the command line).
The command line shows:
Command: _copy
Select objects: pick the cross 1 found
Select objects: right-click
Current settings: Copy mode=Multiple
Specify base point or [Displacement/mode/Multiple]<Displacement>: pick
Specify second point or [use first point as Displacement]: pick

The result is given in Figure below.

MIRROR command
Many drawings have symmetrical elements. Often, especially in mechanical drawing, you can
create one-half or one-quarter of a model and complete it simply by mirroring what you have
drawn.
To mirror, select an object or objects and then choose Mirror from the Modify toolbar.
Alternatively, choose Mirror from the Modify toolbar and then select an object or objects.
AutoCAD prompts for the first and second points of the mirror line. This is an imaginary line
across which AutoCAD creates the mirrored object. The length of the line is irrelevant—only its
start point and direction are important.
Most mirror lines are orthogonal. Therefore, once you specify the first mirror point, turn on
ORTHO and move the mouse in the direction of the second point. You can then quickly pick the
second point.

130
Polar tracking can also easily guide you to specify an orthogonal mirror line. AutoCAD then asks
if you want to delete the source objects. The source objects refer to the objects you have selected
to mirror. If you want to keep them, type n or press Enter. You would keep the source objects
when you are building a symmetrical model and want the mirror image to be added to the
original object(s). Type y when you want to edit an object, change its orientation, so that only the
mirror image is retained in the drawing.

Example: Construct the outline shown in the figure bellow using the Line and Arc tools.

Then call the Mirror tool (left-click on its tool icon in the Home/Modifypanel, pickthe Mirror
tool icon from the Modify toolbar,pick Mirror from the Modify drop-down menu, or enter mi or
mirrorat the command line. The command line shows:

Command: _mirror

Select objects: pick first corner

Specify oppositecorner: pick 7 found

Select objects: right-click

Specify first point of mirror line: end of pick

Specify second point of mirror line: end of pick

Erase source objects [Yes/No] <N>:right-click

131
Command:

The result is shown in Figure bellow

Moving objects
Use the MOVE command to move objects in your drawing. Moving an object is more complex
than erasing one because you need to tell AutoCAD the distance and direction you want the
object to move.
To move an object, select it and choose Move on the Modify toolbar. Alternatively, choose
Move and then select the object. When you choose the MOVE command and once you have
selected an object, AutoCAD responds with the following prompt:
Specify base point or displacement:
You now have two ways of telling AutoCAD how to move the object or objects:

o Displacement method:At the Specify base point or displacement: prompt, state the entire
displacement as an X,Y coordinate such as 2,3 or a polar coordinate such as 2<60. Because
the word displacement already implies the relative distance from the object, you do not use
@.(AutoCAD actually uses 0,0as the relative point.) AutoCAD responds with the Specify
second point of displacement or <use first point as displacement>: prompt. Because you have

132
already given AutoCAD all the information it needs, press Enter. AutoCAD uses the first
point you indicated as the displacement (the default) and moves the object.
o Base point/second point method:At the Specify base point or displacement: prompt, pick a
base point. This can be anywhere in your drawing. At the Specify second point of
displacement or <use first point as displacement>: prompt, specify the distance and angle of
movement either by picking a second point on the screen or by typing a relative coordinate,
using @.

The displacement method requires less input and is simpler when you know the exact
displacement so that you can type it in. The only disadvantage is that once you type in the
displacement, AutoCAD sometimes displays a confusing drag line and copy of your object or
objects. Ignore this display, press Enter, and your object or objects move as you specified. The
base point/second point method works best when you want to move an object relative to another
object on the screen.

ARRAY command

The ARRAY command creates a rectangular or circular (polar) pattern by copying the object(s)
you select as many times as you specify. The ARRAY command is a powerful drawing tool. It
can quickly create large numbers of objects—saving a huge amount of time and effort.
o Rectangular arrays: A rectangular array creates a grid of rows and columns of one or more
objects. The figure below shows an example of a rectangular array.

1) Select the object or objects and choose Array from the Modify toolbar. Alternatively,
choose Array from the Modify toolbar and select the object or objects. AutoCAD opens the
Array dialog box, shown.
2) Click Rectangular Array at the upper-left corner of the dialog box (if it is not already
selected).

133
3) If you have already selected one or more objects, the dialog box indicates the number of
selected objects. If you have not selected any object, click Select Objects to return to your
drawing and select objects. Press Enter to end object selection and return to the dialog box.
4) Type the number of rows and columns you want in the Rows and Columns text boxes. Press
Tab after the last number you type to see the new result in the preview panel.
5) Type the row offset (the distance between the rows). The preview panel doesn’t display any
change when you change the row or column offsets.
6) Type the column offset (the distance between the columns).
7) If you want to specify the offsets by picking points on your screen, click one of the following
buttons:

Pick Both Offsets Pick Row Offset Pick Column Offset


8) If you want to change the angle of the array, type an angle. The preview panel displays the
results of this value. To specify the angle by picking, click the Pick Angle of Array button.
9) To preview the array, click Preview. Then choose Accept to create the array, Modify to return
to the Array dialog box, or Cancel to end the command.
10) To create the array, click OK.

If you need to create a number of copies of an object along a straight path, use a one-column or
one row array instead of the COPY command. It’s faster and easier.

The array dialog box

o Polar (circular) arrays:A polar array creates copies of one or more objects arrayed in a circle
around a center point. An example of a polar array is shown below.

134
To create a polar array, follow these steps:

1. Select the object or objects and choose Array from the Modify toolbar. Alternatively,
choose
Array from the Modify toolbar and select the object or objects. AutoCAD opens the Array dialog
box.
2. Click Rectangular Array at the upper-left corner of the dialog box (if it is not already
selected).
3. If you have already selected one or more objects, the dialog box indicates the number of
selected objects. If you have not selected any object, click Select Objects to return to your
drawing and select objects. Press Enter to end object selection and return to the dialog box.

4. Specify the center point by typing X and Y coordinates or click the Pick Center Point
button. If you selected an object first, check that the center point displayed is what you want.
5. Select the two items you want to specify from the Method drop-down box. You can choose
any two from the three choices:
• Total Number of Items: Sets the total number of items in the resulting array, including
he one you are arraying.
• Angle to Fill: Sets the number of degrees the polar array covers. For example, to array
around half a circle, specify 180°.
• Angle Between Items: Specifies the number of degrees between each item in the polar
array.
6. Complete the values of the two items you specified. You can click the buttons to pick the
angle to fill or the angle between items on the screen.
7. Check the Rotate Items as Copied checkbox to rotate the objects you are arraying. Uncheck
the box to leave them un-rotated.
8. Click Preview to preview the array. Then choose Accept to create the array, Modify to return
to the dialog box, or Cancel to cancel the command.

135
9. Click OK to create the array.

Offsetting objects

The OFFSET command creates lines or curves parallel to one existing object. The beauty of this
command is apparent when you start to create complex objects, such as polylines. You may
remember that polygons and rectangles are polylines, meaning that they are treated as one object.
Using OFFSET, you can create concentric polygons, for example, in one step. The figure below
shows two concentric polygons. The outside polygon was created with the POLYGON
command, and the inside polygon was created using OFFSET.

To offset an object, choose Offset from the Modify toolbar. You cannot select objects before
choosing the command.
AutoCAD responds with the Specify offset distance or [Through] <1.0000>: prompt. AutoCAD
offers two slightly different ways to specify the offset:
If you type an offset distance, AutoCAD responds with the Select object to offset or <exit>:
prompt.
You can select one object. Then AutoCAD displays the Specify point on side to offset: prompt.
Pick a point to indicate on which side of the object AutoCAD should create the offset copy.
AutoCAD creates the offset and continues to show the Select object to offset or <exit>: prompt
so you can offset other objects using the same offset distance. Press Enter to exit the command.
If you want to indicate a through point, which is a point that the offset passes through, such as an
object snap on another object, type t : or right-click and choose Through from the shortcut menu.
Then AutoCAD displays the Select object to offset or <exit>: prompt. Pick one object. At the
Specify through point: prompt, pick a point through which you want the offset to go. AutoCAD
creates the offset.

136
Rotating objects
AutoCAD enables you to easily rotate an object or objects around a base point that you specify.
The base point is usually an object snap point on the object. To indicate the rotation, specify an
angle of rotation. Zero degrees is generally to the right, and degrees increase counterclockwise,
although you can change this convention. By specifying a negative angle, you can turn objects
clockwise.
To rotate an object, choose Rotate from the Modify toolbar and select an object. Alternatively,
select an object and then choose Rotate from the Modify toolbar. At the Specify base point:
prompt, indicate the point around which you want to rotate. At the Specify rotation angle or
[Reference]: prompt, type an angle at the command line.
The Reference option lets you specify the angle with reference to another angle or an object. At
the
Specify the reference angle <0>: prompt, you type in an angle or (more likely) specify an angle
by picking two points. These are often object snap points on the object that specify the object’s
current angle. At the Specify the new angle:prompt type or pick a new angle. This new angle can
also be indicated by picking an object snap on another object in the drawing. You can use the
Reference option to align the object with another object in your drawing.

Rectangle before rotate Rectangle after rotating by 300


Scaling objects

Scaling, or resizing, objects is another common editing task in AutoCAD. As with rotating
objects, you specify a base point, usually an object snap on the object. The base point is the one

137
point on the object that does not move or change as you scale the object. The most common way
to resize an object is to specify a scale factor. The current object has a scale factor of 1.
Therefore, to increase the size of the object, type in a number greater than 1. For example, a scale
factor of 2 doubles the size of the object. To decrease the size of the object, type a number less
than 1. A scale factor of 0.25 creates an object one-quarter of its previous size.
As with the ROTATE command, you can scale using the Reference option. You specify the
reference length, usually the current length of the object, by typing it in or using object snaps on
the object. At the Specify new length: prompt, you can type a new length or pick a point.
AutoCAD measures this point from the base point you specified to determine the new length.
To scale an object, choose Scale from the Modify toolbar and select the object.
Alternatively, select the object and choose Scale from the Modify toolbar.

Resizing commands

There are four additional commands that resize objects. The TRIM and EXTEND commands
bring the endpoint of an object to another object. LENGTHEN lets you lengthen or shorten a
line, polyline, arc, or elliptical arc. STRETCH is used to stretch (larger or shorter) a group of
objects, letting you change their direction at the same time.

Trimming objects

As you edit a drawing, you may find that lines or arcs that once perfectly met other objects now
hang over. To trim an object, you must first specify the cutting edge, which defines the point at
which
AutoCAD cuts the object you want to trim. You define the cutting edge by selecting an object.
You can select several cutting edges and several objects to trim at one time, as shown in the
figure below. When you select an object to trim, you must pick the object on the side that you
want trimmed (not on the side that you want to remain).

138
To trim an object, choose Trim from the Modify toolbar. You cannot select objects before
starting the TRIM command. AutoCAD displays the Current settings: Projection=UCS,
Edge=None
Select cutting edges: prompt.
AutoCAD lets you know the values of the two system variables that affect trimming.The
Projection setting is used only for 3D models. The Edge setting is used for implied
intersections.When Edge is set to Extend, AutoCAD trims to the implied intersection of the
cutting edge and the object to be trimmed. At this prompt, pick the object(s) you want to use as a
cutting edge. Press Enter to end object selection.
If the object you want to use for the cutting edge is already selected before you start the TRIM
command, AutoCAD deselects it. At the Select cutting edges: prompt, you can type P to reselect
that object.

Before trimming After trimming

Stretching objects

The STRETCH command is generally used to stretch groups of objects. It can be used to enlarge
a certain object, for example. You can also shrink objects. You can change not only the length of
the objects but the angle as well. You use a crossing window to choose the objects to be
stretched.

All objects that cross the boundaries of the crossing window are stretched. All objects that lie
entirely within the crossing window are merely moved. Successful stretching involves precise

139
placement of the crossing window. Figure below shows the process of stretching a garage. Note
that the walls that cross the boundaries of the crossing window are stretched.
However, the dormer, which is entirely within the crossing window, is just moved. This
maintains the integrity of the model.
You cannot stretch circles, text, or blocks. You can stretch arcs, although the results may not be
what you expect. The real power of the STRETCH command is in stretching a number of objects
at once. However, you can also stretch one line. The results are similar to using the CHANGE
command to change the endpoint of a line.
To stretch objects, choose Stretch from the Modify toolbar. AutoCAD responds with the Select
objects to stretch by crossing-window or crossing-polygon... instruction and then the Select
objects: prompt. Create the crossing window and select the objects you want to stretch. (You can
also use a crossing polygon.) After completing the crossing window, check to see which objects
are highlighted.
This helps you avoid unwanted results. You can use the object selection Remove option (type r
enter at the command prompt) to remove objects by picking that you don’t want to stretch or
move.
AutoCAD then displays the Specify base point or displacement: prompt. This step is just like
moving objects. You can respond in two ways.
Pick a base point. At the Specify second point of displacement: prompt, pick a second point.
Object snap and polar snap are helpful for picking these points.
Type a displacement, without using the @ sign. For example, to lengthen the objects by 6 units
in the 0-degree direction, type 6<0. Then press Enter at the Specify second point of
displacement: prompt.
When specifying a displacement by typing at the keyboard, you can use both positive and
negative distances. For example, 6<180 is the same as –6<0. Both would stretch the objects 6
unit to the left.

Before stretch After stretch

140
Extending objects

The EXTEND command has the same prompts as the TRIM command, but instead of trimming
objects to a cutting edge, it extends them to a boundary edge. As with TRIM, when you select an
object to extend, you must pick the object on the side that you want extended (not on the side
that you want left as is).
The object you want to extend does not have to actually intersect the boundary edge after its
extension. AutoCAD can extend an object to a boundary edge that would intersect the extended
object if it were longer. This is called extending to an implied intersection.

Before extending After extending


Extending two lines using an arc as the boundary edge

To extend an object, choose Extend from the Modify toolbar. You cannot select objects before the
EXTEND command. AutoCAD displays the Current settings:
Projection=UCS, Edge=Extend Select boundary edges ... Select objects: prompt. AutoCAD lets you know
the values of the two settings that affect extending. Projection is used only for 3D models. Edge is used
for implied intersections.
When Edge is set to Extend, AutoCAD extends to the implied intersection of the boundary edge and the
object to be extended. At this prompt, pick the object(s) you want to use as the boundary edge(s).
Press Enter to end object selection. You can extend to an actual or implied intersection:
If the extension will result in an actual intersection, at the Select object to extend or shift-select to trim or
[Project/Edge/Undo]: prompt, select objects to extend. Be sure to pick each object at the end you want to
extend. Press Enter to end object selection. AutoCAD extends the object(s). If you want to extend to an
implied intersection, at the prompt , right-click and choose Edge.
AutoCAD responds with the Enter an implied edge extension mode [Extend/No extend]
<Extend>: prompt. Right-click and choose Extend. Then select the objects you want to extend at the
Select object to extend or shift-select to trim or [Project/Edge/Undo]: prompt. Be sure to pick each object
at the end you want to extend. Press Enter to end object selection. AutoCAD extends the object(s). Use

141
the Undo option if the results of the extension are not what you want. You can then continue to select
objects to extend.
You can use the Fence object selection method to select objects to extend. AutoCAD extends the side of
the object that the fence line crosses.

Breaking objects

It is often much easier to draw a long line and then break it into two or more shorter lines. A
common use for BREAK is to break a wall at a door or a window in an architectural floor plan.
You specify two points on the object, and AutoCAD erases whatever is between those two
points. Typically, you use object snaps to specify the points. Sometimes, you can use TRIM to
break an object, but if there is no convenient cutting edge, you may find BREAK more efficient.
You can break lines, polylines, splines, xlines, rays, circles, arcs, and ellipses.
To break a line, choose Break from the Modify toolbar. You cannot select the object first and
then the BREAK command. AutoCAD responds with the Select object: prompt. (Notice that you
can only select one object to break.) At this prompt, you have two choices:

I. Select the object at one of the break points you want to create. AutoCAD then responds
with the Specify second break point or [First point]: prompt. Because you have already
specified the first point, you can now specify the second point. AutoCAD breaks the
object between the two points.
II. Select the object using any method of object selection. AutoCAD then responds with the
Specify second break point or [First point]: prompt. Right-click and choose First point.
At the Specify first break point: prompt, pick the first break point. At the Specify second
break point: prompt, pick the second break point. AutoCAD breaks the object between
the two points.

Example: Construct a rectangle and call the break command using one of the methods which
shows:Command: _break
Select object: pick at the point
Specify second break point or [First point]: pick
Command:
The result is shown in the figure.

142
Join Command

The Jointool can be used to join polylines provided their ends are touching; to join lines which
are in line with each other; to join arcs and convert arcs to circles.
Example:Construct a rectangle from four separate polylines. Then Call the Join tool (click the
Join tool icon in the Home/Modify panel, left-click its tool icon in the Modify toolbar, select Join
from the Modify drop-down menu or enter join or j at the command line. The command line
shows:
Command: _join
Select source object:pick a pline
Select objects to join to source: pick a pline
1 found
Select objects to join to source: pick another
1found, 2 total
Select objects to join to source: pick another
1found, 3 total
Select objects to join to source: right-click
3 segments added to polyline
Command: right-click
Command:
The result is shown in the figure..

CHAMFER command Or (Auto Cad 2007)

The CHAMFER command creates corners from two nonparallel lines. You can also chamfer
xlines, rays, and polylines. You can simply extend the lines to meet at an intersection (a square
corner), or create a beveled edge. If you create a beveled edge, you define the edge by either two

143
distances or one distance and an angle relative to the first line you are chamfering. This figure
shows the elements of a chamfered corner.

Chamfering is a two-step process. First you define how you want to chamfer the corner,
specifying either two distances from the corner or a distance and an angle.
Then you select the two lines you want to chamfer. AutoCAD chamfers them using the
information you specified.
To chamfer, choose Chamfer from the Modify toolbar. You cannot select objects before the
CHAMFER command. AutoCAD responds with the (TRIM mode) Current chamfer Dist1 =
0.5000,
Dist2 = 0.5000 Select first line or [Polyline/Distance/Angle/Trim/Method]: prompt. AutoCAD
starts by listing the current settings. You can define two distances from a corner or one distance
and an angle:
• To define two distances from the corner, right-click and choose Distance. At the Specify first
chamfer distance <0.5000>: prompt, type the first chamfer distance or press Enter to accept the
default (which is the last distance you defined). At the Specify second chamfer distance
<0.5000>: prompt, type the second distance. The default for this is always the first chamfer
distance because equal chamfer distances are so common.
• To define a distance (from the corner) and an angle, right-click and choose Angle. At the
Specify chamfer length on the first line <1.0000>: prompt, enter a distance. This is the same as
the first chamfer distance. At the Specify chamfer angle from the first line <0>: prompt, type the
angle between the first line and the chamfer line.

Example:Construct a rectangle 100 by 60 using either the Line or the Polyline tool. Then Call
Chamfer tool ( click the arrow to the right of the tool icon in the Home/Modify panel and select
Chamfer from the menu which appears, click on its tool icon in the Modify toolbar, pickChamfer

144
from the Modify drop-down menu, or enter cha or chamfer at the command line) which then
shows:

Command: _chamfer
(TRIM mode) Current chamfer Dist1 = 1, Dist2 = 1
Select first line or [Undo/Polyline/Distance/ Angle/Trim/Method/Multiple]: d
Specify first chamfer distance < 1 >: 10
Specify second chamfer distance <10 >: right-click
Select first line or [Undo/Polyline/Distance/Angle/Trim/ Method/Multiple]: pick the first line for
the chamfer
Select second line or shift-select to apply corner: pick
Command:
The result is as follows.

FILLET command Or (Auto Cad 2007)

The FILLET command creates rounded corners, replacing part of two lines with an arc. Fillets
are often used in mechanical drawings. In certain cases, you can use FILLET instead of the ARC
command to create arcs. As with CHAMFER, you can fillet lines, xlines, rays, and polylines—
they can even be parallel. You can also fillet circles, arcs and ellipses.The FILLET command
defines the fillet arc by its radius, as shown in this figure.

145
Like chamfering, filleting is a two-step process. First you define the radius of the fillet arc. Then
you select the two lines you want to fillet. AutoCAD fillets them using the information you
specified.
To specify the fillet information, choose Fillet from the Modify toolbar. You cannot select
objects before the command with Fillet. AutoCAD responds with the Current settings: Mode =
TRIM, Radius =0.5000 Select first object or [Polyline/Radius/Trim]: prompt. Right-click and
choose Radius. At the Specify fillet radius<0.5000>: prompt, type the radius you want. The
default is either 0.5000 or the last radius you specified.
AutoCAD repeats the Select first object or [Polyline/Radius/Trim]: prompt. Select the first object
you want to fillet. At the Select second object prompt, select the second object you want to fillet.
AutoCAD creates the fillet.By default, FILLET trims the original lines that it fillets, but the
FILLET command recalls the last setting you used. If you want to keep the full original lines
when you create a fillet, right-click and choose the Trim option and then choose No Trim.
Filleting with a zero radius gives the same results as chamfering with distances set to zero.
The order in which you select the two objects to be filleted is not important. However, where you
pick the objects is quite important. If two objects intersect, AutoCAD keeps the objects on the
same side of the intersection as your pick point and fillets them. Those parts of the objects on the
far side of the intersection are erased.
When you fillet arcs and lines, if more than one fillet is possible, FILLET connects the endpoints
closest to your pick points. Filleting circles and lines can result in unexpected results. Sometimes
you need to experiment to find the proper pick points.

Example:Construct a rectangle 100 by 60 using either the Line or thePolyline tool. Then Call
Fillet (click the arrow to the right of the tool icon in the Home/Modify panel and select Fillet
from the menu which appears, pick its tool icon in the Modify toolbar, pick Fillet from the
Modify drop-down menu, or enter f or fillet at the command line)which then shows:

Command: _fillet
Current settings: Mode = TRIM, Radius = 1
Select first object or [Polyline/Radius/Trim/Multiple]: r (Radius)
Specify fillet radius < 0 >: 15
Select first object or [Undo/Polyline/Radius/Trim/Multiple]: pick

146
Select second object or shift-select to apply corner: pick
Command:

The result will be as follows.

EXPLODE Command (Auto Cad 2007)

The Explode Command breaks a compound object into its component objects. It explodes a
compound object when we want to modify its components separately. Objects that cn be
exploded include blocks, polylines, and regions among others.

A click on the icon or entering ex atthe command line brings prompts into the command line:

Command: _explode
Select objects: pick a block on screen 1 found
Select objects: right-click
Command:
and the picked object is exploded into its original objects.

147
LAB EXERCISE 3
Using the necessary Draw and modify commands that we see in previous labs construct the
following figures.

#1 #2

#3 #4

148
#5#6

#7 #8

#9

149
#10

150
#11

151
#12

152
Lab Session 4

BLOCKS, HATCHING, REGION AND TEXT


Objectives

The aims of this Lab session are:


 To describe the construction of blocks.
 To introduce the insertion of blocks into drawings.
 To introduce the use of hatching in its various forms.
 To introduce about regions.
 To describe methods of adding text to drawings.

4.1 BLOCKS

A Block is a series of objects (lines, arcs, text etc.) grouped together to form a single entry. This
entry can be inserted in to a drawing any number of times without significantly increasing the
size the size of the drawing file. You can use blocks to create libraries of frequently used
symbols.

153
Blocks are drawings which can be inserted into other drawings. Blocks arecontained in the data
of the drawing in which they have been constructed.Wblocks (written blocks) are saved as
drawings in their own right, but canbe inserted into other drawings if required.

A block definition is a collection of objects grouped together to form a single object that can be
inserted in to a drawing any number of time. When inserted, blocks can be assigned different
scale and rotation factors.

We can call the block command by using one of the following.

Draw toolbar

Draw menu Block

Command line entry B or Block

The block command is used to create new blocks that will be defined with in the current drawing
file. The above commands will activate Block definition dialogue box.

Fig 4.1 Block definition dialog Box

154
Name: Specifies the name of the block up to 31 characters.

Basepoint: Indicates the insertion point for the block. Specify X, Y, Z co-ordinates or use the
pick point button to specify base point on the drawing.

Selectobject: Picks the objects to include in the new block.

Retain: If checked, selected object will remain in the drawing.

Convert to block: Converts and replaces the selected object to a block.

Delete: If checked objects included in the block will be deleted from the drawing.

Preview icon: View preview icon On and Off.

Units: Specifies the units the block is scaled to.

Description: Accepts a textural description up to 256 ASCII characters long for display in
content explorer.

Block insertion

Blocks can be inserted into a drawing by using the inserted dialogue box.

Draw toolbar

Inset menu Block…

Command line entry I orInsert

The insert dialogue box includes the following setting:-

Name: Select from the list of blocks.

Browse: Choose Browse… to select from a list of available drawing files using the select
drawing file dialogue box.

155
Specify on the screen: select to use the pointing device to define the insertion point, scale and
rotation angle of the block on the drawing.

Explode: Select to insert the block as the individual objects that make up the block.

Attribute Definition: An attribute is informational text associated with a block. An attribute


definition specifies an attribute’s properties and the prompts which appear when the block is
inserted.

Draw toolbar

Draw menu Block Define attributes

Command line entry ATT or Attdef

The attribute Definition dialogue box creates the attribute tag that appears in the drawing. When
a block is inserted, the attribute tag is replaced by the attribute value at the same location in the
block with the same text style and alignment.

Activate the attribute Definition dialogue box to create an attribute definition, which describes
the characters of the attributes. The characters include the tag prompt, value information, text
information and location.

4.2 HATCHING
Hatching in AutoCAD is a way of filling in areas of your drawing with a pre-formatted pattern to
represent certain materials. It is usually used in sectional views.
You can start the hatch command with one of the following options:
1. By typing H on the keyboard on the command line

2. By using icon on the draw command


3. From the dropdown menu, draw then hatch
When you start the command by using one of the above options, the following dialog box will
appear:

156
Fig 4.2Hatch and gradient dialog box

The Boundary hatch dialogue box is accessed from the draw toolbar and contains the most
common patterns used in controlling hatch pattern definition.
Quick tab feature
Type: Sets the pattern type, there are three options:

Predefined:-You can select from a range of predefined pattern

User defined:- Allows you to define a pattern based on parallel line with spacing and
angle values, using the current line type.

Custom: -Allows you to select a hatch pattern definition not found in the supplied
acad.pat and acadiso.pat files

Angle:Specifies an angle for the hatch pattern relative to the X-axis.

Scale:Expands or contracts a predefined or custom pattern

Pick point: Allows you to determine a boundary from a set of existing objects from which you
want to form an enclosed area. AutoCAD prompts you for a point inside the boundary to be
hatched.

The pick point will detect islands that are within the boundary generated. The space within the
island will not be hatched. This will also apply if the object(s) in question are text.

157
Select Object: Only the object selected will be hatched. The hatch will ignore objects that have
not been selected as boundaries.

Remove island select:objects that AutoCAD detects as island. This option is activated when a
hatch boundary is selected using "pick point" or "select object' option.

View selection:Hatch dialogue box disappears showing the current defined boundaries with hatch
setting that previewed.

There are few things that you have to do to get the hatch that you require. First you must select
the pattern that you want to use. Pick the PATTERN button to do this. Next you have to pick the
internal point that you need the hatch to fill. Use the PICK POINTS button to do this. You can
pick more than one internal point. The important thing to remember is that the entire boundary
must be visible on the screen, or AutoCAD will not be able to hatch it. Once you have picked
your pattern and points, pick on the PREVIEW button to see how the hatch will appear. If
everything is OK, press the
APPLY button. IF you need to change anything, you can adjust the scale and angle of the hatch
until it looks the way you want it to.

4.3 REGIONS
Regions are two-dimensional surfaces. They look like closed polylines, but AutoCAD can
calculate more information from regions than from polylines, such as the centroid, moments of
inertia, and other properties relating to mass. You can also create complex shapes by combining,
subtracting, and intersecting regions. While these commands are most often used for 3D
drawing, they are often used in 2D drawing as a preparation for 3D drawing. You create a region
from other objects. You can use closed polylines, closed splines, circles, ellipses, and
combinations of lines, arcs, and elliptical arcs that create a closed shape. The shape cannot
intersect itself like a figure below.
A complex region is shown below. Although it looks like a circle with seven circles inside it, it is
actually a circular surface with seven holes in it. When you select it, you can see that it is one
object.

158
The real proof of the pudding is when you try to extrude it to create a 3D object out of it. You
can then view it at an angle, hide background lines, and clearly see the holes, as shown in the
second figure.

To create a region, choose Region from the Draw toolbar. AutoCAD asks you to select
objects.
Select all the objects and press Enter to end object selection. If all the objects create a closed,
nonintersecting shape, AutoCAD tells you:
1 loop extracted.
1 Region created.
The original objects are deleted. If your objects aren’t perfectly end to end, AutoCAD merely
states:
0 loops extracted.
0 Regions created.
In order to draw your original objects end to end, remember to use Endpoint object snaps. Also,
don’t forget that you can start a line or arc at the end of the last point drawn by pressing Enter at
the first prompt.
If you had a hatch inside the objects, you lose hatch associativity. You can re-hatch the region if
you wish. When you create a region that is hatched, AutoCAD has no problem creating the
region but doesn’t quite know what to say about the hatch.
Here’s the response:
1 closed, degenerate or unsupported object rejected.
As mentioned earlier, you can combine, subtract, and intersect regions to create complex objects.
The three commands to accomplish these functions are UNION, SUBTRACT, and INTERSECT.
These commands are most often used in 3D drafting.

4.4 TEXT

159
Text conveys important information in your drawing. You use text for title blocks, to label parts of the
drawing, to give specifications, or to make annotations.

AutoCAD provides various ways to create text. For short, simple entries use line text. For longer entries
with internal formatting, use multiline text. Although all entered text uses the current text style, which
establishes the default font and format settings, you can customize the text appearance.
Multiline text

Single line text

Edit text

Find and replace

Text style

Scale text

Justify text

between points
Convert distance

Using Line Text

Draw toolbar:Text→ Single line text


Command line entry: DT or DTEXT

Using TEXT you can create one or more lines of text and end each line when you press ENTER.
Each text line is a separate object that you can relocate, reformat, or otherwise modify. To create
line text

1. From the Draw menu, choose Text -- Single Line Text

2. Specify the insertion point for the first character. Press ENTER to locate the new text
immediately below the last text object you created, if any. If the text height is set to 0 in the
current text style, you are prompted to specify the height of the text.

160
3. Set the text height by dragging the pointing device until the distance between the cursor and
the insertion point indicates the text height you want. Or on the command line, enter a value in
drawing units.

4. Set a text rotation angle by dragging the pointing device until the angle between the cursor and
the insertion point represents the text rotation angle you want. Or on the command line, enter the
X, Y coordinate.

5. Enter the text. Press ENTER to end one line of text and begin another. The TEXT command
displays the text in the drawing as you type. Each line of text is a separate object. If you select
another point in the drawing while TEXT is active, the cursor moves to that point, and you can
continue entering text from there.

6. Press ENTER on a blank line to end text creation.

Formatting Line Text

You can format text as you create it using the options on the command line. Justify determines
how the characters in the text line align with the insertion point. Style sets the default format
characteristics.

You cannot apply formats to individual words and characters using TEXT. If you want to apply
formats to individual words and characters, use MTEXT.

Aligning Line Text

As you create text, you can align it horizontally. That is, you can justify it using one of the
alignment options shown in the following illustration. Left alignment is the default. To left-align
text, do not enter an option at the Justify prompt

Text alignment

When using Dtext Command the default alignment option is bottom left of text. There are a
variety of text alignment options available to enable you to replace text more precisely. When
you activate the Dtext command you will be presented with the following command line
options:-

161
Specify start point of text or [justify / Style]: Enter J to activate the text justify option

Enter an option: [align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR]:

Align: Specifies both text height and text orientation by designating the end points of the
baseline. The text will be fitted between the two points, the text height reducing as the text string
becomes longer.

Fit: Fits text with in an are and at an orientation defined by two points

Center: Aligns text from the horizontal center of the baseline, which you specify with a point.

Middle: Aligns text at the horizontal center of the base line and the vertical center of the height
you specify with a point

Right: Specifies the right end point of text base line.As well as the text placement options
discussed ,you can specify justification based upon the 9 locations.

Top left /Center/ Right


Middle left/ Center/Right
Bottom left/ Center/Right

Multiline Text

Draw menuText→ Multiline text

Command line entryMT or MTEXT

Mtext creates paragraph that fit with in a text boundary. the boundary defines the width of the
paragraph to be entered onto the drawing. Mtext also allows you to specify text justification,
style, height, width, colour spacing and other text attributes. You can select any font within the
character tab, irrespective of the text style created using the text style dialogue box for use with
the Dtext.

Single-line text is awkward when you want to type quite a bit of text. The main disadvantage is
that single-line text does not use word wrap, a feature that wraps text to the next line to keep a
neat right margin. Multiline text (also called paragraph text and not to be confused with

162
multilines) solves this problem and also offers many more formatting options compared to
single-line text. The entire paragraph of multiline text is one object.
The edit box you use to create multiline text resembles Windows word processors and is
resizable.
You use this box both to create and also to edit text and its properties.

To create paragraph text, choose Multiline Text from the Draw toolbar. This starts the MTEXT
command. AutoCAD tells you the current style and text height. For example:
Current text style: ROMANS. Text height: 0.2 of a bounding box to specify where to place the
text.
At the Specify opposite corner or [Height/Justify/Line spacing/Rotation/Style/Width]: prompt,
specify the diagonally opposite corner of the bounding box. You can also choose one of the other
options to specify the text properties before you type in the text. The Multiline Text Editor is
shown in below.

Text Editing

Modify Menu Text…

Command line entry EDor DDEDIT

Use the Ddedit to alter an existing Dtext or Mtext string.

LAB EXERCISE 4

#1 Using make block command create the following 3 objects and insert them in your current
drawing file using insert block.

163
# 2 Using Wblockwrite the following figure and insert it by opening new drawing file.

#3Draw this shape and hatch each possible section. It could looksomething like this when it is
done (check that you hatched all areas and the scale iscorrect.

#4Using polyline and hatch command draw the following figure.

164
#5 Draw the following figure using the necessary draw and modify commands.

165
#6Using the text style Arial of height 20and enclosing the wording within a polylinerectangle of
Width=5 and Fillet=10,construct the drawing shown below.

166
Lab Session 5

LAYERS, DIMENSIONING AND CHANGE PROPERTIES


Objectives

The aims of this lab session are:


 To show the benefits of using different type of layers in a drawing.
 To describe a variety of methods of dimensioning drawings.
 To describe how to change the properties of objects.

5.1 Layers

Drawing can be controlled by the use of layers, line types and colors. A complex drawing may
include text, construction line, and hidden details, dimensions various views, etc., all of which
combined would present the reader with to much information. A drawing could easily become
cluttered. By assigning aspects of your drawing to a particular drawing to a particular layer, i.e.,
text to the text layer, you can make visible only the information you wish to present. This chapter
will show you how to create new layers, allocating each layer its own specific color and line
type.

Complex drawing may contain a large number of elements. AutoCAD allows you to create as
many layers as is necessary to organize your drawing.

Think of a layer as a sheet of overhead transparency onto which you can place specific objects
such as text or dimensions. By switching these layers on or off you can determine the visibility
of specific elements within the drawing.

Controlling Layer

Layers are created and controlled from the layer properties manager dialogue box, which can be

located on the object toolbar ( ) or by selecting Layers… from the format pull down menu.
This dialogue box is used to assign each layer a specific name, line type and color.

167
Layer Properties

Layers have the following properties:

Layer Name - The name of layer, can be up to 31 characters in length, made up from
characters, digits or special characters (dollar $, hyphen and underscore_).

Visibility - Layers can be turned either On or Off. .

Freeze / Thaw - Controls the regeneration of the layer when a display is regenerated.
Thawed layers are regenerated. Freezing unneeded lavers increases regenerationspeed.

Locked / Unlocked - Objects on locked layers are visible but cannot be edited. Locked
layers can be current, can be drawn upon and line type and color can be changed.

Layer Plot table- Layers can be potable or non-plot table. A non-potable layer will be
visible on the screen but will not appear in a hard plot.

Color Number - The color number determines the color for visible layers. Default layer
color is 7 (white, though appears black on the screen!). Objects can override color assigned to
layers.

168
Linetype - Name of line type defined for that layer. Several layers can use the same line type.
Objects can override the line type assigned to a layer.

Lineweight- Displays the available line weights that can be applied to a layer

Steps to create a layer:-

Press the layer button to activate the layer properties Manager Dialogue box.

Press the new button and enter the layer name Construction line.

Fig 5.1 Layers property manager dialog box

Set layer line type

Set the line type continuous on the construction line. This will activate the select linetype
dialogue box. Press Load… button to activate the load or reload line type dialogue box. Use the
scroll bar on the right of the box to look at the variety of linetypes available for selection.

Fig 5.2 Select line type and load and reload line type
dialog box

Color selection

169
When you start anew drawing, you will see in the colour control box in the object properties tool
bar that the colour is set to Bylayer, that is the colour set to layer 0,I.e white.You can change this
to any colour at any time irrespective of the colour setting on the current layer by selecting the
select colour dialogue box.Selection of colour will make it current and override that is set to the
current layer.

Fig 5.3 The select color dialog box

5.2DIMENSIONING

Dimensioning is one of the most important and time-consuming feature of drawing. a complex
drawing mar require a variety of dimensioning such as linear, radial and angular dimensions.

Parts of dimensioning

 Dimension line: is a line that indicates the direction and extent of a dimension.
 Extension line: extend from the feature to the dimension line
 Arrowhead: are added to each end of the dimension line
 Dimension text: is an optional text string that usually indicates the actual measurement.
 Leader line: is a solid line leading from some annotation to the referenced feature.

170
Dimension tool bar

There are several ways in which the dimensions tools can be called:

1. From the Annotate/Dimensions panel ( for AutoCad 2009 and above ).

2. From the Dimension toolbar. The toolbar can be called to screen with a right-click in any
toolbar on screen followed by a click on Dimension in the pop-up menu which appears.

3. Click Dimension in the menu bar. Tools can be selected from thedrop-down menu which
appears.
4. By entering an abbreviation for a dimension tool at the command line.

Any one of these methods can be used when dimensioning a drawing, butsome operators may
well decide to use a combination of the four methods.

Linear
171
Used to draw exactly horizontal and vertical dimensions

Example: Construct a rectangle 180x110 using the Polylinetool. Then Click on Linear in the
Dimensiontoolbar. The command line shows:

Command: _dimlinear
Specify first extension line origin or <selectobject>: pick
Specify second extension line origin: pick
Non-associative dimension created.
Specify dimension line location or [Mtext/Text/ Angle/Horizontal/Vertical/Rotated]: pick
Dimension text = 180
Command:
Figure below shows the 180 dimension. Follow exactly the same procedurefor the 110
dimension.

Aligned

The dimension line will be aligned to selected points

Example:Construct the outline shown below using the Line tool. Left-click the Aligned tool
icon and dimension the outline. The prompts and replies are similar to the linear example.

172
Arc Length

Used to measure the length of an arc or poly line arc segment

Example:Construct two arcs of different sizes as in the following figure. Then click on Arc Length in the
Dimension toolbar or enterdimarc at the command line. The command line shows:

Command: _dimarc

Select arc or polyline arc segment: pick an arc

Specify arc length dimension location, or [Mtext/

Text/Angle/Partial/Leader]: pick a suitableposition

Dimension text= 147

Command:

Examples on two arcs are shown in the figure below.

Jogged radius
173
You can create jogged radius dimensions, also called “foreshortened radius dimensions,” when
the center of an arc or circle is located off the layout and cannot be displayed in its true location.

Example:Draw a circle and an arc as indicated in Figure below. Then Call the Jogged tool with
a click on Joggedin the Dimension toolbar or by entering jog at the command line.
Thecommand line shows:

Command: _dimjogged
Select arc or circle: pick the circle or the arc
Specify center location override: pick
Dimension text = 60
Specify dimension line location or [Mtext/Text/Angle]: pick
Specify jog location: pick
Command:
The results of placing as jogged dimension on a circle and an arc areshown below.

Dimension Style

Every dimension style has a dimension style associated with it. You can use default dimension
style or define your own. Dimension style manager dialogue box is used to modify existing or
create new dimension style. To activate this dialogue box, select Dimension style from the
Format menu.

174
Fig 5.4Dimension StyleManager dialog box

Dimension style dialogue box shows the current setting for the various linear, radial and angular
dimension. In case of the ISO-25 style shown, this means that dimensions are set to 2 decimal places and
dimensions are aligned along the dimension line using the standard text style.
 Set current: To make selected style current if we have many dimension styles.

 New: When we want to create new dimension style.

 Modify: If we want to change the setting of existing dimension style.

Creating new dimension style

Press the new button on the dimension style manager dialogue box. Enter style name then press Continue
You will get new dimension style dialogue box.

175
Fig 5.5New dimension style dialog box

Line and arrow tab

Is used to set the color and thickness of the dimension and extension lines
The size and type of arrow heads, selectable from the list, used for the dimension line and
leader.
The size types and visibility of a center mark for the circles.
Base line spacing for base line dimension style.

Text tab

Use this tab to set text style, color and position on the dimension line
Text alignment options includes

176
 Forced horizontal
 Aligned with the horizontal line
 Set to the ISO standard

Fit tab

Use this tab to set the placement of the dimension text, line and arrows between the
extension lines. If there is limited room between the extension lines, these options allow
you to determine weather the text or arrows are forced out side the extension line.
Sets text placement when it is not possible to accept the default text position.
Overall scaling factor. Used to scale all the elements of the dimension to suit the drawing
scale.

Primary tab

Used to set dimension units and number of decimal place.


Dimension text prefix / suffix
Zero suppression, leading or trailing
Units and precision of angular dimensions.

Alternate units tab

Used to set alternate units format and placement. Dimension text will include both Metric
and imperial equivalent dimensions.

Tolerance tab

Use this tab to select and set one of three tolerance formats. These includes:-
Symmetrical, Deviation, Limits, Basic.

Before simple tolerances can be included with dimensions, new settings will need to be made in
the Dimension Style Manager dialog as follows:
1. Open the dialog. The quickest way of doing this is to enter d at the command line
followed by a right-click. This opens up the dialog.

177
2. Click the Modify … button of the dialog, followed by a left-click on the Primary
Units tab and the resulting sub-dialog make settings as shown in Figure below. Note
the changes in the preview box of the dialog.

Fig 5.6 The modify Dimension Style dialog box

5.3 Object Properties Manager


The Object Property Manager is a window that displays the properties of selected objects. You
can use the Object Property Manager (which can also be called the Properties window or OPM)
to change the properties of objects as well.

To open the Object Property Manager window, click Properties on the Standard toolbar.
The
Properties window opens on your screen.

178
The Properties window can be used to directly edit objects, called Geometry in theProperties
window, but can be used for editing other object properties as well:
 You can change the layer, color, linetype, linetype scale, and lineweight of objects.
 You can edit text and text properties.
 You can edit plot styles.
 You can edit hyperlinks.

The Properties window contains two tabs. The Categorized tab organizes the types of properties
you can edit by category. In the properties window above, you see the result of opening the
Properties window with one line selected. Use the Geometry category to edit the line. The
Alphabetic tab contains the same information organized alphabetically.
To change either endpoint of the selected line, just type new coordinates in the Properties
window and press Enter. Of course, this method of editing a line is only useful when you know
the absolute coordinates. When you select a geometric property, such as Start X, the X
coordinate of the line’s start point, an arrow button appears. You can click this button and then
pick a new start point directly on your screen. The new point becomes the new start point of the
line, changing both the X and Y coordinates of the start point if your pick point requires it.
The information you see in the Properties window depends on whether objects are selected:
 If you open the Object Properties Manager with no object selected, you see only
properties that apply to the entire drawing, such as UCS, current layer, and viewport data.
You can select an object while the window is open to display data on that object.

179
 If one object is selected, you see both general information and geometrical information
on that object.
 If more than one object is selected, you see general information such as layer, color, and
linetype data, but no geometry data.
 If more than one object is selected and you choose one type of object from the drop-down
list at the top of the window, you see information applying only to that type of object.
This dropdown list provides a quick way to filter the type of objects you can edit.

LAB EXERCISE 5
#1. By opening a layer properties manager dialog box, create the following layers with the given
properties.

Name Color Line type Line weight


Object line Red Solid Default
Hidden line Blue Hidden 2 0.05
Phantom Green Phantom 0.15
Center line Cyan Center 0.25
Text Magenta Solid 0.3

#2.Open any of the drawings previously saved from exercises and add appropriate dimensions.

#3.Construct the drawing shown below but inplace of the given dimensions add
dimensionsshowing tolerances of 0.25 above and below.

180
#4.Give the dimension for the following drawing which you construct in previous lab exercise.
Use appropriate layer for each line type.

#5.Give the dimension for the following figure which you construct in Lab exercise 2.

181
Lab Session 6

ORTHOGRAPHIC PROJECTION, SECTIONAL AND ISOMETRIC


DRAWINGS
Objectives

The aims of this lab session are:

 To introduce methods of constructing views in orthographicprojection


 To introduce how to make sectional drawings
 To introduce about the construction of isometric drawings
o To introduce about ISOPLANE
o To see how to draw in isometric mode

182
6.1 Orthographic projection
Orthographic projection involves viewing an article being described in a technical drawing from
different directions – from the front, from a side, from above, from below or from any other
viewing position. Orthographic projection often involves:
 The drawing of details which are hidden, using hidden detail lines
 Sectional views in which the article being drawn is imagined as being cut through and the
cut surface drawn
 Centre lines through arcs, circles spheres and cylindrical shapes.

Example:
Taking the solid shown in Fig. 6.1, to construct a three-view orthographic projection of the solid:
1. Draw what is seen when the solid is viewed from its left-hand side and regard this as the
front of the solid. What is drawn will be a front view (Fig. 6.2).

Fig 6.1 Fig 6.2The front view of the solid


2. Draw what is seen when the solid is viewed from the left-hand end of the front view. This
produces an end view. Figure 6.3 shows the end view alongside the front view.
3. Draw what is seen when the solid is viewed from above the front view. This produces a
plan. Figure 6.4 shows the plan below the front view.
4. In the Home/Layers panel, in the Layer Control list click on Center to make it the
current layer (Fig. 6.5). All lines will now be drawn ascentre lines.
5. In the three-view drawing add centre lines.
6. Make the Hidden layer the current layer and add hidden detail lines.

183
Fig. 6.3 Front and end views of the
solid

Fig 6.4 Front and end views and plan of the


solid

184
Fig 6.5 Making the layer Center current from the Layers panel
7. Make the Text layer current and add border lines and a title block.
8. Make the Dimensions layer current and add all dimensions.

The completed drawing is shown in Fig. 6.6.

Fig 6.6 The completed working drawing of the solid

185
6.2 Sectional views

In order to show internal shapes of a solid being drawn in orthographic projection the solid is
imagined as being cut along a plane and the cut surface then drawn as seen. Common practice is
to hatch the areas which then show in the cut surface. Note the section plane line, the section
label and the hatching in the sectional view ( Fig. 7.10 ).

Fig 6.7 A sectional view

Adding hatching

To add the hatching as shown in Fig. 6.7:


1. Call the Hatch tool – either left-click on its tool icon in the Home/ Draw panel, click the
tool in the Draw toolbar, or enter h at the command line. Note: do not enter hatch as this
gives a different result. The Hatch and Gradient dialog (Fig. 7.8) appears.
2. Click in the Swatch field. The Hatch Pattern Palette appears. Left click the ANSI tab
and from the resulting pattern icons double-click the ANSI31 icon. The palette disappears
and the ANSI31 pattern appears in the Swatch field.

186
Fig 6.8The Hatch and Gradient dialog and the A NSI Hatch Pattern Palette

3. In the dialog left-click the Pick an internal point button. The dialog disappears.
4. In the front view pick points as shown in the left-hand drawing of Fig. 6.9. The dialog
reappears. Click the Preview button of the dialog and in the sectional view which
reappears; check whether the hatching is satisfactory. In this example it may well be that
the Scale figure in the dialog needs to be entered as 2 in place of the default 1. Press the
Esc key of the keyboard and the dialog returns. Change the figure and Preview again. If
satisfied right-click.

187
Fig 6.9The result of hatching

6.3Isometric Drawings
An isometric drawing is a 2D drawing drawn to look like a 3D drawing. By drawing
parallelograms instead of squares, the drawing gives the impression of being in three dimensions.
AutoCAD enables you to do the same thing.

Setting the AutoCAD window for isometric drawing


To start isometric mode, choose Tools then Drafting Settings to open the Drafting Settings dialog
box. On the Snap and Grid tab, in the Snap type & style section, choose Grid snap (if not already
selected), and then Isometric snap. While you’re there, turn on Snap and Grid if you want them
on. Click OK. Once you are in isometric mode, press F5 to toggle from plane to plane.
Or
To set the AutoCAD window for the construction of isometricdrawings:
1. At the command line:
Command: enter snap
Specify snap spacing or [On/Off/Aspect/Rotate/Style/Type] <5 >:s (Style)
Enter snap grid style [Standard/Isometric]< S> : i (Isometric)
Specify vertical spacing < 5 >:right-click
Command:
And the grid dots in the window assume an isometric pattern as shownin Figure below. Note also
the cursor hair lines which are at set in anIsometric right angle.

188
Understanding isometric planes

AutoCAD uses the ISOPLANE (short for isometric plane) command to rotate the crosshairs to
the special angles required for isometric drawing. You then toggle the ISOPLANE setting from
left to right to top to draw on each of the three “planes.” As you do so, AutoCAD changes the
angles of the crosshairs, snap, and grid to the appropriate angles.
These angles are 30 degrees for the X axis, 90 degrees for the Z axis, and 150 degrees for the Y
axis. As you toggle among the planes, you see the crosshairs take on various configurations of
these angles. The figure below shows the standard isometric cube. You can see three sides—left,
right, and top. In the figure, the crosshairs are set to the right isometric plane.
Isometric drawing is not often used for precise drawing because it can be difficult to specify the
exact points you need. Also, true 3D drawing has mostly supplanted isometric drawing. It is,
however, used for piping work as well as for illustrations.

There are three isometric angles – Isoplane Top,Isoplane Left and IsoplaneRight. These can be
set either by pressing the F5 function key or by pressing the Ctrl and E keys.Repeated pressing
of either of these ‘toggles’ between the three settings. Figure below is an isometric view showing
the three isometric planes.

189
The isometric circle
Circles in an isometric drawing show as ellipses. To add an isometriccircle to an isometric
drawing, call the Ellipse tool. The command lineshows:

Command: _ellipse
Specify axis endpoint of ellipse or [Arc/Center/Isocircle]:enter i (Isocircle)right-click
Specify center of isocircle:pick or entercoordinates
Specify radius of isocircle or [Diameter]: entera number
Command:

And the isocircle appears. Its isoplane position is determined by whichof the isoplanes is in
operation at the time the isocircle was formed.Figure below shows these three isoplanes
containing isocircles.

Example 1:

190
1. Working to the shapes and sizes given in the orthographic projection in Fig. 6.10, set
Snap on (press the F9 function key) and Grid on (F7).
2. Set Snap to Isometric and set the isoplane to Isoplane Top using F5.
3. With Line, construct the outline of the top of the model (Fig. 6.11) working to the
dimensions given in Fig.6.10.
4. Call Ellipse tool and set to isocircle and add the isocircle of radius 20 centered in its
correct position in the outline of the top (Fig. 6.11).
5. Set the isoplane to Isoplane Right and with the Copy tool;copy the top with its ellipse
vertically downwards three times asshown in Fig. 6.12.
6. Add lines as shown in Fig. 6.11.
7. Finally using Trim remove unwanted parts of lines and ellipsesto produce Fig. 6.12.

Fig 6.10 Fig 6.12

191
Fig. 6.11

Example 2:

Figure 6.4 is an orthographic projection of the model of which the isometric drawing is to be
constructed. Figure 6.5 shows the stages in its construction. The numbers refer to the items in the
list below.

Fig 6.13

192
1. In Isoplane Right construct two isocircles of radii 10 and 20.

2. Add lines as in drawing 2 and trim unwanted parts of isocircle.

3. With Copy commandcopy 3 times as in drawing 3.

4. With Trimcommandtrim unwanted lines and parts of isocircle as in drawing 4.

5. In Isoplane Left add lines as in drawing 5.

6. In Isoplane Right add lines and isocircles as in drawing 6.

7. With Trimcommandtrim unwanted lines and parts of isocircles to complete theisometric


drawing – drawing 7.

Fig 6.14

LAB EXERCISE 6
Figure 1 below is an isometric drawing of a slider fitment on which the three exercises 1,2 and 3
are based.

193
Fig 1

#1 Figure 2 below shows a first angle orthographic projection of part of the fitment shown in the
isometric drawing in Fig. 1. Construct a three-view third angle orthographic projection of the
part.

Fig .2

#2 Figure 3 below shows a first angle orthographic projection of the other part of the fitment.
Construct a three-view third angle orthographic projection of the part.

194
#3Construct an isometric drawing of the part shown in Fig. 3 below.

Fig. 3

#4 .Figure 4 shows a pictorial drawing of the component shown in the three-view orthographic
projection of Figure.5. Construct the three views but with the font view as a sectional view based
on the section plane A – A.

Fig.4

195
Fig. 5

#5. Construct the following objects using isometric drawing.

196
197
198
#6. Construct an isometric drawing of the angle plate shown in Figs 6 and 7.

199
Fig. 6 Fig. 7

# 7. Copy the following figure of Cotter joint with socket and spigot ends.

200
# 8.The two views of a model are given below. Copy the two views and generate a full sectional view by
replacing one of the views by chosing apropriate cutting line.

201
Lab session 7

3-DIMENSIONAL DRAWINGS
Objectives

The aims of this lab session are:


 To introduce the tools used for the construction of 3D solid models;
 To give examples of the construction of 3D solid models
 To give examples of constructions involving the Boolean operators – Union,
SubtractandIntersect.
3D DRAWINGS
Introduction:
The AutoCAD coordinate system includes a third coordinate direction Z, which, when dealing
with 2D drawing in previous chapters, has not been used. 3D model drawings make use of this
third Z coordinate. After the isometric drawing, now it is time to switch to the 3D drawing. This
section focus on the fundamental concepts of producing 3D drawings.It shows how to create 3D
drawing coordinates, (User Coordinate Systems), and how to change viewpoints to see the object
in 3D.
3D Modeling work space
It is possible to construct 3D model drawings in the AutoCAD Classic or 2D Drafting &
Annotation workspaces, but in this part we will be working in the 3D Modeling workspace.
To set this workspace click the Workspace Settings icon in the status bar and select 3D
Modeling from the menu which appears. The 3D Modeling workspace appears as in the

following figure.

202
Poly solid tool
1. Make sure layer 0 is current.
2.Click Top in the ViewCube( Fig. 12.5 ) or in the view tool. The screen switches to a Top
view.
3. Construct an octagon of edge length 60 using the Polygon tool.
4.Set layer 0 current and click the house icon in the ViewCube or SE isometric in the view
toolbar. The screen switches to an Isometric view.
5.Call the Polysolidtool with a click on its tool icon in the 3D Modeling panel. The command
line shows:
Command: _Polysolid
Height = 0, Width = 0, Justification = Center
Specify start point or [Object/Height/Width/Justify] <Object>:enter h (Height)
Specify height <4 >: 60
Height = 60, Width= 0, Justification = Center
Specify start point or [Object/Height/Width/Justify] <Object >:enter w (Width)
Specify width <0 >:5
Height= 60, Width = 5, Justification = Center
Specify start point or [Object/Height/Width/Justify] < Object >:
Specify next point or [Arc/Undo]: pick one cornerof octagon
Specify next point or [Arc/Undo]: pick secondcorner
Specify next point or [Arc/Close/Undo]: pick third

203
Specify next point or [Arc/Close/Undo]: pick fourth
Specify next point or [Arc/Close/Undo]: pick fifth
Specify next point or [Arc/Close/Undo]: pick sixth
Specify next point or [Arc/Close/Undo]: pick seventh
Specify next point or [Arc/Close/Undo]: pick last
Specify next point or [Arc/Close/Undo]: enter c (Close)
Command:
And the Polysolidforms as shown in the above figure.

2D outlines suitable for 3D models

When constructing as a basis for constructing some forms of 3D model, select a tool from the
Home/Draw panel, or enter tool names or abbreviations for the tools at the command line. If
constructed using tools such as Line,Circle and Ellipse, before being of any use for 3D modeling,
outlines must be changed into regions with the Region tool. Closed polylines can be used without
the need to use the Region tool.
Example 1 – Line outline and Region
1. Construct the left-hand drawing of Figure below using the Linetool.
2. Click the Region tool from the Home/Draw panel or from the draw toolbar, or enterregat the
command line.
Command: _region
Select objects: window the drawing 12 found
Select objects: right-click
1 Region created
Command:
And the Line outline is changed to a region – right-hand drawing of the figure below.

204
Example 2: Union,Subtractregions

1. In the Top view, construct drawing 1 of Fig. below and withthe Copy tool
(Home/Modifypanel), copy the drawing three times toproduce drawings 2,3 and 4.
2. With the Region tool change all the outlines into regions.
3. Drawing 2 – call the Union tool from the Home/Solid Editing panel. The command line
shows:

Command: _union
Select objects: pick the left-hand region 1 found
Select objects: pick the circular region 1 found,2 total
Select objects: pick the right-hand region 1found, 3 total
Command:
4. Drawing 3 – with the Solid, Union tool form a union of the left-handregion and the circular
region.
5. Drawing 4 – call the Subtract tool, also from the Home/Solid Editingpanel. The command
line shows:
Command: _subtract Select solids and regions to subtract from …
Select objects: pick the region just formed 1 found
Select objects: right-click
Select solids and regions to subtract: pick the right-hand region 1 found
Select objects: right-click
Command:

205
Example 3: Intersect and Region
1. Construct drawing 1 of Figbelow.
2. With the Region tool, change the three outlines into regions.
3. With the Copy tool, copy the three regions.
4. Drawing 2 – call the Intersect tool from the Home/3D Modelingpanel. The command line
shows:
Command: _intersect
Select objects: pick one of the circles 1 found
Select objects: pick the other circle 1 found, 2 total
Select objects: right-click
Command:
And the two circular regions intersect with each other to form a region.
5. Drawing 3 – repeat using the Intersect tool from the Home/SolidEditing panel on the
intersection of the two circles and the rectangularregion.

206
The Extrude tool

With EXTRUDE, you can create solids by extruding (adding thickness to) selected objects. You
can extrude closed objects such as polylines, polygons, rectangles, circles, ellipses, closed
splines, donuts, and regions. You cannot extrude 3D objects, objects contained within a block,
polylines that have crossing or intersecting segments or plotlines that are not closed. You can
extrude an object along a path, or you can specify a height value and a tapered angle.
Use EXTRUDES to create a solid from a common profile of an object, such as a gear or
sprocket. EXTRUDE is particularly useful for objects that contain fillets, chamfers, and other
details that might otherwise be difficult to reproduce except in a profile. If you create a profile
using lines or arcs, use the Join option of PEDITto convert them to a single polyline object or
make them into a region before you use EXTRUDE.
Tapering the extrusion is useful specifically for parts that need their sides defined along an angle,
such as a mold used to create metal products in a foundry. Avoid using extremely large tapered
angles. If the angle is too large, the profile can taper to a point before it reaches the specified
height.

The Extrudetool can be called with a clickon its tool icon in theHome/3D Modeling panel, from
the Modeling toolbar, from the Draw drop-down menu, or by enteringextrude or its abbreviation
ext at the command line.
Example 1: the use of extrude tool

207
From the first example of forming a region:
1. Call the Extrude tool. The command line shows:
Command: _extrude
Current wire frame density: ISOLINES = 4
Select objects to extrude: pick region 1 found
Select objects to extrude: right click
Specify height of extrusion or [Direction/Path/Taper angle] <45> :enter 50 right-
click
Command:
2. Select SE Isometric . The extrusion appears in an isometricview.
3. Call Zoom and zoom to 1.
N.B:Note the Current wire frame density: ISOLINES = 4 in theprompts sequence when
Extrude is called. The setting of 4 is suitablewhen extruding plines or regions consisting of
straight lines, butwhen arcs are being extruded it may be better to set ISOLINES to ahigher
figure as follows:
Command: - enter isolines right-click
Enter new value for ISOLINES <4>: enter 16 right-click
Command:
Example 2: From the second example of forming a region:
1. Set ISOLINES to 16.
2. Call the Extrude tool. The command line shows:
Command: _extrude
Current wire frame density: ISOLINES =16
Select objects to extrude: pick the region 1 found
Select objects to extrude: right-click
Specify height of extrusion or [Direction/Path/Taper angle]:
enter t right-click
Specify angle of taper for extrusion: enter 5right-click
Specify height of extrusion or [Direction/Path/Taper angle]: enter 100 right-click
Command:
3.Click on the SE isometric View.

208
4. Zoom to 1.
The result is shown in Figure above.
Example 3:From the third example of forming a region:

1. Place the screen in the Front view.


2. Construct a semicircular arc from the centre of the region.
3. Place the screen in the Top.
4. With the Move tool, move the arc to the centre of the region.
5. Place the screen in the SE Isometric view.
6. Set ISOLINES to 24.
7. Call the Extrude tool. The command line shows:
Command: _extrude
Current wire frame density: ISOLINES = 24
Select objects to extrude: pick the region 1found
Select objects to extrude: right-click
Specify height of extrusion or [Direction/Path/
Taper angle] < 100 >: enter p right-click
Select extrusion path or [Taper angle]: pick thepath
Command:
The result is shown in the above figure.

Revolve tool

With REVOLVE, you can create a solid by revolving a closed object about the X or Y axis of the
current UCS, using a specified angle. You can also revolve the object about a line, polyline, or
two specified points. Similar to EXTRUDE, REVOLVE is useful for objects that contain fillets
or other details that would otherwise be difficult to reproduce in a common profile. If you create
a profile using lines or arcs that meet a polyline, use the PEDIT Join option to convert them to a
single polyline object before you use REVOLVE.
You can use REVOLVE on closed objects such as polylines, polygons, rectangles, circles,
ellipses, and regions. You cannot use REVOLVE on 3D objects, objects contained within a
block, polylines that have crossing or intersecting segments, or polylines that are not closed.

209
TheRevolvetool can be called with a click on its tool icon in theModeling toolbar, by a click on
its tool icon in the Home/3D Modelingpanel, by a click on its name in the Modeling sub-menu
of the Drawdrop-down menu, or by entering revolve at the command line, or itsabbreviation rev
.

Example 1:The use of revolve


1. Construct the closed polyline shown below.

2.Set ISOLINES to 24.


3.Call the Revolve tool from the Home/3D Modeling control panel. The command line shows:
Command: _revolve
Current wire frame density: ISOLINES = 24
Select objects to revolve: pick the polyline 1 found
Select objects to revolve: right-click
Specify axis start point or define axis by [Object/X/Y/Z] < Object >: pick
Specify axis endpoint: pick
Specify angle of revolution or [Start angle]<360>: right-click
Command:
4. Place in the SEIsometric view. Zoom to 1.
The result is shown in the figure.

Example 2:

210
1. Construct the pline (left-hand drawing of the figure belo ). The drawingmust be either a
closed pline or a region.
2. Call Revolve and form a solid of revolution through 180 °.
3. Place the model in the SE Isometric view. Zoom to 1.
The result is shown in the right-hand side of Figure below.

Box tool
You can use BOXto create a solid box. The base of the box is always parallel to the XY plane of
the current UCS.
The RECTANGor PLINEcommand creates a rectangle or closed polyline from which you can
create a box using EXTRUDE. The 3D command creates a box shape defined by surfaces only.
Example:
1. Place the window in the Front view.
2.Click the Box tool icon in the Home/3D Modelingpanel .The command line shows:
Command: _box
Specify first corner or [Center]: 90,90 enterright-click
Specify other corner or [Cube/Length]: enter110, – 30 right-click
Specify height or [2Point]: enter 75 right-click

211
Command: right-click
BOX Specify first corner or [Center]: 110, 90 right-click
Specify other corner or [Cube/Length]: 170, 70right-click
Specify height or [2Point]: 75right-click
Command: right click
BOX Specify first corner or [Center]: 110,–10
Specify other corner or [Cube/Length]: 200,–30
Specify height or [2Point]: 75
Command:
3. Place in the SEIsometric view. Zoom to 1.
4. Call the Union tool from the Home / Solid Editing panel.
The commandline shows:
Command: _union
Select objects: pick one of the boxes 1 found
Select objects: pick the second of box 1 found, 2 total
Select objects: pick the third box 1 found, 3 total
Select objects: right-click
Command:
And the three boxes are joined in a single union as shown in the figure.

Cone tool

You can use CONE to create a solid cone defined by a circular or an elliptical base tapering to a
point perpendicular to its base. By default, the cone's base lies on the XY plane of the current
UCS. The height, which can be positive or negative, is parallel to the Z axis. The apex
determines the height and orientation of the cone.
To create a truncated cone or a cone that requires a specific angle to define its sides, draw a 2D
circle and then use EXTRUDE to taper the circle at an angle along the Z axis. To complete the
truncation, you can subtract a box from the tip of the cone with the SUBTRACT command.
CIRCLE creates a circle from which you can create a cone using EXTRUDE with its Taper
option. The 3D command creates a conical shape defined by surfaces only.

212
Cylinder tool
You can use CYLINDER to create a solid cylinder with a circular or an elliptical base. The base
of the cylinder lies on the XY plane of the current UCS.
If you want to construct a cylinder with special detail, such as grooves along its sides, create a
2D profile of its base with a closed PLINE and use EXTRUDE to define its height along the Z
axis. CIRCLE creates a circle from which you can create a cylinder using EXTRUDE.

Sphere Tool
You can use SPHERE to create a solid sphere based on a center point and a radius or diameter.
Its latitudinal lines are parallel to the XY plane, and the central axis is coincident with the Z axis
of the current UCS.
To create a dome or dish, combine a sphere with a box and use SUBTRACT. If you want to
create a spherical object that has additional detail, create 2D profile and use REVOLVE to define
a rotation angle about the Z axis. The 3D command creates a spherical shape defined by surfaces
only.

Torus tool

You can use TORUS to create a ring-shaped solid similar to the inner tube of a tire. The torus is
parallel to and bisected by the XY plane of the current UCS.
To create a lemon-shaped solid, use a negative torus radius and a positive number of greater
magnitude for the tube radius. For example, if the torus radius is -2.0, the tube radius must be
greater than 2.0.
A torus may be self-intersecting. A self-intersecting torus has no center hole because the radius
of the tube is greater than the radius of the torus. The 3D command creates a toroidal shape
defined by surfaces only.

Wedge tool

You can use WEDGE to create a solid wedge. The base of the wedge is parallel to the XY plane
of the current UCS with the sloped face opposite the first corner. Its height, which can be

213
positive or negative, is parallel to the Z axis. The 3D command creates a wedge shape defined by
surfaces only.

Example:Sphere and Cylinder

1. Set ISOLINESto 16.


2. Click the Sphere tool icon from the Home/3D modelingpanel. Thecommand line shows:
Command: _sphere
Specify center point or [3P/2P/Ttr]: 180,170
Specify radius or [Diameter]: 50
Command:
3. Click the Cylinder tool icon in the Home/3D modelingpanel. Thecommand line shows:
Command: _cylinder
Specify center point of base or [3P/2P/Ttr/Elliptical]: 180,170
Specify base radius or [Diameter]: 25
Specify height or [2Point/Axis endpoint]: 110
Command:
4. Place the screen in the Front view. Zoom to 1.
5. With the Move tool (from the Home/Modifypanel), move the cylindervertically down so that
the bottom of the cylinder is at the bottom of thesphere.
6. Click the Subtract tool icon in the Home/Solid Editingpanel. Thecommand line shows:
Command: _subtract
Select solids and regions to subtract from...
Select objects: pick the sphere 1 found
Select objects: right-click
Select solids and regions to subtract
Select objects: pick the cylinder 1 found
Select objects: right-click
Command:
7. Place the screen in the SE Isometric view. Zoom to 1.
The result is shown in the above figure.

214
Example: Cylinder, Cone andSphere

1. Call the Cylinder tool and with a centre 170,150 construct a cylinderof radius 60 and height
15 .

2. Click the Cone tool in the Home/3D Modelingpanel. The commandline shows:
Command: _cone
Specify center point of base or [3P/2P/Ttr/Elliptical]: 170,150
Specify base radius or [Diameter]: 40
Specify height or [2Point/Axis endpoint/Topradius]: 150
Command:
3. Call the Sphere tool and construct a sphere of centre170,150 andradius 45 .

4. Place the screen in the Front view and with the Move tool, move thecone and sphere so that
the cone is resting on the cylinder and thecentre of the sphere is at the apex of the cone.

5. Place in the SE Isometric view, Zoom to 1 and with Unionform a single 3D model from the
three objects.

The result is shown in the following figure.

Example:Box and Wedge

215
1. Click the Box tool icon in the Home/3D modelingpanel and constructtwo boxes, the first from
corners 70,210 and 290,120 of height 10, thesecond of corners 120, 200, 10and 240, 120, 10and
of height 80.
2. Place the screen in the Front view and Zoom to 1.
3. Click the Wedge tool icon in the Home/3D modelingpanel. Thecommand line shows:
Command: _wedge
Specify first corner or [Center]: 120,170,10
Specify other corner or [Cube/Length]: 80,160,10
Specify height or [2Point]: 70
Command: right-click
WEDGESpecify first corner of wedge or [Center]:240, 170, 10
Specify corner or [Cube/Length]: 280, 160, 10
Specify height or [2Point]: 70
Command:
4. Place the screen in the SE Isometric view and Zoom to 1.
5. Call the Union tool from the Home/Solid Editing panel and inresponse to the prompts in
the tool’s sequences pick each of the 4objects in turn to form a union of the 4 objects.

The result is shown in the above figure.

Example:Cylinder and Torus

1. Using the Cylinder tool from the Home/3D modelingpanel, constructa cylinder of
centre180,160 , of radius 40 and height 120 .
2. Click the Torus tool icon in the Home/3D modelingpanel. Thecommand line shows:
Command: _torus
Specify center point or [3P/2P/Ttr]: 180, 160,10
Specify radius or [Diameter]: 40
Specify tube radius or [2Point/Diameter]: 10
Command: right-click
TORUSSpecify center point or [3P/2P/Ttr]: 180,160,110
Specify radius or [Diameter] < 40 >: right-click
Specify tube radius or [2Point/Diameter] <10 >: right-click

216
Command:
3. Call the Cylinder tool and construct another cylinder of centre180,160, of radius 35 and
height 120.
4. Place in the SE Isometric view and Zoom to 1.
5. Click the Union tool icon in the Home/Solid Editingpanel and form aunion of the larger
cylinder and the two tori.
6. Click the Subtract tool icon in the Home/Solid Editing panel andsubtract the smaller cylinder
from the union.

The result is shown in the above figure.

Sweep tool

With the SWEEP command, you can create a new solid or surface by sweeping an open or
closed planar curve (profile) along an open or closed 2D or 3D path. SWEEP draws a solid or
surface in the shape of the specified profile along the specified path. You can sweep more than
one object, but they all must lie on the same plane.To call the tool click on its tool icon in the
Home/3D Modelingpanel
Example – Sweep
1. Construct the pline outline ( Fig. A) in the Top view.
2. Change to the Front view, Zoom to 1 and construct a pline as shown in Fig. B as a path
central to the ellipse.
3. Place the window in a SE Isometric view and click the Sweep tool icon. The command
line shows:
Command: _sweep
Current wire frame density: ISOLINES = 4
Select objects to sweep: pick the ellipse 1 found
Select objects to sweep: right-click
Select sweep path or [Alignment/Base point/Scale/Twist]: pick the pline
Command:
The result is shown in Fig. C.

217
Fig A Fig B Fig C

Loft tool

With the LOFT command, you can create a new solid or surface by specifying a series of cross
sections. The cross sections define the profile (shape) of the resulting solid or surface. Cross
sections (generally, curves or lines) can be open (for example, an arc) or closed (for example, a
circle). LOFT draws a solid or surface in the space between the cross sections. You must specify
at least two cross sections when you use the LOFT command.
To call the tool, clickon its icon in the Home/3D modeling panel.

Example:Loft

1. Construct the seven circles shown in Fig. D at vertical distances of30 units apart.

2. Place the drawing area in the SE Isometric view.

3. Call the Loft tool with a click on its tool icon in the Home/3Dmodeling panel

4. The command line shows:

Command: _loft

Select cross-sections in lofting order: <Snapoff >pick the bottom circle 1 found

218
Select cross-sections in lofting order: pick the next circle 1 found, 2 total

Select cross-sections in lofting order: pick the next circle 1 found, 3 total

Select cross-sections in lofting order: pick the next circle 1 found, 4 total

Select cross-sections in lofting order: pick the next circle 1 found, 5 total

Select cross-sections in lofting order: pick the next circle 1 found, 6 total

Select cross-sections in lofting order: pick the next circle 1 found, 7 total

Select cross-sections in lofting order: right-click

And the Loft Settings dialog appears as follows.

5.Click the Smooth Fit radio button to make it active, followed by a clickon the OK button. The
loft appears.

The result is shown in Fig. E below.

219
Fig. D Fig. E

LAB EXERCISE 7

#1.Figure 1A below shows the pline outline fromwhich the polysolid outline of Fig. 1B hasbeen
constructed to a height of 100 andWidth of 3 . When the polysolid has beenconstructed,
construct extrusions can thenbe subtracted from the polysolid. Sizes of theextrusions are left to

220
your judgment.

Fig. 1A Fig. 1B

#2Thefigure below shows a 3D model constructedfrom four polysolids which have been
formedinto a union using the Union tool from theModify panel. The original polysolid
wasformed from a hexagon of edge length 30. The original polysolid was of height 40 andWidth
5. Construct the union.

221
# 3Figure below shows the 3D model fromExercise 2 acted upon by the Press pull tool,which
can be called by entering Respell atthe command line. With the 3D model fromExercise 2 on
screen and using the Press pulltool, construct the 3D model shown inbelow. The distance of the
pull can beestimated.

# 4Figure below shows the outline from whicha solid of revolution can be constructed.Use the
Revolve tool from the Home/3Dmodeling panel to construct the solid ofrevolution.

222
# 5Working to the dimensions given in fig below, construct an extrusion of the plate to a
heightof 5 units.

#6Construct a 3D solid model of a bracketworking to the information given in the following fig.

223
#7Working to the polylines shown in Fig.7Aconstruct the Sweep shown in Fig. 7B.

Fig. 7A

Fig. 7B

#8Construct the cross-sections as shown in Fig.8A working to suitable dimensions. Fromthe


cross-sections construct the lofts shown inFig. 8B. The lofts are topped with a sphereconstructed
using the Sphere tool.

224
Fig. 8A Fig. 8B

Lab Session 8

VIEW PORTS AND BLOCKS

225
Objectives

The aims of this Lab session are:


 To give examples of 3D solid models constructed in multiple viewport settings.
 To demonstrate how 3D models can be saved as blocks for insertion into other drawings
viathe DesignCenter ;
 To show how a library of 3D models in the form of blocks can be constructed to enable
themodels to be inserted into other drawings;

8.1 VIEW PORTS


One of the better methods of constructing 3D models is in differentmultiple viewports. This
allows what is being constructed to be seen froma variety of viewing positions.

Setting up view port systems

Set up multiple viewports as follows:

1. Click New in the View/Viewports panel or from the menu bar click View →
Viewports→ New. The Viewports dialog appears as shown below.

In the dialog:

226
2. Click the New Viewports tab and a number of named viewports systems appear in the
Standard Viewports list in the dialog.
3. Click the name Four: Equal, followed by a click on 3D in the Setup pop-up list. A
preview of the Four: Equal viewports screen appears showing the views appearing in
each of the four viewports.
4. Click in each viewport in the dialog in turn, followed by selecting Conceptual from the
Visual Style pop-up list.
5. Click the OK button of the dialog and the AutoCAD 2009 drawing area appears showing
the four viewport layout.
6. Click in each viewport in turn and Zoom to All.

The result is shown in Figure below.

Example 1:Four: Equal viewports


Figure 8.1 shows a first angle orthographic projection of a support. Toconstruct a Scale 1:1 3D
model of the support in a Four: Equal viewportsetting, proceed as follows:
1.Click View in the View/Viewports panel. In the Viewports dialogmake sure the 3D option is
selected from the Setup pop-up list andConceptual from the Visual Style pop-up menu and
click the OKbutton of the dialog. The AutoCAD 2009 drawing area appears in aFour: Equal
viewport setting.

227
2.Click in each viewport in turn, making the selected viewport active, andZoom to 1.
3.Using the Polyline tool, construct the outline of the plan view of theplate of the support,
including the holes in the Top viewport (Fig. 8.2).Note the views in the other viewports.
4.Call the Extrude tool from the Home/3D modelingpanel and extrudethe plan outline and the
circles to a height of 20.
5.With Subtract from the Home/Solids Editing panel, subtract the holesfrom the plate (Fig.
8.3).
6.Call the Box tool & in the centre of the plate construct a box ofWidth=60, Length=60 and
Height =30.
7.Call the Cylinder tool and in the centre of the box construct a cylinderof Radius=20 and of
Height=30.

Fig 8.1

228
Fig 8.2

8. Call Subtract and subtract the cylinder from the box.


9. Click in the Right viewport, and, with the Move tool, move the boxand its hole into the
correct position with regard to the plate.
10. With Union, form a union of the plate and box.
11. Click in the Front viewport and construct a triangle of one of the websattached between the
plate and the box. With Extrude, extrude thetriangle to a height of 10. With the Mirror tool,
mirror the web to theother side of the box.

229
Fig 8.3

12. Click in the Right viewport and with the Move tool, move the twowebs into their correct
position between the box and plate. Then, withUnion, form a union between the webs and the
3D model.

13. In the Right viewport, construct the other two webs and in the Frontviewport, move, mirror
and union the webs as in steps 12 and 13.

Figure 8.4 shows the resulting 4-viewport scene.

230
Fig 8.4

Example 2: Four: Left viewports

1. Open the Four: Left viewport layout from the Viewports dialog.
2. Make a new layer of color magenta and make that layer current.
3. In the Top viewport construct an outline of the web of the SupportBracket shown in Fig. 8.5. With the
Extrude tool, extrude the partsof the web to a height of 20.

Fig 8.5

231
4. With the Subtract tool, subtract the holes from the web.
5. In the Top viewport, construct two cylinders central to the extrusion,one of radius 50 and
height 30, the second of radius 40 and height 30.With the Subtract tool, subtract the smaller
cylinder from thelarger.
6.Click in the Front viewport and move the cylinders verticallyby 5 units. With Union form a
union between the cylinders andthe web.
7. Still in the Front viewport and at one end of the union, construct two cylinders, the first of
radius 10 and height 80, the second of radius 15and height 80. Subtract the smaller from the
larger.
8. With the Mirror tool, mirror the cylinders to the other end ofthe union.
9. Make the Top viewport current and with the Move tool, move thecylinders to their correct
position at the ends of the union. Form aunion between all parts on screen.
10. Make the Isometric viewport current. From the Home/View panelselect Realistic.

Figure 8.6below shows the result.

232
Fig 8.6
Example 3: Three: Right viewports
1. Open the Three: Right viewport layout from the Viewports dialog.Make sure the 3D setup is
chosen.
2. Make a new layer of color Green and make that layer current.
3. In the Front viewport (top left), construct a pline outline to thedimensions in Fig. 8.7.
4. Call the Revolve tool from the Home/3D modeling panel and revolvethe outline through 360
°.
5. In each of the three viewports in the Home/View panel selectConceptual from its pop-up list.

The result is shown in Fig. 8.8 below.

233
Fig 8.7

Fig 8.8
8.2 Creating 3D Model Libraries

In the same way as 2D drawings of parts such as electronics symbols,engineering parts, building
symbols and the like can be saved in a file asblocks and then opened into another drawing by
dragging the appropriateblock drawing from the Design Center, so can 3D models.

Example 1: Inserting 3D blocks

234
1.Construct 3D models of the parts for a lathe milling wheel holder todetails as given in Fig. 8.9,
each on a layer of different colors.
2.Save each of the 3D models of the parts to file names as given inFig. 14.1 as blocks using
Create from the Blocks & Reference/Blockpanel. Save all seven blocks and delete the drawings
on screen. Savethe drawing with its blocks to a suitable file name (e.gFig01.dwg).

Fig 8.9.The components of a lathe milling wheel holder


3. Set up a Four: Equal viewports setting.
4. Open the DesignCenter with a click on its icon in the Standardtoolbar (Fig. 8.10 ), or by
pressing the Ctrl and 2 keys of the keyboard.

235
Fig 8.10

5.In the Design Centerclick the directory Lab 8(the directory that you saved your files for this
lab), followed by another click on Fig01.dwgand yet another click on Blocks. The saved blocks
appear as icons in the right-hand area of the DesignCenter.
6.Drag and drop the blocks one by one into one of the viewports on screen. Figure 8.11 shows
the Nut block ready to be dragged into the Right viewport. As the blocks are dropped on screen,
they will needmoving into their correct positions in suitable viewports using the Move tool from
the Home/Modify panel.

Fig 8.11

7. Using the Move tool, move the individual 3D models into their final places on screen and
shade the Isometric viewport using Conceptual shading from the Home/View panel
(Fig. 8.12).

236
Fig
8.12

Note:

1. It does not matter which of the four viewports any one of the blocksis dragged and dropped
into. The part automatically assumes theview of the viewport.

2. If a block destined for layer 0 is dragged and dropped into the layerCenter (which in our
acadiso.dwtis of colourred and of linetypeCENTER2 ), the block will take on the colour (red)
and linetype ofthat layer ( CENTER2 ).

3. In this example, the blocks are 3D models and there is no need touse the Explode tool option.

237
Example 2: A library of fastenings

1. Construct 3D models of a number of engineering fastenings. Thenumber constructed does not


matter. In this example only five havebeen constructed – a 10 mm round head rivet, a 20 mm
countersunkhead rivet, a cheese head bolt, a countersunk head bolt and a hexagonalhead bolt
together with its nut ( Fig. 8.13 ). With the Create tool saveeach separately as a block, erase the
original drawings and save the file to a suitable file name – in this example Fig05.dwg.

2. Open the DesignCenter,click on the Chapter 14 directory, followedby a click on Fig05.dwg.


Then click again on Blocks in the content listof Fig05.dwg. The five 3D models of fastenings
appear as icons in theright-hand side of the DesignCenter (Fig. 8.14).

3. Such blocks of 3D models can be dragged and dropped into position inany engineering
drawing where the fastenings are to be included.

Fig 8.13 The five fastenings

Fig 8.14.A library of fastenings

238
LAB EXERCISE 8

#1A two-view orthographic projection of arotatable lever from a machine is given in Fig. 1A, together
with an isometric drawing ofthe 3D model constructed to the details givenin the drawing of Fig.
1B.Construct the3D model drawing in a Four: Equalviewportsetting.

Fig. 1A Fig. 1B

239
# 2Working in a Three: Left viewport setting, construct a 3D model of the faceplate to the
dimensions given in Fig. 2A. With the Mirror tool, mirror the model to obtain an opposite
facing model. In the Isometric viewport call the Hide tool (Fig. 2B).

Fig. 2A Fig. 2B

240
Lab session 9

SOLID EDITING TOOLS


Objectives

The aims of this lab session are:-

 To give examples of the use of the tools from the Home/Solid Editing panel:
 3D Array – Rectangular &Polar 3D arrays
 3D Mirror
 3D Rotate
 To give examples of the use of the Section tool from the Home/Solid Editing panel;
 To give examples of the use of the Helix tool;

9.13D Array Tool

Example1:A Rectangular Array


1. Construct the star-shaped pline on a layer color green (Fig. 9.1) andextrude it to a height
of 20 .

241
Fig 9.1 Fig 9.2

2. Click on the 3D Array icon in the Modify/3D Operations menu (Fig. 9.2). The
command line shows:
Command: _3darray
Select objects: pick the extrusion 1 found
Select objects: right-click
Enter the type of array [Rectangular/Polar]< R >:right-click
Enter the number of rows (—) <1 >:enter 3 right-click
Enter the number of columns (III): enter 3 right-click
Enter the number of levels (...): enter 4 right-click
Specify the distance between rows (—): enter 100 right-click
Specify the distance between columns (III): enter 100 right-click
Specify the distance between levels (...): enter 300 right-click
Command:
3. Place the screen in theIsometric view.

4. Shade using the Home/View/Conceptual visual style. The resulting figure is shown above.

242
Example 2: APolar Array

1. Use the same star-shaped 3D model.

2. Call the 3D Array tool again. The command line shows:

Command: _3darray

Select objects: pick the extrusion 1 found

Select objects: right-click

Enter the type of array [Rectangular/Polar]<R >: enter p (Polar) right-click

Enter number of items in the array: 12

Specify the angle to fill (+ = ccw), - =cw)< 360 >: right-click

Rotate arrayed objects? [Yes/No] < Y >:right-click

Specify center point of array: 235,125

Specify second point on axis of rotation:300,200

Command:

3. Place the screen in the ViewCube/Isometric


view.
4. Shade using the Home/View/Conceptual visual
style (Fig. below).

9.23DMirror Tool

Example:3D Mirror

243
1. Working on a layer color green, construct the outline in Fig. 9.3.

2. Extrude the outline to a height of 20.

3. Extrude the region to a height of 5 and render. Conceptualstyle


shading is shown in Fig. 9.4 (left-hand drawing).

4. Click on 3D Mirror in the 3D Operation sub-menu of the

Modify drop-down menu. The command line shows:

Command: _3dmirror

Select objects: pick the extrusion 1 found

Select objects: right-click

Specify first point of mirror plane(3 points): pick

Specify second point on mirror plane: pick

Specify third point on mirror plane


or[Object/Last/Zaxis/View/XY/YZ/ZX/3points]:enter .xy
right-click

of (need Z): enter 1 right-click

Delete source objects? [Yes/No] : <N >:right-click

Command:

The result is shown in the right-hand illustration of Fig. 9.4

244
Fig 9.4

Example 2: 3D Mirror
1.Construct a solid of revolution in the shape of a bowl in the Front view working on a layer of
color yellow (Fig. 9.5).
2.Click 3D Mirror in the Modify/3D Operations drop-down menu. The command line shows:
Command: _3dmirror
Select objects: pick the bowl 1 found
Select objects: right-click
Specify first point on mirror plane (3 points): pick
Specify second point on mirror plane: pick
Specify third point on mirror plane: enter .xy right-click (need Z): enter 1 right-click
Delete source objects? : [Yes/No] : < N >: right-click
Command:
The result is shown in Fig. 9.6.
3. Place in the Isometric view.
4.Shade using the Home/View/Conceptual visual style (Fig. 9.6).

245
Fig. 9.5The3D model Fig 9.6 3D Mirror – the result in a Isometric view

9.3 3D Rotate Tool

Example 1: 3D Rotate

1.Use the same 3D model of a bowl as for the last example. Call the 3DRotatetool from the 3D
Operations sub-menu of the Modify dropdownmenu. The command line shows:
Command: pick 3D Rotate from the Modify drop-down menu
3DROTATE

Current positive angle in UCS: ANGDIR = counterclockwise ANGBASE = 0

Select objects: pick the bowl 1 found

Select objects: right-click

Specify base point: pick the center bottom of the bowl

Specify rotation angle or [Copy/Reference] < 0 >: enter 60 right-click

Command:

3. Place in the Isometric view and in Conceptual shading. The result is shown in the above
figure.

246
9.4 Slice Tool
Example:Slice
1.Construct a 3D model of the rod link device shown in the two-view projection in Fig. 9.7 on a layer color
green.

Fig 9.7

2.Place the 3D model in the Top view.


3.Call the Slice tool from the Home/Solid Editing panel (Fig. 9.8).The command line shows:

Fig 9.8
Command: _slice
Select objects: pick the 3D model
Select objects to slice: right-click
Specify start point of slicing plane or
[planarObject/Surface/Zaxis/View/XY/YZ/ZX/3points]<3points >: pick
Specify second point on plane: pick
Specify a point on desired side or [keep Bothsides] < Both >:right-click
Command:

247
Figure 9.9 shows the picked points.

Fig 9.9

4. With the Move tool, move the lower half of the sliced model away fromthe upper half.

5. Place the 3D model(s) in the Isometric view.

6. Shade in Conceptual visual style. The result is shown in Fig. 8.10 below.

Fig 9.10

9.5SECTION TOOL

Example: Section

1. Construct a 3D model to the information given in Fig. 14.27 on layersof different colors. Note
there are three objects in the model - a box,a lid and a cap.

248
Fig 9.11

2. Place the model in the Top view.

3. Make a new layer Hatch of color Red.

4. Click the Section Plane tool icon in the Home/3D Modeling panel(Fig. 9.12). The command
line shows:

Fig 9.12The Section Plane tool in the Home/Solid Editing panel

Command: _section
Select objects: window the model 3 found
Select objects: right-click
Select first point on Section plane by [Object/Zaxis/View/XY/YZ/ZX/3points _ 3points _
:pick first point
Specify second point on plane: pick first point

249
Specify third point on plane: enter .xy right-click
of (need Z): enter 1 right-click
Command:
5. Place the drawing in the Front view.
6. Close all layers except Hatch.
7. Shade in realistic mode.

The result is shown in Fig. 9.13.

Fig 9.13

9.6 Helix Tool

The Helix tool can be called with a click on its tool icon in the extension ofthe Home/3D
Modelingpanel (fig 9.14)
Example:Helix
1. Construct the triangular outline shown in Fig. 9.15(left side) using the Polylinetool. Make sure
the pline outline is placed at right angles to the bottomend of the helix as shown in Fig.
9.15(right side). This may mean moving and rotating the outline in a selection of the ViewCube
views.

Fig 9.14 Fig 9.15

2. Make a new layer of color Cyan and make it current.

250
3. Call the Helix tool from the Home/3D Modeling panel (Fig. 9.14) orfrom the Modeling
toolbar. The command line shows:

Command: _Helix

Number of turns =3 Twist = CCW

Specify center point of base: enter 160,160 right-click

Specify base radius or [Diameter] < 1 >: pick 160,200

Specify top radius or [Diameter] < 1 >: enter 40 right-click

Specify helix height or [Axis endpoint/Turns/turnHeight/tWist] < 1 >: enter t (Turns)


right-click

Enter number of turns <3 >: enter 10 right-click

Specify helix height or [Axis endpoint/Turns/turnHeight/tWist] < 1 >: enter 100 right-
click

Command:

4. Call the Extrude tool form the 3D Modeling panel and extrude theoutline along the path of
the helix. The command line shows:

Command: _extrude

Current wire frame density: ISOLINES = 4

Select objects to extrude: pick the outline 1 found

Select objects to extrude: right-click

Specify height of extrusion or [Direction/Path/Taper angle]: enter p (path) right-click

Select extrusion path or [Taper angle]: pick the helix

Command:

The result is shown in Fig. 9.16.

5. Add three cylinders, one to fi t inside the helix, the second to form theshank of the screw, the
third for the head of the screw. Subtract a boxfrom the head for the screw slot. Then union the
four parts of the screw.
6. Shade the screw using the Conceptual visual style.

251
The result is shown in Fig. 9.17.

Fig 9.16 Fig 9.17

LAB EXERCISE 9
#1Construct a 3D model drawing of theseparating link shown in the two-viewprojection (figure
below). With the Slice tool,slice the model into two parts and remove therear part. Place the front
half in an isometric view using the View Cube. Shade the resultingmodel.

252
# 2Working to the dimensions given in the two orthographic projections (Fig.2A), andworking
on two layers of different colors,construct an assembled 3D model of theone part inside the
other. With the Slice tool,slice the resulting 3D model into two equalparts, place in an isometric
view and call theHide tool as indicated in Fig.2B. Shade theresulting model in Realistic mode.

253
Fig. 2A

254
Fig. 2B

255
Lab Session 10

3D MODELING TEMPLATE RENDERING AND LIGHT EFFECTS

Objectives

The aims of this Lab session are:


 To construct a template for 3D modelling to be used as the drawing window for further
work in 3D in this lab;
 To introduce the use of the Render tools in producing photographic-like images of 3D
solid models;
 To show how to illuminate a 3D solid model to obtain good lighting effects when
rendering;
 To give examples of the rendering of 3D solid models;

10.1 Setting Up a New 3D Template

In this lab session we will be constructing all 3D model drawings in theacadiso3D.dwttemplate.

1. Click the Workspace Switching button and click 3D Modeling fromthe menu which appears
(Fig. 10.1).

2. The AutoCAD window (Fig. 10.2) appears.

256
Fig 10.1 Fig 10.2The 3D modeling work space

3. In the Command palette enter:

Command: enter perspective < 1 > : enter 0

Command:

4. Open the Options dialog with a right-click in the Command palette,followed by a click on
Options … in the menu which appears.

257
5. Click the Colors tab. The Drawing Window Colors dialog appears. Set Uniform Background
color to White (Fig.10.3).

Fig 10.3In the Options dialog set all background colors to White

6. Set Units to a Precision of 0, Snap to 5 and Grid to 10. Set Limits to420,29. Zoom to All .

7. In the Options dialog click the Files label and click Default TemplateFile Name for QNEW (
Fig. 10.4 ) followed by a click on the Browsebutton which brings up the Select Template dialog,
from which theacadiso3d.dwt can be selected. Now when AutoCAD is openedfrom the desktop,
the acadiso3D.dwt template will open.

8. Set up 5 layers of different colors. In my template these have beennamed after the colors
( Fig. 10.5 ).

9. Save the template to the name acadiso3D and then enter a suitabledescription in the Template
Definition dialog.

258
Fig 10.4 Setting the default template setting in the Options dialog

Fig 10.5 Set up five new layers

10.2 Pallets

259
Click the Tool Palettesicon in the View/Palettes panel (Fig. 10.6). TheTool Palettes – All
Palettespalette appears docked at the right-hand edgeof the AutoCAD window. Drag the palette
away from its docked position.

Fig 10.6Tool Palettes icon

Right-click in the title bar of the palette and a right-click menu appears(Fig. 10.7). In Fig. 10.7
the Draw palette is showing.

Fig 10.7The Tool Palettes – All Palettes palette with its right-click menu

260
To choose the tool palette required for the work in hand, either click onthe name of the required
palette in the tabs at the right-hand side of AllPalettes palette or, if the required name is not
showing, select the palettename from the right-click menu appearing with a right-click in the
bottomleft-hand corner of the All Palettes palette (Fig. 10.8).

The All Palettes palette can be docked against the side of the AutoCADwindow if needed.

Fig 10.8The right-click menu from the All Palettes palette

261
Applying materials
Materials can be applied to a 3D model directly from icons in a selectedpalette. Three examples
follow – applying a masonry material, applying awood material and applying a metal material.
Examples of applying materials:
In the two examples which follow, lighting effects are obtained by turning Sun Status on, by
clicking the Sun Status icon in the Visualize/Sun panel (Fig. 10.9). The Lighting – Viewport
Lighting Mode dialog appears (Fig. 10.10). Click Turn off the default lighting
(recommended).

Fig 10.9The Sun Status icon in the Visualize / Sun panel

Fig 10.10The Lighting – Viewport Lighting Mode dialog


When the material has been applied, click the Render icon in the Output/Render panel (Fig.
10.11) and the model will render.

262
Fig 10.11The Render icon from the Output / Render panel
Example 1:applying a masonry material

Construct the necessary 3D model. In the All Palettes palette click the tablabelled Masonry –
Materials Sample. Right-click on the icon representingthe material to be applied to the model
and from the menu which appears,click Apply Materials To Objects. A small icon similar to a
paint brushappears with a small square. Move the square until it is on part of the modelto which
the material is to be applied and left-click, followed by a right-click.

Then render the model. Figure 10.12 shows the resulting rendering.

Fig 10.12Applying a masonry material

263
Example2: applying a metal material

Construct the necessary 3D model. From the All Palettes palette clickthe tab labelled Metals –
Materials Sample. Right-click on the iconrepresenting the material to be applied to the model
and from the menuwhich appears, click Apply Materials To Objects. Left-click the model tobe
rendered, followed by a right-click and render the model. The renderingis shown in Fig. 10.13.

Fig 10.13applying a metal material

Render tools and dialogs

The tool icons and menus in the Output/Render panel are shown in Fig. 10.14.

Fig. 10.14The tools and menus in the Output / Render panel

264
The LIGHTS tools
The different forms of lighting from light palettes are shown in Fig. 10.15 .There are many forms
of lighting available when using AutoCAD; the most frequently used include the following:
 Ambient lighting is taken as the general overall light that is all around and surrounding
any object. Usually left at 30%.
 Point lights shed light in all directions from the position in which the light is placed.
 Distant lights send parallel rays of light from their position in the direction chosen by the
operator.
 Spotlights illuminate as if from a spotlight. The light is in a direction set by the operator
and is in the form of a cone, with a ‘ hotspot ’ cone giving a brighter spot on the model
being lit.
 Photometric lighting is lighting in which lights of a selected wattage can be placed in a
lighting scene. The set variable LIGHTINGUNITS must be set to 1 or 2 for photometric
lights to function.
 Viewport lighting mode in Default lighting or User light/sunlight. Sun light, which
can be edited.
 Sky background and illumination.
Other forms of lighting are shown in Fig. 10.15. In this book, examples of lighting methods
shown in examples will only be concerned with the use of Point and Direct lights, together with
Default lighting.

265
Fig 10.15The Lights tools palettes

LAB EXERCISE 10

# 1Figure 1A is a rendering of a drip tray.Working to the sizes given in Fig. 1B ,construct a 3D


model drawing of the tray.Add lighting and a suitable material, place themodel in an isometric
view and render.

Fig. 1A

266
Fig.
1B

# 2 Construct the 3D model of the two parts of stand and support projection given in Fig 2A.Add
different materials to the parts of the assembly as shown in Fig 2B and render theresult.

267
Fig 2A

Fig 2B

268
Lab session 11

SOLID EDITING TOOLS

Objectives

The aims of this lab session are:

To introduce the use of tools from the Solid Editing panel;
To show examples of a variety of 3D solid models;

SOLID EDITING TOOLS

The Solid Editing tools can be called from the Home/Solid Editing panel or from the Solid
Editing toolbar.Examples of the results of using some of the Solid Editing tools are shown in
this lab session. These tools are of value if the design of a 3D solid model needs to be changed
(edited), although some are useful for constructing parts of 3D solids which cannot easily be
constructed using other tools.

Example 1 – Extrude faces tool


1.Set Isolinesto 24.
2.In the View Cube / Rightconstruct a cylinder of radius 30 and height 30 (Fig. 11.1).
3.In the View Cube / Frontconstruct the pline shown in Fig. 11.1. Mirror the pline to the other
end of the cylinder.

Fig 11.1

4. In the ViewCube / Top move the pline to lie central to the cylinder.

269
5. Place the screen in the Isometricview.

6. Click the Extrude faces tool icon in the Home / Solid Editing panel. The command line
shows:

Command: _solidedit
Solids editing automatic checking: SOLIDCHECK = 1
Enter a solids editing option [Face/Edge/Body/Undo/eXit] <eXit>: _face
Enter a face editing option
[Extrude/Move/Rotate/Offset/Taper/Delete/Copy/coLor/mAterial/Undo/eXit] <eXit>:
_extrude
Select faces or [Undo/Remove]: 2 faces found.
Select faces or [Undo/Remove/ALL]: enter r right-click
Remove faces or [Undo/Add/ALL]: pick 1 face found,1 removed.
Specify height of extrusion or [Path]: enter pright-click
Select extrusion path: pick the path pline
Solid validation started.
Solid validation completed.
Enter a face editing option
[Extrude/Move/Rotate/Offset/Taper/Delete/Copy/coLor/mAterial/Undo/eXit]<eXit>:
right-click
Command:
7. Repeat the operation using the view at the other end of the cylinder.

8. Add lights and a material and r ender the 3D model (Fig. 11.2).

270
Fig 11.2

Example 2:Move faces tool

1. Construct the 3D solid drawing shown in the left-hand drawing of Fig. 11.3 from three boxes
which have been united using the Union tool.
2. Click on the Move faces tool in the Home/Solid Editing panel. The command line shows:
Command: _solidedit
[Prompts]: _face
Enter a face editing option[prompts]: _move
Select faces or [Undo/Remove]: pick face 1 face found.
Select faces or [Undo/Remove/ALL]: right-click
Specify a base point or displacement: pick
Specify a second point of displacement: pick
[Further prompts]:
And the picked face is moved – right-hand drawing of Fig. 11.3

271
Fig.11.3

Example 3 – Off set faces tool


1. Construct the 3D solid drawing shown in the left-hand drawing ofFig. 11.4 from a hexagonal
extrusion and a cylinder which have been united using the Union tool.
2. Click on the Offset faces tool icon in the Home/Solid Editing toolbar. The command line
shows:
Command: _solidedit
[Prompts]: _face
[Prompts]
[Prompts]: _offset
Select faces or [Undo/Remove]: pick the bottom face of the 3D model 2 faces found.
Select faces or [Undo/Remove/All]: enter r right-click
Select faces or [Undo/Remove/All]: pick highlighted faces other than the bottom face 2
faces found, 1 removed
Select faces or [Undo/Remove/All]: right-click
Specify the offset distance: enter 30 right-click
3. Repeat, offsetting the upper face of the cylinder by 50 and the righthandface of the lower
extrusion by 15.
The results are shown in Fig. 11.4.

272
Fig 11.4

Example 4: Taper faces tool

1. Construct the 3D model as in the left-hand drawing of Fig. 11.5. Place in Isometricview.
2. Call Taper faces. The command line shows:
Command: _solidedit
[Prompts]: _face
[Prompts]: _taper
Select faces or [Undo/Remove]: pick the upper face of the base 2 faces found.
Select faces or [Undo/Remove/All]: enter r right-click
Select faces or [Undo/Remove/All]: pick highlighted faces other than the upper face 2
faces found, 1 removed
Select faces or [Undo/Remove/All]: right-click
Specify the base point: pick a point on the right-hand edge of the face
Specify the taper angle: enter 10 right-click
And the selected face tapers as indicated in the right-hand drawing (Fig. 11.5).

273
Fig 11.5

Example 5:Copy faces tool

1. Construct a 3D model to the sizes as given in Fig. 11.6.

Fig 11.6

2. Click on the Copy faces tool in the Home/Solid Editing toolbar. The command line shows:

Command: _solidedit
[Prompts]: _face
[Prompts]: _copy
Select faces or [Undo/Remove]: pick the upper face of the solid model 2 faces found.
Select faces or [Undo/Remove/All]: enter r right-click

274
Select faces or [Undo/Remove/All]: pick highlighted face not to be copied 2 faces found,
1 removed
Select faces or [Undo/Remove/All]: right-click
Specify a base point or displacement:pick anywhere on the highlighted face

Specify a second point of displacement: pick a point some 50 units above the face

3. Add lights and a material to the 3D model and its copied face andrender (Fig. 11.7).

Fig 11.7

Example 6:Color faces tool


1. Construct a 3D model of the wheel to the sizes as shown in Fig. 11.8.

275
Fig 11.8

2. Click the Color faces tool icon in the Home/Solid Editingtoolbar. The command line shows:

Command: _solidedit

[Prompts]: _face

[Prompts]: _color

Select faces or [Undo/Remove]: pick the inner face of the wheel 2 faces found

Select faces or [Undo/Remove/All]: enter r right-click

Select faces or [Undo/Remove/All]: pick highlighted faces other than the required face 2
faces found, 1 removed

Enter new color <ByLayer>: enter 1 (which is red) right-click

3.Add lights and a material to the edited 3D model and render (fig 11.9).

Fig 11.9

276
LAB EXERCISE 11

# 1 Construct the polyline (left-hand drawing) in the following figure. With the Revolve tool
create solid of revolution from the pline. Add suitable lighting and a colored glass material and
render it to get – right-hand illustration in the following figure.

277
# 2Working to the dimensions given in theorthographic projections of the three partsof this 3D
model (Fig. 2A), construct theassembled parts as shown in the rendered 3Dmodel of Fig. 2B .

Fig 2A

278
Fig. 2B

279
Lab session 12

PRINTING AND PLOTTING

Objectives
The aims of this lab session are:-
 To describe the settings required for printing an auto cad drawing file;
 To introduce how we can print out an Auto Cad drawing that we produce in 2D and 3D;
 To give an example of producing hard copy of an Auto cad drawing file;

PRINTING AND PLOTTING


The plot command is used to plot a drawing to a printer or plotting device or save the drawing as
a plot file.
Standard toolbar
File menu Plot…
Command line entry Plot
Creating Layout
The AutoCAD window provides two parallel working environments represented by the Model
and layout tabs. Working on the Model tab, you draw a model of your subject. On the layout
tabs, you can arrange multiple "snapshots" of the model. Each layout represents a drawing sheet
that can display one or more views of the model at various scales.
 The Model tab accesses a limitless drawing area. In model space, you draw at 1:1 scale,
and you decide whether one unit represents one inch (for a bracket) or one meter (for a
bridge).
 Layout tabs access virtual drawing sheets.When you set up layout, you tell AutoCAD
the sheet size you want to use. The layout represents the drawing sheet. This layout
environment is called paper space.

280
You can right-click a layout tab to display a shortcut menu with options to
 Create a new layout
 Import a layout from a template drawing
 Delete a layout
 Rename a layout
 Change the order of the layout tabs
 Create a new layout based on an existing layout
 Select all layouts
 Create a page setup for the current layout
 Plot a layout

Layout Setting Tab (Page Set Up Dialog Box)

In order to set up the plotting that youwant to print out


1. Right click on the layout tab.

Fig. right click on the lay out tab


2. From the lists that follow select page setup manager. The following dialog box
appears.

281
Fig. page setup manager dialog

3. In order to get in to set up click on the modify button. The following dialog appears.

Here you can specify layout settings such as plot area, plot scale, plot offset, drawing
orientation, and paper size.

282
Paper Size and Paper Units: Displays standard paper sizes available for the selected plotting
device. Printable Area displays the actual area on the paper that is used for the plot based on
the currently configured paper size.
Actual paper sizes are indicated by the width (X axis direction) and height (Y axis direction). If
no plotter is selected, the full standard paper size list is displayed and available for selection. A
default paper size is set for the plotting device when you create a PC3 file with the Add-a-
Plotter wizard. The paper size is saved with a layout and overrides the PC3 file settings.
Drawing Orientation: Specifies the orientation of the drawing on the paper for plotters that
support landscape or portrait orientation. You can change the drawing orientation to achieve a
0-, 90-, 180-, or 270-degree plot rotation by selecting Portrait, Landscape, or Plot Upside-
Down. The paper icon represents the media orientation of the selected paper. The letter icon
represents the orientation of the drawing on the page.
 Portrait: Orients and plots the drawing so that the short edge of the paper represents
the top of the page.
 Landscape: Orients and plots the drawing so that the long edge of the paper represents
the top of the page.
 Plot Upside-Down: Orients and plots the drawing upside-down.
Note: The orientation of plots is also affected by the PLOTROTMODE system variable.
Plot Area: Specifies the area of the drawing to be plotted.
 Layout/Limits: When plotting a layout, plots everything within the margins of the
specified paper size, with the origin calculated from 0,0 in the layout.
 When plotting from the Model tab, plots the entire drawing area defined by the
drawing limits. If the current viewport does not display a plan view, this option has
the same effect as the Extents option.
 Extents: Plots the portion of the current space of the drawing that contains objects.
All geometry in the current space is plotted. AutoCAD may regenerate the drawing
to recalculate the extents before plotting.
 Display: Plots the view in the current viewport in the Model tab or in the current
paper space view in a layout tab.
 View: Plots a view saved previously with the VIEW command. You can select a

283
named view from the list provided. If there are no saved views in the drawing, this
option is unavailable.
 Window: Plots the portion of the drawing you specify by a windowed area. Choose
the Window button to use the pointing device to specify the two corners of the area
to be plotted, or enter coordinate values.
o Command: Specify first corner: Specify a point
o Specify other corner: Specify a point
Plot Scale: Controls the relative size of drawing units to plotted units. The default scale setting
is 1:1 when plotting a layout. The default setting is Scaled to Fit when plotting the Model tab.
When you select a standard scale, the scale is displayed in Custom.
Note: If the Layout option is specified in Plot Area, AutoCAD plots the actual size of the
layout and ignores the setting specified in Scale.
 Scale: Defines the exact scale for the plot. The four most recently used standard
scales are displayed at the top of the list.
 Custom: Defines a user-defined scale. You can create a custom scale by entering
the number of inches (or millimeters) equal to the number of drawing units.
 Scale Line weights: Scales line weights in proportion to the plot scale. Lineweights
normally specify the line width of plotted objects and are plotted with the linewidth
size regardless of the plot scale.
Plot Offset: Specifies an offset of the plotting area from the lower-left corner of the paper. In a
layout, the lower-left corner of a specified plot area is positioned at the lower-left margin of the
paper. You can offset the origin by entering a positive or negative value. The plotter values are
in inches or millimeters on the paper.
 Center the Plot: Automatically calculates the X and Y offset values to center the
plot on the paper.
 X: Specifies the plot origin in the X direction.
 Y: Specifies the plot origin in the Y direction.
Plot Options: Specifies options for line weights, plot styles, hidden lines, and the order in
which objects are plotted.
Plot with Line weights: Specifies whether line weights assigned to objects and layers are

284
plotted.
 Plot with Plot Styles: Specifies whether plot styles applied to objects and layers are
plotted. When you select this option, Plot with Line weights is automatically selected
also.
 Plot Paper space Last: Plots model space geometry first. Paper space geometry is
usually plotted before model space geometry.
 Hide Objects: Plots model space views with hidden lines removed. Hidden line
removal for objects in layout viewports is controlled by selecting a viewport border and
then selecting Hide Plot in the Properties window. The effect of this setting is reflected
in the plot preview, but not in the layout.
Example1: printing a single copy
1. With a drawing to be printed or plotted on screen click the Plot tool icon in the Standard
toolbar (Fig.A).
2. The Plot dialog appears. Set the Printer/Plotter to a printer or plotter currently attached to the
computer and the Paper Size to a paper size to which the printer/plotter is set.
3. Click the Preview button of the dialog and if the preview is OK, right click and in the right-
click menu which appears, click Plot.
The drawing plots producing the necessary hard copy ( Fig.B ).

Fig .A Fig. B

285
Example 2:Multiple view copy
A 3D model to be printed is a Realistic view of a 3D model which has been constructed on three
layers – Red,Blue and Green in color. To print a multiple view copies proceed as follows:
1. Place the drawing in a Four: Equal viewport setting.
2. Make a new layer vportsof color cyan and make it the current layer.
3. Click the Layout button in the status bar. The drawing appears in Pspace. A view of the 3D
model appears within a cyan colored viewport ( Fig.C).
4. Click the Plot tool icon in the Output/Plot toolbar. Make sure the correct Printer/Plotter and
Paper Size settings are selected and click the Preview button of the dialog.
5. A preview of the 3D model appears.
6. If the preview is satisfactory (Fig. C), right-click and from the right-click menu click Plot. The
drawing plots to produce the required four-viewport hard copy.

Fig .CMultiple view copy

286
LAB EXERCISE 12
#By opening the drawing files that you saved in the previous exercises try to produce a print out
of the drawings by altering different plot options settings in the page setup dialog box.

REFERENCES
1. Akintan Thomas, AutoCAD Training Manual 2D Level 1,Tom Computer Center, May
2006
2. Alf Yarwood, Introduction toAutoCAD 2009 2D and 3D Design, First edition,Macmillan
Company, 2008
3. Ellen Finkelstein,Top 25 AutoCAD Productivity Tips Every AutoCAD User Should
Know, retrived from www.ellenfinkelstein.com, (n.d), retrieved July 17 2014.
4. Jon McFarland, Auto Cad 2009 And Auto Cad Lt 2009 No Experience Required,Wiley
Publishing, Inc. India, 2008
5. Kristen S. Kurland, AutoCAD 3DTraining Manual,Autodesk, Inc.2004

MostefaBouchama, Engineering Graphics WithAuto Cad, King Fahd University of Petroleum &
Minerals, July 2004

287

You might also like