Circle code

C

chump1708

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?
Thanks
Prasad
 
V

Vladimir S. Oka

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?
Thanks
Prasad

Asking in comp.programming is possibly a better idea.

If you try to implement this in C, and have questions, you can always
come back here.

Cheers

Vladimir
 
C

CBFalconer

Can anyone give me an idea for drawing a circle without making
use of any floating point computations?

Sure. Take compass, insert pencil in pencil holder, place pointy
end on desired circle center, adjust compass for appropriate
radius, and spin it.

What was your question about the C language?

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
R

Roberto Waltman

Can anyone give me an idea for drawing a
circle without making use of any floating
point computations?

This is not a C language question.
Try asking in "comp.graphics.algorithms",
and/or search for "Bresenham’s Algorithm"

Roberto Waltman

[ Please reply to the group, ]
[ return address is invalid. ]
 
D

Default User

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?


Why? That seems a fairly useless thing to do.



Brian
 
M

Mike Wahler

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?
Thanks
Prasad

Use a compass and a pencil.

I used no floating point calculations in
conceiving or presenting this idea.

-Mike
 
T

tedu

Vladimir said:
If you try to implement this in C, and have questions, you can always
come back here.

this C program draws one circle without any fp:

#include <stdio.h>
int main(int argc, char **argv) {
printf("o\n");
}
 
I

Ico

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?
Thanks
Prasad


Solution #1:
------------

#include <stdio.h>

int main(void)
{
putchar('O');
}

Solution #2:
------------

#include <stdio.h>

int main(int i, char **v)
{
int c='\n',_=-c,y;
for(y=i-c;putc((_*_<c*c-y*y)?0x2a:040,stdout),_<=c;++_);
return((puts("")&&c>y)?main(++i,v):i^i);
}
 
G

Googmeister

Here's the LOGO / differential geometry solution:

repeat
go forward 1 unit
turn right 1 unit
 
V

Vladimir S. Oka

Googmeister said:
Here's the LOGO / differential geometry solution:

repeat
go forward 1 unit
turn right 1 unit

Apart from the original question not being asked by me at all, this is
now way off topic in comp.lang.c! Please trim your cross-posts to
comp.programing only.

Cheers

Vladimir
 
T

tedu

Vladimir said:
This program is not correct C:


return 0;

i was hoping the on-topic requirements here were loose enough to
squeeze a little c99 into the group.
Also I was not the OP.

that post isn't visible to me, which is why i quoted the original
author as well.
 
V

Vladimir S. Oka

tedu said:
i was hoping the on-topic requirements here were loose enough to
squeeze a little c99 into the group.

You're right about the C99. I guess I'll get used to it when there's
more compilers supporting it. I still think that it's good practice to
have something returned from a function that does have a return value.
that post isn't visible to me, which is why i quoted the original
author as well.

Sorry for jumping the gun.

Cheers

Vladimir
 
K

Keith Thompson

Default User said:
Why? That seems a fairly useless thing to do.

It could be very useful for a graphics program running on a system
where integer arithmetic is significantly faster than floating-point
arithmetic. (That doesn't make it topical here, of course.)
 
C

Chris F.A. Johnson

Can anyone give me an idea for drawing a circle without making use of
any floating point computations?

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
long radius = 100, point;
if ( argc > 1 ) radius = strtol(argv[1],NULL,10);
point = radius + 18;
printf( "%!\n%d %d %d 0 360 arc stroke showpage\n", point, point, radius);
return 0;
}
 
J

Jordan Abel

Solution #1:
------------

#include <stdio.h>

int main(void)
{
putchar('O');
}

You need to also output a newline, otherwise the output might never
show. In particular, my system's interactive shell prints a carriage
return and overwrites an unterminated last line of output with its
prompt. Other systems may not flush an unterminated last line to the
output device at all.
 
I

Ico

Jordan Abel said:
You need to also output a newline, otherwise the output might never
show. In particular, my system's interactive shell prints a carriage
return and overwrites an unterminated last line of output with its
prompt. Other systems may not flush an unterminated last line to the
output device at all.

Yes, you are completely right. I guess my suggesions are just bad
examples for the OP's homework.
 
R

Richard Bos

tedu said:
this C program draws one circle without any fp:

#include <stdio.h>
int main(int argc, char **argv) {
printf("o\n");
}

Whether that draws a true circle or only an approximation is
implementation-dependent. On non-Western or oddly configured systems it
could even result in a completely different drawing.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top