Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Approximate Circles Computers do not draw perfect circles. Because there is only a limited number of pixels, a circle in a computer can only be

image text in transcribed
Approximate Circles Computers do not draw perfect circles. Because there is only a limited number of pixels, a circle in a computer can only be an approximation of a perfect circle. Usually, any smart program does a good job and uses a lot of tricks to make it look good enough that you see it as a perfect circle. However, sometimes the approximation is too rough. At right, you see a circle approximated by 9 line segments (a 9-sided polygon). As more sides are added, the circle gets smoother. In this exercise you will draw polygons of various sizes, controlled by the mouse, to form different approximations of a circle. Version 1 First, use a for loop to draw the example given here, with exactly 9 points. Use the variable int points = 9; (Use a variable, not a constant, because in Version 2 it will be controlled by the mouse.) Use a for loop to draw points lines around a circle, centred in the window, with radius 100 (diameter 200), as shown above. The starting point for the first line will always be at angle 0 (straight out to the right) which will always be the point (width/2+radius, height/2). Every point after that will be at an angle of, in this example, 1/9th, 2/9ths, ..., 9/9ths of the way around the whole circle (2nt radians). Use a line to connect each point to the previous point. You will have to keep track of the previous point using variables. Remember that if you have a circle with its centre at (Xc, yc) and radius r then the point at an angle of o radians around the circle is ( xc + r cos(0), yc + r sin(0)). Version 2 Once you have a 9-sided polygon, use the value mousex/20 to determine the value of points instead. In the draw( ) function, erase the window and draw a new polygon every frame. Watch what happens as you move the mouse from left to right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Classical Mechanics

Authors: R Douglas Gregory

1st Edition

0511159242, 9780511159244

More Books

Students also viewed these Mathematics questions