Unformatted text preview:

Lecture 5 Affine Graphics A Connect the Dots Approach to Two Dimensional Computer Graphics The lines are fallen unto me in pleasant places Psalms 16 6 1 Two Shortcomings of Turtle Graphics Two points determine a line In Turtle Graphics we use this simple fact to draw a line joining the two points at which the turtle is located before and after the execution of each FORWARD command By programming the turtle to move about and to draw lines in this fashion we are able to generate some remarkable figures in the plane Nevertheless the turtle has two annoying idiosyncrasies First the turtle has no memory so the order in which the turtle encounters points is crucial Thus even though the turtle leaves behind a trace of her path there is no direct command in LOGO to return the turtle to an arbitrary previously encountered location Second the turtle is blissfully unaware of the outside universe The turtle carries her own local coordinate system her state but the turtle does not know her position relative to any other point in the plane Turtle geometry is a local intrinsic geometry the turtle knows nothing of the extrinsic global geometry of the external world The turtle can draw a circle but the turtle has no idea where the center of the circle might be or even that there is such a concept as a center a point outside her path around the circumference These two shortcomings no memory and no knowledge of the outside world often make the turtle cumbersome to program For example even though it is straightforward to program the turtle to generate a regular polygon it is not so easy to program the turtle to draw a rosette A rosette is simply the collection of all the lines joining all pairs of vertices in a polygon Nevertheless though we can easily program the turtle to visit all the vertices of a polygon we cannot simply command the turtle to draw the lines joining each pair of vertices because the turtle does not remember where these vertices are located It is for this reason that in Turtle Graphics to generate the rosette we need to precompute the distances between each pair of vertices and the angles between adjacent diagonals Two points determine a line but Turtle Graphics gives us access to only one pair of points at a time 2 Affine Graphics In Affine Graphics we will have simultaneous access to many different points in the plane and we will be able to join any two of these points with a straight line These two abilities distinguish affine geometry from turtle geometry and these two properties make Affine Graphics an extremely powerful tool for Computer Graphics To implement Affine Graphics we are going to introduce a new language CODO COnnect the DOts In CODO as in LOGO points and vectors are stored internally in terms of coordinates but the CODO programmer just like the LOGO programmer has no direct access to these coordinates Instead the main tools in CODO for generating new points and lines are the affine transformations discussed in the Lecture 4 2 1 The CODO Language In CODO there are four types of objects points vectors line segments and affine transformations Points and vectors are stored internally using affine coordinates line segments are represented by their end points affine transformations are stored as 3 3 matrices There are only three types of commands in CODO commands that create geometry commands that generate affine transformations and a command to display geometry Below is a complete description of the CODO language Geometry Creation 1 VECTOR VECTOR P Q creates the vector from P to Q usually denoted by Q P 2 LINE LINE P Q creates the line segment PQ LINE P1 K Pn creates the line segments P1P2 K Pn 1P n 3 TRANSFORM TRANSFORM X M applies the affine transformation M to the object X which may be a point a vector or a line segment to create a new point vector or line segment Note that by definition TRANSFORM LINE P Q M LINE TRANSFORM P M TRANSFORM Q M TRANSFORM X 1 K X n M1 K M p applies each affine transformation M j to each object X i to create the new collection of objects TRANSFORM X i M j Affine Transformations 1 Vectors a ROT rotates vectors by the angle b SCALE s scales the length of vectors by the scale factor s 2 Points a TRANS v translates points by the vector v b ROT Q rotates points about the fixed point Q by the angle c SCALE Q s scales the distance of points from the fixed point Q by the factor s d SCALE Q w s scales the distance of points from the fixed point Q in the 2 e direction w by the scale factor s AFFINETRANS P1 P2 P3 Q1 Q2 Q3 creates the unique affine transformation that maps Pk Qk k 1 2 3 f COMPOSE M1 M 2 creates the composite transformation of M1 and M 2 We often write M1 M 2 instead of Compose M1 M 2 g INVERT M creates the inverse of the transformation M We often write M 1 instead of INVERT M Rendering DISPLAY X1 K X n displays the objects X1 K X n The objects displayed may be only either points or lines Notice that CODO does not include a full suite of vector operations In CODO we can perform scalar multiplication on vectors c v TRANSFORM v SCALE c but there are no commands to compute u v u v or det u v The emphasis in CODO is on affine transformations not on vector operations Nevertheless these vector operations could easily be added as a simple enhancement to the version of CODO presented here The commands to create geometry can be used to generate new points lines and vectors from existing points lines and vectors But we still need some initial geometry to get started We begin by fixing a single point C and a single vector ivec In affine coordinates we set C 0 0 1 and ivec 1 0 0 Thus C is located at the origin of the underlying coordinate system and ivec is the unit vector pointing along the positive x axis We can generate a unit vector along the y axis by the command TRANSFORM ivec ROT 2 and we can generate a new point along the x axis by the command TRANSFORM C TRANS ivec In the next section we will show how to generate lots of interesting shapes starting from this modest beginning 2 2 Sample CODO Programs We begin by writing a CODO program to generate the vertices of a polygon To find the vertices of an n sided polygon we simply rotate one vertex around the center of the polygon n times through an angle of 2 n POLYVERTS Center Vertex Number of Vertices 2 Number of Vertices For k 0 Number of Vertices PolyVerts k TRANSFORM Vertex ROT Center k 3 Another program STARVERTS generates the vertices of a star in much the same …


View Full Document

Rice COMP 360 - Lecture Notes

Documents in this Course
Radiosity

Radiosity

42 pages

Radiosity

Radiosity

22 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?