Midterm Review Spring 2015

advertisement
CIS 457
Midterm Review Highlights
Spring, 2015
Study quizzes, assignments (hints in Appendix F), sample programs on website, and the
following topics:
Intro./Java GUI review
- 7 steps in creating Java GUI
-using a JFrame for a window, and JPanel for drawing
-adding Components to Container, setting properties of components, specifying layout manager, registering
event listeners
Chapter 1
- drawline, drawRect, fillRect methods from Graphics class : what pixels are displayed (i.e. set to
foreground color)? how many pixels are displayed?
- client rectangle
- using getSize() method to get a Dimension (encapsulates width, height of a Component)
- problem with boundaries of filled regions (e.g. problem filling upper left and lower right portions
of a rectangle with different colors)
- checker method pg. 8
- logical coordinates vs. device coordinates
- obtaining maxX, maxY of client rectangle
- transforming y coordinate to orient y-axis with positive toward top and origin in lower left of client
rectangle
- converting logical coordinates to device coordinates: 2 possible solutions: rounding, truncating
- both rounding and truncating: iX(fx(X)) = X; and | fx(iX(x) – x | < 0.5
- we use rounding since truncating can often lead to worse results (especially in cases where logical
coordinates are often integral --- see examples on handout)
- iX, iY, fx, fy methods (pg. 9 -- no scaling (i.e. scaling factor of 1 for both x and y cords.), “reversing”
direction of y)
- applications : creating geometric figures through rotation (e.g. Triangles program – pg. 11-13) obtaining
center of drawing rectangle; using p (p>0, p<1)and q (q = 1-p) to obtain point on line segment between two
other points
- principle of doing work (arithmetic) all with logical coordinates (float) and converting to int for drawing
(pg. 13 )
-anisotropic and isotropic mapping modes (general principle: divide logical (float type) coordinate by
pixelWidth (pixelHeight) to obtain device (int type) coordinate; multiply device (int type) coordinate by
pixelWidth (pixelHeight) to obtain logical (float type) coordinate;
-note that with isotropic mapping we use same scale for both x and y coordinates (we can choose
pixelSize to be the max of pixelWidth and pixelHeight; if pixelSize is equal to pixelWidth, the
drawing rectangle borders left and right of canvas (JPanel); if pixelSize is equal to pixelHeight, the
drawing rectangle borders top and bottom of canvas (JPanel)
- isotropic mapping with origin in center of the drawing rectangle (see methods on page 19), logical x
coordinates ranging from –rWidth/2 to +rWidth/2; logical y coordinates ranging from –rHeight/2 to
+rHeight/2; note changes in drawing rectangle as window is resized (pg. 19, fig. 1.8)
-using MouseEvents for obtaining points for a polygon (CvDefPoly example pgs.23-25) -- to register an
object for listening for mouse events on a component, call addMouseListener method on the component
(you can use a MouseAdapter reference as argument to this call); MouseAdapter is an abstract class that
implements the MouseListener interface that defines 5 abstract methods – mouseClicked, mouseEntered,
CIS 457 Midterm Review Highlights
2.
mouseExited, mousePressed, mouseReleased; MouseAdapter has empty implementation for each of those
methods; override the methods (e.g. MousePressed on pg. 24) that are needed;
Chapter 2
-mathematics behind the 2-dimensional and 3-dimensional graphics
-Vector Space over a Field; scalars (Field elements) and vectors
-properties of a vector space (pg. 32-33); basis for a vector space (see class notes for definition of a basis)
-R2 and R3 vector spaces – these vectors geometrically have length and direction
-unit vectors i, j, and k form a basis for R3
-vector addition in R2 and R3
-inner product (dot product) definition of 2 vectors in R3 or R2 (note for computing inner product of 2
vectors in R2, use 0 for the 3rd component of the two vectors); note that the inner product of 2 vectors is a
scalar
-properties of the inner product (pg. 34); note that inner product is commutative; note
easy formula for obtaining the dot product of 2 vectors (derived by writing vectors as linear combinations
of i, j, and k basis vectors, and using properties of dot product) -know how to compute the dot product of 2
vectors
-note that for a vector u, |u| 2 = u . u ; and u . u = 0 if and only if u is the 0 vector
-determinants: useful for solving system a1x + b1y = c1, a2x + b2y = c2; (Cramer’s rule, pg. 35)
- determinant of 3 by 3 matrix (can expand about any row or column)
- determinant form of equation of line in R2 through 2 points, and determinant form of plane
in R3 determined by 3 points (pg. 36)
- definition of vector product (cross product) of 2 vectors a and b: a x b note that the cross product
of 2 vectors is a vector (not a scalar)
-geometrical interpretation of the cross product (see fig. 2.4 on pg. 37)
- note that the 3 vectors, in order: a, b, a x b form a right-handed triple, that is if vectors a and b are
joined at that tails and a is rotated toward b through an angle of less than 180 degrees (this assumes
that a and b are vectors that are not in the same (or exact opposite) direction) then a x b has the
direction of a right-handed screw if rotated in the same way
-properties of vector product (note a x b = - b x a; i.e. a x b and b x a have same length but are in
opposite directions; length of a x b is equal to area of parallelogram determined by a and b
- determinant form of a x b (pg. 38, section 2.4)
-know how to compute the cross product of 2 vectors using a determinant
- using the cross product to determine orientation of 3 points A, B, C (see fig. 2.6 pg. 39 and
discussion on 39, section 2.5)
-static float method area2 in class Tools2D: can be used for determining orientation of 3 points in R2
(Point2D class has 2 fields (default, i.e. package, access) and a 2 argument constructor – pg. 25)
- definition of a Polygon (pg. 41); simple polygons, convex vertex of a polygon, reflex vertex of
a polygon, convex polygon, concave polygon; convex and concave region in a plane (see class
notes)
- detecting a convex vertex in a polygon (find vertex (vertices) with min x-coordinate; among
all such vertices, select vertex with min y-coordinate)
- static boolean method ccw for determining orientation of vetices of a polygon (pg. 42, section 2.6)
- know formula for twice the area of polygon – generalizes formula for twice the area of a triangle
(pg. 43, section 2.7)
-static float method area2 with a single parameter of type Point2D[] (pg. 43) – obtains
twice the signed area of a polygon
- point-in-triangle test (section 2.8; how is that modified if orientation of A, B, C is negative (clockwise) ? )
-point-in-polygon test – know how to do this (setion 2.9, pg. 46-47)
CIS 457 Midterm Review Highlights
3.
-point-on-line test: case 1: given ax + by = c, equation of line; using tolerance epsilon; case 2: given 2
points : first derive formula for line (can use determinant formulation, pg. 30), then proceed as in case 1, or
more easily use Tools2D.area2 method that takes 3 Point2D arguments
-point-on-line segment AB test – use point-on-line test, and test x-coordinates and
y-coordinates for being in range (see static boolean method onSegment (pg. 48-49))
-Go over handout “Projection of point P on a line”, and the exercises in that handout
-Projection of point on a line (fig. 2.10 pg. 49) – note that if P’ is the projection of P
on AB then the length of AP’ is given by absolute value of AP . AB / |AB|
(note that AB / |AB| is a unit vector in direction of AB)
- distance between a point and a line, given line: ax + by = h, with a2 + b2 = 1; note that
vector n = (a,b) is a unit normal to this line (i.e. n has length 1 and is perpendicular to
the line); signed distance from P to line: OP . n - h (here O is the origin (0,0))
-projection of point on a line: problem is to determine coordinates of point P’, the projection
of point P on line; case 1: given 2 points A and B that determine the line
(see static Point2D method projection
on pg. 52; it uses fact that AP’ is given by the (signed) length of the
AP’ times unit vector in direction of AB)
case 2: given ax + by = h equation of line with a2 + b2 = 1
(see static Point2D method projection on pg. 53; it uses:
fact that OP’ = OP –dn where d is signed distance from P to line,
and n is the unit normal (a,b) to the line )
-Triangulation of a polygon – know algorithm; static method triangulate in class Tools2D
Chapter 3
- matrix multiplication; identity matrix; inverse of a square matrix
- linear transformation (mapping from one vector space to another, both vector spaces over the same
field, with 2 properties: know these properties)
-note: a linear transformation maps the 0 vector of one vector space to the 0 vector of another (know
how to show this – see class notes)
-note: the entire mapping of a linear transformation is determined by the mapping of the basis vectors
(why?)
- linear transformations from R2 to R2 given by T(x,y) = (ax + by, cx + dy) can be written as
T(x,y) = [x y] M where M is the 2 by 2 matrix with first row is equal to [a c] and second row
equal to [b d]; important note that in this “transformation matrix” M, the first row is the
image of the vector (1, 0) and the second row is the image of the vector (0, 1)
-types of linear transformations from R2 to R2 :
rotation through angle φ about the origin: 1st row of M: [cos φ sin φ] ,
2nd row of M: [-sin φ cos φ] you can easily obtain this by considering the images of
(1,0) and (0,1) (see arrow code example pgs. 67-69)
scaling: T(x,y) = (sxx, syy) 1st row of M: [sx 0], 2nd row of M: [0, sy]
special cases of scaling: reflection about the origin, reflection about the x-axis, reflection
about the y-axis (know the transformation matrices for these linear transformations)
shearing along the x-axis: transformation matrix: 1st row [1 0] 2nd row [a 1]
shearing along the y-axis: transformation matrix: 1st row [1 b] 2nd row [0 1]
-Translation: shifting points in same direction, using a “shift vector”; translation is not a linear
transformation (assuming shift vector is not the zero vector); why? Because the 0 vector does not get
mapped to 0 vector (assuming shift vector is not 0)) : x gets mapped to x + a, y gets
mapped to y + b; vector (a,b), the “shift vector” is also called the “translation vector”; there is no 2
CIS 457 Midterm Review Highlights
by 2 matrix that can be used as the transformation matrix; however a 3 x 3 transformation matrix
with “homogeneous coordinates” can be used;
[x y 1] times this homogeneous transformation matrix gives [x’ y’ 1]; ([x y] gets mapped to
[x’ y’]); this homogeneous matrix has [1 0 0] as 1st row; [0 1 0] as 2nd row;
and [a b 1] as 3rd row
-composition of linear transformations: resulting transformation matrix is the product of the
corresponding transformation matrices
-note: if several points are to be transformed using a composite linear transformation, for efficiency :
first obtain the composite transformation matrix and apply to each point, rather than for each point
applying the first transformation to the point then the second
-note if we have a transformation given by a 2 by 2 transformation matrix and wish to form a
composite transformation with a transformation given by a 3 by 3 matrix, first modify the 2 by 2
transformation matrix to a 3 by 3 (make 3rd col. 0 0 1, and 3rd row 0 0 1) see e.g. pg. 72, equation 3.5
-inverse transformations (section 3.5); note that not every linear transformation has an inverse
transformation; e.g. projection of a point in R2 onto the x-axis does not have an inverse transformation
-rotation about an arbitrary point (sec. 3.6) -- application code pgs. 75-77
-changing the coordinate system (sec. 3.7)
-rotations about 3D coordinate axes (sec. 3.8)
-rotation about an arbitrary axis (sec. 3.9)
4.
Download