University of Babylon College of Information Technology Department of Information Network Day:

advertisement
University of Babylon
College of Information Technology
Department of Information Network
Day: Wednesday
Date: 31-10-2012
Stage: Second.
Topic: Introduction to Computer Graphics
Lecture3: Ellipse and Polygon Generating Algorithms.
General Objective:
The students will be able to use ellipse and polygon generating
algorithms when they need to build other algorithms.
Procedural Objective:
1. The students will be able to use ellipse generating algorithm to
draw different kinds of it.
2. The students will be able to use polygon generating algorithm to
draw many modified shapes of it.
3. The students will be able to modify the given algorithms to draw
many other shapes.
Teaching aids: Lecture (presented by MS-power point program on the
laptop), LCD monitor, discussion between lecturer and students,
whiteboard, pens.
1
5.1 Ellipse-Generating Algorithm
5.1.1 Introduction
Ellipse: A modified circle whose radius varies from a maximum value in
one direction (major axis) to a minimum value in the perpendicular
direction (minor axis).
The sum of the two distances d1 and d2, between the fixed positions F1
and F2 (called the foci of the ellipse) to any point P on the ellipse, is the
same value, i.e.
d1 + d2 = constant
5.1.2 Ellipse Properties
Expressing distances d1 and d2 in terms of the focal coordinates F1 = (x1,
x2) and F2 = (x2, y2), we have:
( x  x1 )2  ( y  y1 )2  ( x  x2 )2  ( y  y2 )2  constant
2
2
Cartesian coordinates:
2
 x  xc   y  yc 
  1

  
 rx   ry 
Polar coordinates:
x  xc  rx cos 
y  yc  ry sin 
5.1.3 Steps of Ellipse Generating Algorithm:
1. Get the center point (xc,yc) and the two radius (rx) & (ry).
2. Set theta=0, twpi=6.283, dtheta=1/max(rx,ry), x=xc+rx,y=yc.
3. While (theta<=twpi) do the following sub steps:
3.1 pset(x,y).
3.2 x = x + rx / ry * (yc-y) * dtheta.
3.3 y = y + ry / rx * (x-xc) * dtheta.
3.4 theta=theta+dtheta.
4. end.
3
5.2 Polygon-Generating Algorithm
5.2.1 Introduction
A polygon can be represented as a number of line segments connected
end to end to form a close figure. Alternatively, it may be represented as
the points where the sides of the polygon are connected. The line
segments which make up the polygon boundary are called sides or edges.
The end points of the sides are called the polygon vertices.
Polygon with six vertices
5.2.2 Steps of Polygon Generating Algorithm:
1. Get the center point (xc,yc) ,radius (r), number of vertices(n).
2. Set theta=0, twpi=6.28, dtheta=twpi/n, xs=xc+r,ys=yc.
3. For i=1 to n do the following sub steps:
3.1 theta = theta + dtheta.
3.2 xe = xc + r * Cos(theta).
3.3 ye = yc - r * Sin(theta).
3.4 Line (xs, ys)-(xe, ye).
3.5 Set xs=xe, ys=ye.
4. end.
4
Download