م . نسح

advertisement
‫م‪.‬م عالء الدين عباس عبد الحسن‬
‫‪Sunday 4/11/2012‬‬
ELLIPSE-GENERATING
ALGORITHMS
* Loosely stated, an ellipse is an elongated circle. We can also
describe an ellipse as a modified circle whose radius varies
from a maximum value in one direction to a minimum value
in the perpendicular direction.
* The straight-line segments through the interior of the ellipse
in these two perpendicular directions are referred to as the
major and minor axes of the ellipse.
2
Ellipse-Generating Algorithms
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).
F1
d1
P=(x,y)
F2
d2
 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 + d3 2 = constant
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
ry
rx
* Cartesian coordinates:
* Polar coordinates:
2
 x  xc   y  yc 
  1

  
 rx   ry 
2
x  xc  rx cos 
y  yc  ry sin 
4
Ellipse Algorithms
* Symmetry between quadrants
* Not symmetric between the two octants of a quadrant
* Thus, we must calculate pixel positions along the
elliptical arc through one quadrant and then we obtain
positions in the remaining 3 quadrants by symmetry
(-x, y)
(x, y)
ry
rx
(-x, -y)
5
(x, -y)
Polar Ellipse Algorithm
Begin
xc , yc --- ellipse Center
r1,r2 -- Radiuses
x , y --- point on ellipse
theta
-- angle
dTheta --- angle change
dTheta = 1/Max(r1,r2)
for (theta =0 to Pi*2
step = dTheta)
begin
x=xc + r1 * Cos(theta)
y=yc + r2 * Sin(theta)
point(x , y)
endfor
end
ELLIPSE-GENERATING
ALGORITHMS
* Polar coordinates:
sin θ = (y – yc )/ry
cos θ =(x – xc) / rx
dx = -rx sin θ dθ
Dy = ry cos θ dθ
Dx= -rx (y – yc )/ry = (rx/ry ) (yc -y)dθ
Dy = ry (x – xc) / rx = ( ry/rx) ( x – xc) dθ
7
Ellipse Algorithm
Begin
xc , yc --- ellipse Center
rx,ry -- Radiuses
x , y --- point on ellipse
theta
-- angle
dTheta --- angle change
dTheta = 1/Max(r1,r2)
for (theta =0 to Pi*2
step = dTheta)
begin
x = x + rx / ry * (yc-y) * dtheta
y = y + ry / rx * (x-xc) * dtheta
point(x , y)
endfor
end
Polygon
*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.
9
Polygon Classifications
An interior angle of a polygon is an angle inside the polygon boundary that is
formed by two adjacent edges. If all interior angles of a polygon are less than
or equal to 180 , the polygon is convex. An equivalent definition of a convex
polygon is that its interior lies completely on one side of the infinite extension
line of any one of its edges. Also, if we select any two points in the interior of a
convex polygon, the line segment joining the two points is also in the interior. A
polygon that is not convexis called a concave polygon. Figure 3-42gives examples
of convex and concave polygons.
The term degenerate polygon is often used to describe a set of vertices that
are collinear or that have repeated coordinate positions. Collinear vertices generate
a line segment. Repeated vertex positions can generate a polygon shape with
extraneous lines, overlapping edges, or edges that have a length equal to 0. Sometimes
the term degenerate polygon is also applied to a vertex list that contains
fewer than three coordinate positions.
r
10
Polygon Classifications
11
Identifying Concave
Polygons
* A concave polygon has at least one interior
angle greater than 180r. Also, the extension of
some edges of a concave polygon will intersect
other edges, and some
* pair of interior points will produce a line
segment that intersects the polygon boundary.
Therefore, we can use any one of these
characteristics of a concave polygon as a basis
for constructing an identification algorithm.
12
Polar polygon Algorithm
Begin
xc , yc --- polygon Center
r -- Radius
N -- number of vertices
theta
-- angle
dTheta --- angle change
dTheta = twPI/ N
xs=xc+r,ys=yc
for (i= 1 to N )
begin
theta = theta + dtheta
xe = xc + r * Cos(theta).
ye = yc - r * Sin(theta).
Line (xs, ys)-(xe, ye).
Set xs=xe, ys=ye.
endfor
end
14
Download