Upload
edwina-simon
View
219
Download
0
Tags:
Embed Size (px)
Citation preview
Computational Biology, Part EBasic Principles of Computer
Graphics
Computational Biology, Part EBasic Principles of Computer
Graphics
Robert F. MurphyRobert F. Murphy
Copyright Copyright 1996, 1999, 2000, 2001. 1996, 1999, 2000, 2001.
All rights reserved.All rights reserved.
2D Coordinate Systems2D Coordinate Systems
Basic 2D Graphics Goal: Display an object or Basic 2D Graphics Goal: Display an object or a set of objects which are defined in some a set of objects which are defined in some coordinate system specified by the user using coordinate system specified by the user using the coordinate system of a graphics devicethe coordinate system of a graphics device user coordinates may or may not correspond to user coordinates may or may not correspond to
“real world” coordinates“real world” coordinates geographical map - yesgeographical map - yes stock prices vs. time - nostock prices vs. time - no
2D Coordinate Model2D Coordinate Model
World Coordinate
Plane
Device Coordinate
Plane
“World” or “User” Coordinates“World” or “User” Coordinates
Units may be anything and may be different Units may be anything and may be different for x and yfor x and y
Three equivalent methods to describe the Three equivalent methods to describe the coordinates of an objectcoordinates of an object Absolute x,y values (Absolute x,y values (“absolute” “absolute” coordinates)coordinates) Relative to object origin (Relative to object origin (“local” “local” coordinates)coordinates) Relative to previous position (Relative to previous position (“relative” “relative” coordinates)coordinates)
“World” or “User” Coordinates“World” or “User” Coordinates
3,1
4,2
5,1
Absolute
*
1,1
1,-1
Relative
*
1,1
2,0
Local
* 1st coordinates must be absolute
“Physical” or “Device” Coordinates“Physical” or “Device” Coordinates
Different for each deviceDifferent for each device Units are some measure of actual distance Units are some measure of actual distance
(such as pixels, inches, etc.) and are (such as pixels, inches, etc.) and are normally the same for x and y normally the same for x and y
Windows and ViewportsWindows and Viewports
Output devices such as monitors have finite Output devices such as monitors have finite sizes, so we cannot visualize entire planesizes, so we cannot visualize entire plane We define a We define a viewportviewport as a rectangular portion as a rectangular portion
of the World we wish to seeof the World we wish to see We may also wish to use only a We may also wish to use only a portion portion of of
our output device to display a graphour output device to display a graph We define a We define a windowwindow as a rectangular portion of as a rectangular portion of
the Device we wish to usethe Device we wish to use
Windows and ViewportsWindows and Viewports
World Coordinate
Plane
Device Coordinate
Plane
Viewport
Window
Windows and ViewportsWindows and Viewports
Note that many differents terminologies are Note that many differents terminologies are used for these concepts and that window used for these concepts and that window and viewport as used here are and viewport as used here are reversedreversed from from the way they are used in many computer the way they are used in many computer graphics textsgraphics texts
Windows and ViewportsWindows and Viewports
4 values (x & y coordinates of two points) 4 values (x & y coordinates of two points) required to specify required to specify viewportviewport e.g., positions of lower left and upper right cornerse.g., positions of lower left and upper right corners
4 values (x & y coordinates of two points) 4 values (x & y coordinates of two points) required to specify required to specify windowwindow
These 8 values define a unique These 8 values define a unique transformationtransformation from World to Device from World to Device coordinatescoordinates
The Basic Linear TransformationThe Basic Linear Transformation
We can convert from World (We can convert from World (unprimedunprimed) to ) to Device (Device (primedprimed) coordinates using the ) coordinates using the following equations:following equations:
x' =x'min+ x−xmin( )x'max−x'min
xmax−xmin
y'=y' min+ y−ymin( )y'max−y'min
ymax−ymin
The Basic Linear TransformationThe Basic Linear Transformation
We can convert these equations to the formWe can convert these equations to the form
These equations simultaneously These equations simultaneously scalescale and and translocatetranslocate
x' =a+bx
The Basic Linear TransformationThe Basic Linear Transformation
(Demonstration C1, Part 1)(Demonstration C1, Part 1)
Transformation matricesTransformation matrices
Can use matrix notation to simplify Can use matrix notation to simplify description of calculationsdescription of calculations
Goal: Be able to use a single Goal: Be able to use a single transformation transformation matrix matrix to convert fromWorld to Device to convert fromWorld to Device coordinatescoordinates
Problem: Scaling requires multiplication, Problem: Scaling requires multiplication, translocation requires additiontranslocation requires addition
Solution: Use Solution: Use homogeneous coordinateshomogeneous coordinates
Transformation matricesTransformation matrices
Homogeneous coordinates: Add an extra Homogeneous coordinates: Add an extra coordinate to both World and Device coordinate to both World and Device coordinatescoordinates
Translation, scaling and rotation can now be Translation, scaling and rotation can now be done with a single matrix (set done with a single matrix (set ww=1)=1)
x' y' w'[ ] = x y w[ ]a d gb e hc f i
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
Transformation MatricesTransformation Matrices
Translation (Displacement)Translation (Displacement)
x' y' 1[ ] = x y 1[ ]1 0 00 1 0Tx Ty 1
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
which gives:x'=x+Txy'=y+Ty
Transformation MatricesTransformation Matrices
ScalingScaling
x' y' 1[ ] = x y 1[ ]Sx 0 00 Sy 00 0 1
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
which gives:x'=Sxxy'=Syy
Transformation MatricesTransformation Matrices
Rotation about Rotation about xx axis axis
x' y' 1[ ] = x y 1[ ]
1 0 00 cosθ 00 0 1
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
which gives:x'=xy'=ycosθ
Transformation MatricesTransformation Matrices
Rotation about Rotation about originorigin
x' y' 1[ ] = x y 1[ ]
cosφ sinφ 0−sinφ cosφ 00 0 1
⎡
⎣
⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥
which gives:x'=xcosφ−ysinφy'=xsinφ+ ycosφ
Transformation matricesTransformation matrices
Net transformation can be obtained by Net transformation can be obtained by multiplying matricesmultiplying matrices
Transformation matrices can be Transformation matrices can be implemented in display hardware for implemented in display hardware for dramatic speed improvementdramatic speed improvement
When not implemented in hardware, When not implemented in hardware, tradeoff increased cost for matrix tradeoff increased cost for matrix computation vs. ease in manipulationcomputation vs. ease in manipulation
Transformation MatricesTransformation Matrices
(Demonstration C1, Part 2)(Demonstration C1, Part 2)
Non-linear transformationsNon-linear transformations
Transformations such as logarithms can be Transformations such as logarithms can be implemented using run-time computation or implemented using run-time computation or precomputed lookup tables precomputed lookup tables
Graphing Data in ExcelGraphing Data in Excel
Since all graphs on our monitor are two-Since all graphs on our monitor are two-dimensional, how can we graph data for a dimensional, how can we graph data for a single variable (where does the other single variable (where does the other dimension come from)?dimension come from)? When only one variable is available, Excel When only one variable is available, Excel
“creates” a variable called the “creates” a variable called the categorycategory. It then . It then plots the original variable plots the original variable versusversus the category. the category. By default, the category consists of the numbers By default, the category consists of the numbers starting from 1 and incrementing by 1.starting from 1 and incrementing by 1.
Graphing Data in ExcelGraphing Data in Excel
Types of graphs that require only one row or Types of graphs that require only one row or column of data (categorical graphs)column of data (categorical graphs) Area, Line, 3D Area, 3D LineArea, Line, 3D Area, 3D Line Bar, Column, 3D Bar, 3D ColumnBar, Column, 3D Bar, 3D Column Pie, Doughnut, Radar, 3D PiePie, Doughnut, Radar, 3D Pie (3rd dimension for the 3D plots has depth of 1)(3rd dimension for the 3D plots has depth of 1)
If more than one row or column of data is If more than one row or column of data is provided, additional lines, bars, etc. are created provided, additional lines, bars, etc. are created
Graphing Data in ExcelGraphing Data in Excel
Types of graphs requiring two or more rows Types of graphs requiring two or more rows or columns of data (correlated or or columns of data (correlated or XYgraphs)XYgraphs) XY (scatter)XY (scatter)
If XY graph is selected but only one row or column If XY graph is selected but only one row or column of data are present, categorical values are generated of data are present, categorical values are generated and plot becomes equivalent to a Line graphand plot becomes equivalent to a Line graph
3D surface3D surface
Graphing Data in ExcelGraphing Data in Excel
(Demonstration C2)(Demonstration C2)
Graphing Data in ExcelGraphing Data in Excel
Graphing Tip: When values to be plotted Graphing Tip: When values to be plotted are not present in conveniently adjacent are not present in conveniently adjacent cells, data can be “collected” using cells, data can be “collected” using references to cells containing original datareferences to cells containing original data