I know this is a newbie question, but how do I design a circle in Unix C?
I know this is a newbie question, but how do I design a circle in Unix C?
What do you mean?
-How to calculate the dimensions for a given circle??
-How to draw one with dos graphics(I dunno)
-???
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
If you would give us a better expression of what you want,
we could answer to your question!
klausi
When I close my eyes nobody can see me...
I want to know how do I design a circle in Unix C, just using the math.h library and this formula:
x^2 + y^2 = R^2
where r is the radius.
Hello.
Hmm...That sounds more like a mathematical question than a computer programming question. Find a good geometry or trig book, they should tell you there. Good Luck!
Remember, a programmers creativity is more important than any code that they learn, because without creativity, it is impossible to apply that code.
The hard way is to use sin and cosign to calculate a circle. The easy way is to use the Bresenhem algorithm. He also invented one for lines as well. Excellent programming probject to learn how to create graphic primitives.
The Bresenhem circle algorithm essentially does the math required to calculate 1/4 of the circle. It then mirrors the other three quadrant's from the first. Effecient.
enjoy.
Hey guys...
I don't know the answer. But, I think what he wants to know is how to put the pixels onto the screen.
He already has the formula for drawing with center at the origin.
>> x ^ 2 + y ^ 2 = r ^ 2
So, if any1 of you does know it...You should tell him how to put pixels onto the screen...
My Pseudo-code
_____________
for (float x=0;x!=r;x+=1)
{
y = sqrt(r^2 - x^2);
putpixel(x,y,color);
}
for (float x=0;x!=r;x-=1)
{
y = sqrt(r^2 - x^2);
putpixel(x,y,color);
}
-----
or for a better algorithm check out the TUTORIAL pages on this site for Denthor's Grafix Tutorials - i think it's the lesson3
Last edited by Zeeshan; 11-06-2001 at 09:14 AM.