answersLogoWhite

0

There are several options to draw a circle using C or C++ without the built-in functions...

<> <> <> <>

If you can draw a single pixel at a time, use a for loop to iterate Angle from 0 to 2*pi. Then plot a pixel with x=cos(Angle) and y=sin(Angle). Smaller steps will give better results. Lines from one point to the next may look nicer.

Generally, you can use a line from one pixel to the next to draw a polygon. The number of sides is determined by the number of steps from 0 to 2*pi. A circle is a polygon with an "infinite" number of sides (compared to the display resolution). Experiment with non-integral steps to see that the polygon can end at any place. Use an integral number of steps to end where the circle began. Start and stop at fractions of 2*pi, or step backwards, to create arcs. Speed up the code by using lookup tables to calculate sin() and cos(). Hint: they can be the same table, and don't need to be a complete 2*pi circle.

<> <> <> <>

You can also draw the circle without the sin() and cos() functions if you understand the trigonometry behind sin() and cos(). Recall that sin(theta) is radius / y, and cos(theta) is radius / x, given that x and y are the two sides of a right triangle and that radius is the hypotenuse.

By Pythagoream's theorem, x2 + y2 is radius2. It is then simple to solve for x or y, given the other along with radius. You also do not need to compute for the whole circle - you can compute for one quadrant, and generate the other three quadrants by symmetry. You generation loop would, for example, simply iterate from origin to radius as x by delta x, generating y, and reflecting that in the other three quadrants. You can also compute for one half of a quadrant, and use both symmetry and reflection to generate the other seven half quadrants.

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
More answers

You cannot draw any graphics in standard C++. For graphics output you need an appropriate API that supports your platform and hardware. Since this is platform-specific, it is not part of the standard.

User Avatar

Wiki User

11y ago
User Avatar

C++ has no built-in graphics methods. Graphics are platform-specific, but C++ is a generic language. To use graphics you need a graphics library and API that are specific to your platform and hardware. The code you use will therefore be specific to that library.

User Avatar

Wiki User

11y ago
User Avatar

You cannot -- not with a generic C or C++ implementation. Both are designed to be as generic as possible, but graphics are platform-specific. For graphics output, you therefore need a suitable graphics library and API for your specific platform and hardware.

User Avatar

Wiki User

11y ago
User Avatar

C does not provide any native support for graphics manipulation. C is a general-purpose language, not a system-specific language. To add graphics support you must link to a graphics library. Generic libraries such as OpenGL are recommended.

User Avatar

Wiki User

8y ago
User Avatar

Add your answer:

Earn +20 pts
Q: To draw a circle and show its movements using c plus plus graphics?
Write your answer...
Submit
Still have questions?
magnify glass
imp