Overview

advertisement
Graphics
Overview



Brief (2-3 week) introduction
2-dimensional graphics only
 Many of the concepts translate over to 3D
Our approach
 A trivial graphics system
 develop basic graphic primitives
 2-dimensional array
 console-based output
 bring the system over to the Java GUI world
 using our developed graphic primitives
 examining Java's own 2-dimensional facilities
 the Graphics2D, AffineTransform, etc classes
Basic Concepts

point
 Position in space
 No dimension

line
 two points specify a direction
adding a third point
 if first and third specify the same direction as first and second, we say the points are
on the same line


one dimensional
the line specified by the two points consists of the two points and all the points that satisfy
above test of direction
plane
 two-dimensional
 height and width
 x and y axes
 origin at (0,0)
 x and y coordinates
 Cartesian coordinate system
y-axis


0
x-axis
Basic Geometry
slope of a line
 vertical rise per unit of horizontal movement (rise vs. run)
 (y2 – y1) / (x2 – x1)
 We denote this value as m, and we say that the slope of the
line is m
(x2, y2)
y-axis

(x1, y1)

Slope-intercept equation of a line
 y = mx + b
 b is the y-axis intercept (when x = 0)
 uniquely specifies a line
b

length of a line segment with endpoints (x1, y1) and (x2, y2)
 ((x2 – x1)2 + (y2 – y1) 2 )1/2
x-axis
(x2, y2)
y-axis
line segment
 points on a line between two endpoints
(x2, y2)
(x1, y1)
0

x-axis
y-axis
0
(x1, y1)
0

midpoint of a line segment with endpoints (x1, y1) and (x2, y2)
 (x1+x2)/2, (y1+y2)/2)

perpendicular lines
 Lines L1 and L2
 mL1 = -1 / mL2

vector
 direction and length
 [Dx, Dy]
 Dx = distance to move in x direction
 Dy = distance to move in y direction
 No fixed position in space (unlike line segment)
 How far and in what direction, but no starting point
x-axis
Dy
Dx
Display Devices and Pixels





unlike mathematical points, points on display device have dimension
number of points is the resolution of the device
point on the display device is called a pixel (picture element)
line segments are drawn on the display device by setting the intensity of the pixels between
the endpoints
device can be thought of as a 2-dimensional array or grid
Frame Buffers


until we display our image on the display device, we will keep our grid with the pixel
intensities stored in memory
The storage area is called a frame buffer
Vector Generation



Turning on the pixels for a line segment is called vector generation
 Determining the pixels between two endpoints is the same regardless of the position of
the line segment, so we speak of vectors
Various algorithms for vector generation
 Differ in efficiency, speed, accuracy of drawn vector
 simple-minded
 dda
 Bresenham
Basic idea is to use information about the slope of the line to move in the x and y directions
 Issues of round-off error (coordinates are integers, while the slope usually is not)

Want to make sure we turn on an appropriate number of pixels
Too few steps
Just right
Too many steps
Character Generation


facilities for character display are sometimes built into the display device
 may be done in hardware for efficiency
Two basic method of character generation
 stroke method – characters are drawn from a series of line segments
(using a vector generation algorithm)
 Allows for scaling (simply draw larger/smaller segments)

dot matrix method – characters are represented as a 2-dimensional grid of dots (similar
pixels and a frame buffer)
 Placing the character on the screen means copying the corresponding dots to pixels
in the frame buffer
 usually handled by a character generator chip
 Not conducive to scaling
Display Devices


raster display
 frame buffer is scanned and displayed
vector refresh display
 requires only the endpoints; draws the image on the display using vector generation
Display File



originally used in vector refresh displays, but proved useful in other display types as well
holds the graphic drawing commands
 e.g. draw a line between (x1, y1) and (x2, y2)
interpreted using the vector generation algorithm
Some Graphic Primitives




lines are usually specified via both endpoints
however, we often draw lines end-to-end (e.g. polygons)
we will therefore specify a line by only one endpoint
 the final point of the previous line segment becomes the first of the new line segment
the system keeps track of the current pen position
Line-*** Specifying a Line

Line-ABS(x, y)
 Draw a line from the current pen position to point (x, y)

Line-REL(dx, dy)
 Draw a line from the current pen position to a point dx units
away in the x direction and dy units away in the y direction.
(x, y)
(current pen position)
dy
dx
(current pen position)
Move-*** Moving the Pen (without drawing)
Provides for drawing disconnected segments

Move-ABS(x, y)
 Draw a line from the current pen position to point (x, y)

Move-REL(dx, dy)
 Draw a line from the current pen position to a point dx units away in the x direction and dy
units away in the y direction.
Using these Commands

Drawing a house
LINE-REL(0, 0.2)
LINE-REL(0.1, 0.1)
LINE-REL(0.1, -0.1)
LINE-REL(0, -0.2)
LINE-REL(-0.2, 0)

Wishful thinking
 If we could package the above as a method 'House'
MOVE-ABS(0.1, 0.2)
HOUSE
MOVE-ABS(0.4, 0.2)
HOUSE
MOVE-ABS(0.7, 0.2)
HOUSE
The Display File Interpreter


above commands are placed in display file
interpreter goes through the file executing the commands
Normalized Device Coordinates




(0, 1)
Don't want to be tied down to a particular device's coordinates
Want device independence
Will use coordinate units other than pixels
 Interpreter will then convert to device-specific coordinates
Will use a coordinate system that goes from 0.0 to 1.0
 These are called normalized device coordinates
(1, 1)
(0, 0)
(1, 0)
(0, 0)
(1, 0)
Things to Think About


Line Style
 Color
 Solid/dashed
 Weight?
Polygons
 What about ovals and circles?
Download