answersLogoWhite

0

The C language does not provide any support for graphics as standard. C is designed to be as generic as possible, but graphics are a system-specific feature. To use graphics in C you need a third-party graphics library that supports your operating system and hardware, however generic libraries such as OpenGL are available. Nevertheless, it is not possible to draw curves, you can only approximate a curve using a series of short lines. The shorter the lines and the higher the resolution, the smoother the curve will appear.

Assuming you have access to an OpenGL library, you can draw an ellipse as follows:

void DrawEllipse(float cx, float cy, float rx, float ry, int num_segments)

{

const float pi = atan (1) * 4;

float theta = 2 * pi / float (num_segments);

float c = cosf (theta);

float s = sinf (theta);

float x = 1;

float y = 0;

float t;

glBegin (GL_LINE_LOOP);

for (int i = 0; i < num_segments; ++i)

{

glVertex2 f (x * rx + cx, y * ry + cy);

t = x;

x = c * x - s * y;

y = s * t + c * y;

}

glEnd();

}

User Avatar

Wiki User

8y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake

Add your answer:

Earn +20 pts
Q: How you can draw an ellipse in C language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

What does elipticall mean?

isn't it an arty word, like when you draw an ellipse-- so when you see/draw something with an ellipse you call it an elliptical drawing


How can one draw a perfect ellipse?

One can create a perfect ellipse using two pins on a piece of string and a pencil. Place the pins at opposite sides and then loop the string around them. Finally place the pencil in the loops and pull it around the pins to draw the ellipse.


How can you draw an ellipse by arc of circle method when major axis 120mm and minor axis 80mm?

Circular segment


Define the focus and the eccentricity of an ellipse?

A circle is perfectly round, and has one center. An ellipse is like a circle with TWO "centers", and each "center" is called a "focus". The plural of "focus" is "foci". Take a piece of string and tie a loop in each end. Put a pin through the loops, and hold it still in the center of the circle. Place the tip of your pencil at the center of the string, and you can draw a circle by keeping the string taut. Now take TWO pins, and put one pin at each end of the string; place the pins at some short distance apart, and hold them there. Place your pencil and draw, and the shape you draw will be an ellipse. The two pinpoints are the focuses, or foci, of the ellipse. Eccentricity is a measure of how far the ellipse varies from a circle. An ellipse with an eccentricity of zero _IS_ a circle, while an eccentricity of 1.0 is a straight line, with that string stretched out straight. In astronomy, every natural orbit is an ellipse.


What words did Apollonius of Perga introduce into the language of mathematics?

He is credited with introducing the words: ellipse, parabola and hyperbola.