-
Drawing circles
I need your help because I often experience off-by one errors when using graphic functions. I would like to write a Circle function, its prototype should look like this: void Circle(HDC hdc,double x,double y,double r);. It should draw a circle by making a call to Arc function - what will the parameters of Arc look like (use parameters of Circle, of course - i.e. hdc,x,y and r)?
-
Well why dont you simply use the Ellipse() func....
You can still have your Circle func....but like this.....
Code:
void Circle(HDC hdc,int x, int y, int rad){
Ellipse(hdc,x,y,rad + x,rad + y);
}
Not difficult
-
Sorry but I guess you're wrong in some things! First, the ellipse function actually fills the inside of an ellipse with background colour. That is why I want to use Arc function. Second thing is, that calling the ellipse function with parameters you specified will NOT draw a circle with the centre at [x;y] and radius of r. Well, I DO KNOW I should call ellipse(hdc,x-rad,y-rad,x+rad,x+rad) but that IS wrong, you'll experience that nasty off-by-one error as Petzold calls it. So, my question would be: what about ellipse(hdc,x-rad,y-rad,x+rad+1,y+rad+1)? Will that work? FUNNY NOTE: What actually I did was: I wrote the core of my app as a COM DLL server in C++ and I created the user interface in VB, which HAS a circle function :))))))))))))))
-