VIEWS: 8 PAGES: 39 POSTED ON: 4/1/2011
Approaches to Infinity CVGLab Goals of the Chapter To examine the effective use of repetition and recursion in creating figures. To extend the ability to visualize complex patterns. To use recursion to draw space-filling curves. To construct fractal curves and trees. To examine fractal image compression. To examine the nature, and construct pictures of, the Mandelbrot and Julia sets. To develop methods for “fractalizing” a curve using random fractals. Introduction Repetition -. Will do something again and again without complaint complaint. -. The high precision with which modern computers can do calculations allows an algorithm to take closer and closer “looks” at an object, effectively “zooming in” to ever greater levels of detail. Fractals and Self-similarity Recursion – open makes a difficult geometric task extremely simple. Recursive algorithms – con give rise to shapes that are both lovely and intriguing or that have useful applications in science and engineering. Self-similar – appear “ the same” at every scale. exactly self-similar – the enlargement looks exactly like the original. Statistically self-similar – the wiggles and irregularities in the curve are the same “on the average,” Fractals – various forms of self-similar curves. Fractals and Self-similarity 1. Successive Refinement of Curves -. Koch curve : to form Kn+1 from Kn; Fractals and Self-similarity 2. Drawing Koch Curves and Snowflakes -. N : the order of the curve Kn the order-n Koch curve consists of four versions of the order (n-1) Koch curve. Fractals and Self-similarity 3. Fractional Dimension -. Dimension : appears in the exponent of N 1 r 1 Where, an object has dimension D if, when it is N D subdivided into N equal parts. log( N ) D 1 log( ) r -. Peano curves String Production and Peano Curves L-Systems – to draw complex curves based on a simple set of rules. A command to perform some operation: -. „F‟ means forward (1, 1) (go forward visibly a distance 1 in the current direction). -. ‘+’ means turn (A) (turn right through angle A degrees). -. „-‟ means turn (-A) (turn left through angle A degrees). World Windows and Viewports 2. Setting the Window and Viewport Automaticall Setting of the Window -. Extent(or bounding box) -. For finding the routine the extend may have to be run twice, a different way each time: Pass1. Execute the drawing routine, but do no actual drawing;just compute the extent. Then set the window. Pass2. Execute the drawing routine again. Do the actual drawing. World Windows and Viewports Automatic Setting of the Viewport to Preserve the Aspect Ratio. -. A common wish is to find the largest such viewport that will fit inside the screen window on the display. World Windows and Viewports Resizing the Screen window; the Resize Event -. Resize : typically by dragging one of its corners with the mouse. glut ReshapeFunc (myReshape); // specifies the function called on a resize // event void myReshape (Glsizei W, Glsizei H); Making a Matched Viewport -. Using a reshape function to set the largest matching viewport upon a resize event Clipping Lines Clipping – a fundamental task in graphics, needed to keep those parts of an object that lie outside a given region from being drawn. 1. Clipping a Line the Cohen-Sutherland clipper: a classic line-clipping algorithm • like segment CD, the function returns a value of 1. • like segment AB, the function returns a value of 0 • like segment ED, the function clips the portion of the segment that lies outside the window and returns a value of 1. • like segment AE, the function clips both ends and returns a value of 1. Clipping Lines 2. The Cohen-Sutherland Clipping Algorithm -. “trivial accept” : no clipping(a large window). -. “trivial reject” : nothing is drawn(a small window). Testing for a Trivial Accept or Trivial Reject -. “inside-outside code word” Clipping Lines • Trivial accept: Both code words are FFFF; • Trivial reject: The code words have a T in the same position; both points are to the left of the window, or both are above, etc. Clipping Lines Chopping When There Is Neither Trivial Accept nor Trivial Reject d e , dely delx where e is pl.x W .right and the statements delx p 2.x p1.x; dely p 2. y p1. y; dely p1. y (W .right p1.x) delx Clipping Lines Developing the Canvas Class • Canvas class -. Provides a handy drawing canvas on which to draw the lines, polygons, etc. of interest. -. This class provides simple methods for creating the desired screen window and establishing a world window and viewport, and it ensures that the window-to-viewport mapping is well defined. Developing the Canvas Class 1. Some Useful Supporting Class Class Point2 : A Point Having Real Coordinates. class Point2 { public: Point2() {x = y = 0.0f;} //constructor1 Point2 (float xx, float yy) {x = xx; y = yy;} //constructor2 void set (float xx, float yy) {x = xx; y = yy;} float getX () {return x;} float getY () {return y;} void draw (void) {glGegin (GL_POINTS); glVertexf ((GLfloat)x, (GLfloat)y); glEnd ();} private: float x, y;}; Developing the Canvas Class Class IntRect : An Aligned Rectangle with Integer Coordinates class IntRect { public: IntRect () {1 = 0; r = 100; b = 0; t = 100;} // constructors IntRect (int left, int right, int bottom, int top) {l = left; r = right; b = bottom; t = top;} void set (int left, int right, int bottom, int top) {l = left; r = right; b = bottom; t = top;} void draw (void) // draw this rectangle using OpenGL private: int l, r, b, t; }; Developing the Canvas Class Class RealRect : An Aligned Rectangle with Integer Coordinates class RealRect { same as intRect except use float instead of int }; Developing the Canvas Class 2. Declaration of Class Canvas Developing the Canvas Class 3. Implementation of Class Canvas Developing the Canvas Class Relative Drawing 1. Developing moveRel() and lineRel() -. moveRel(), lineRel(): “moves” the CP through the displacement (dx, dy) Relative Drawing 2. Turtle Graphics -. Three functions: 1) turnTo (float angle): void Canvas : : turnTo (float angle) {CD = angle;} 2) turn (float angle): void Canvas : : turn (angle) {CD += angle;} 3) forward (float dist, int isVisible) void Canvas:: forward(float dist, int isVisible) { const float RadPerDeg = 0.017453393; //radians per degree float x = CP.x + dist * cos(RadPerDeg * CD); float y = CP.y + dist * sin(RadPseDeg * CD); if(isVisible) lineTo(x, y); else moveTo(x, y);} Figures Based on Regular Polygons 1. The Regular Polygons Definition: A polygon is regular if it is simple, if all its sides have equal lengths, and if adjacent sides meet at equal interior angles. -. n-gon: to a regular polygon having n sides. Figures Based on Regular Polygons Pi ( R cos(2i / n), R sin(2i / n)), for 1,..., n 1 Figures Based on Regular Polygons • Drawing a hexagon. for (i = 0; i < 6; i++) { cvs.forward(L, 1); cvs.turn(60); } A 7-gon and its offspring Drawing Circles and Arcs • Drawing a circle is equivalent to drawing an n-gon that has a large number of vertices. 1. Drawing Arcs -. Defining an arc. Drawing Circles and Arcs • drawCircle(): -. By specifying a center and radius. -. The center is given, along with a point on the circle. -. Three points are given through which the circle must pass. Using the Parametric Form for a Curve • Two principal ways to describe the shape of a curved line: -. implicitly -. Parametrically • Implicit form: describes a curve by a function F(x, y) that provides a relationship between the x and y coordinates. F ( x, y ) 0. F ( x, y ) ( y Ay )(Bx Ax ) ( x Ax )(By Ay ) F ( x, y ) x 2 y 2 R 2 • inside-outside function F ( x, y ) 0 for all ( x, y ) on the curve, F ( x, y ) 0 for all ( x, y ) outside the curve, and F ( x, y ) 0 for all ( x, y ) inside the curve, Using the Parametric Form for a Curve • single valued in x : y g ( x) F ( x, y ) y g ( x ) in y : x h( y ) F ( x, y ) x h ( x ) • not single valued y R2 x 2 Using the Parametric Form for a Curve 1. Parametric Forms for Curves Examples: The Line and the Ellipse -. line : parametric form that visits A at t = 0 and B at t = 1, x(t ) Ax ( Bx Ax )t and y (t ) Ay ( B y Ay )t. -. ellipse : parametrically by x(t ) W cos(t ) and y (t ) H sin(t ), for 0 t 2 , where, W is " half width" H is " half height" Using the Parametric Form for a Curve Finding an Implicit Form from a Parametric Form x 2 y ( ) ( ) 2 1. W H 2. Drawing Curves Represented Parametrically Using the Parametric Form for a Curve Superellipses -. Implicit formula x n y ( ) ( ) n 1, where n is bu lg e W H -. parametric representation x(t ) W cos(t ) | cos(t ) 2 / n1 |, y(t ) H sin(t ) | sin(t ) 2 / n1 |, for 0 t 2 -. n > 1 the bulge is outward, n < 1 the bulge is inward, n = 1 the supercircle becomes a square. Using the Parametric Form for a Curve • superhyperbola -. parametric representation x(t ) W cos(t ) | sec(t ) 2 / n1 |, y (t ) H sin(t ) | tan(t ) 2 / n1 |, for 0 t 2 -. n = 1 becoming straight n < 1 pinching inward Using the Parametric Form for a Curve 4. Polar Coordinate Shapes -. Polar coordinates x(t ) r (t ) cos( (t )) x f ( ) cos( ) and y(t ) r (t ) sin( (t )). y f ( ) sin( ) -. Examples of curves with simple polar forms. . Cardioid: f(θ) = k(1 + cos(θ)). . Rose curves: f(θ) = k cos(nθ), where n specifies the number of petals in the rose. Two cases are shown. . Archimedean spiral: f(θ) = kθ. Using the Parametric Form for a Curve -. conic sections 1 f ( ) 1 e cos( ) Where e is the eccentricity of the section for e = 1, the shape is a parabola; for 0 <= e < 1, it is an ellipse; And for e > 1, it is a hyperbola. -. Logarithmic spiral f ( ) kea Where a = cot(α) Using the Parametric Form for a Curve 5. 3D Curves P(t ) ( x(t ), y(t ), z (t )) The helix x(t ) cos(t ) y (t ) sin(t ) z (t ) bt , The toroidal spiral x(t ) (a sin(ct ) b) cos(t ) y(t ) (a sin(t ) b) sin(t ) z (t ) a cos(ct )