Download presentation
Presentation is loading. Please wait.
Published bySamuel Jesse Osborne Modified over 9 years ago
1
1 Computer Graphics Week5 – Shapes & Scan Conversion
2
Shapes and Scan Converting The process by which an idealized shape, such as a line or a circle, is transformed into the correct "on" values for a group of pixels on the computer is called scan conversion and is also referred to as rasterizing. 2
3
1-Line and linear shapes The most popular line-drawing algorithm is the midpoint-line algorithm. This algorithm takes the x- and y- coordinates of a line's endpoints as input and then calculates the x, y-coordinate pairs of all the pixels in between. 3
4
Basic linear shapes such as triangles and polygons can be defined by a series of lines. A polygon is defined by n number of vertices connected by lines, where n is the number of sides in the polygon. A quadrilateral, which is a special case of a polygon is defined by four vertices, and a triangle is a polygon with three vertices 4
5
Relative drawing void moveTo(GlPoint point){ currPoint = point; } void lineTo(GlPoint point) { glBegin(GL_LINES); glVertex2f(currPoint.x,currPoint.y); glVertex2f(point.x, point.y); //draw the line glEnd(); currPoint= point; //update current point to new point glFlush(); } 5
6
6
7
OpenGL geometric primitive types 7
8
2-Circle and hyperbolic shapes The basic mechanics for these algorithms are the same as for lines: figure out the pixels along the path of the shape, and turn the appropriate pixels on. Interestingly, we can also draw a curved segment by approximating its shape using line segments. The smaller the segments, the closer the approximation. 8
9
For example, consider a circle. Recall from trigonometry that any point on a circle of radius r (and centered at the origin) has an x, y-coordinate pair that can be represented as a function of the angle theta the point makes with the axes 9
10
10 Points along a circle
11
11
12
2D-Graphical objects PolyLines- input from -file -interactive (using mouse) -computed (using relative drawing) Curves -implicit form -parametric form 12
13
Drawing circle void drawCircle (Point2 center, float radius) { const int numVerts = 50; // use larger value for a better circle ngon(numVerts, center.getX(), center.getY(), radius, 0); } 13
14
Drawing Arcs void drawArc(GlPoint center, float radius, float startAngle, float sweep) { // startAngle and sweep are in degrees const int n = 30; // number of intermediate segments in arc float angle = startAngle * 3.14159265 / 180; // initial angle in radians float angleInc = sweep * 3.14159265 /(180 * n); // angle increment GlPoint point; point.x=center.x+ radius * cos(angle); point.y=center.y+ radius * sin(angle); moveTo(point); for(int k = 1; k < n; k++, angle += angleInc){ point.x=center.x+ radius * cos(angle); point.y=center.y+ radius * sin(angle); lineTo(point); } } 14
15
Curves Implicit form F(x,y) = 0 Straight line F(x,y)=(y-A 2 )(B 1 –A 1 )-(x-A 1 )(B 2 –A 2 ) Circle F(x,y)= x 2 +y 2 – R 2 Inside – outside function F(x,y) 0 outside the curve 15
16
Curves Parametric form – CurrentPoint = (x(t), y(t)) t Î T Straight line x(t) = A 1 +t(B 1 –A 1 ) y(t) = A 2 +t(B 2 –A 2 ) Ellipse x(t) = A.cos(t) // A is width of ellipse y(t) = B.sin(t) // B is heigth of ellipse 16
17
Drawing ellipse void drawEllipse(GlPoint center,float A,float B) { float cx=center.x; float cy=center.y; GlPoint point; point.x=cx+A; point.y=cy; moveTo(point); for (float t=0.0; t<=TWOPI+0.01; t+=TWOPI/100) { point.x=cx+A*cos(t); point.y=cy+B*sin(t); lineTo(point); } glFlush(); } 17
18
Other conic sections Parabola F(x,y)= y 2 -4ax x(t)=at 2 y(t)=2at Hyperbola F(x,y)= (x/a) 2 - (y/b) 2 -1 x(t)=a/cos(t)y(t)=b.sin(t)/cos(t) 18
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.