Solved

# How to calculate a circle?

Posted on 1998-12-23
Medium Priority
628 Views
Hello.

My version of Delphi dosn't have a circle function where i can give a x and a y position and a radius. I wonder if there are anyone that have a delphi routine to calculate a circle from x,y and radius and then plot it in a canvas.

Pierre
0
• 11
• 4
• 4
• +2

Expert Comment

ID: 1352766
In fact, I do think that the Canvas object of any Delphi version
support Circle methods. Could you tell me which version you're using ?
Writing a routine that plot a circle to a canvas is somewhat easy. You can use Bresenham algorithm to do it.

0

LVL 4

Accepted Solution

dwwang earned 600 total points
ID: 1352767
Circle(x,y,r)=
Ellipse(X1, Y1, X2, Y2: Integer);

According to you requirement,
X1:=x-r;
Y1:=y-r;
X2:=x+r;
Y2:=y+r;
0

LVL 10

Expert Comment

ID: 1352768
There is... Try this,,,

Form1.Canvas.Circle(<parameters>);

if you really don't have one here is something I did..

procedure Circle(x, y, radius : Integer; Where : TForm; Color : TColor);
var
theta : integer;
begin
for theta := 0 to 359 do
Where.Canvas.Pixels[x + round(cos(theta) * radius), y + round(cin(theta) * radius)] := Color;
end;

and an example call would be....

Circle(Width shr 1, Height shr 1, 50, Form1, clBlack);

This would draw a circle right in the middle of Form1 with a radius of 50 in a black color

This should help you. If not let me know. I think you should have a TCanvas type which should do it. If you don't have the TCanvas type then you should use the Device Context in order to do and that's pretty easy actually... anyway, let us know what you think...

Merry Christmas!

-Viktor
--Ivanov
0

LVL 10

Expert Comment

ID: 1352769
oopss...i already see a mistake.... where it says
y + round(cin(theta)
it should be
y + round(sin(theta)

sorry for that ;-)

-Viktor
0

LVL 10

Expert Comment

ID: 1352770
I'm curious again of which comment/answer helped u the most. o O

Merry Christmas!

-Viktor
--Ivanov
0

Author Comment

ID: 1352771
The second example (Procedure Circle) worked very good. Thanks for the help.

Pierre
0

LVL 10

Expert Comment

ID: 1352772
Well, then you should have accepted my answer, and not Wang's... I'm sick and tired to give the correct information that is needed and then other people get the credit... That's the thing I hate the most...
0

LVL 4

Expert Comment

ID: 1352773
Hi, Vik

I think you comment can help pierre, however, I post the answer first, also I think the answer should work. So is there anything wrong?

Still remember? In another topic you had just asked others not to argue about the points  :-)

Regards,
Wang
0

Author Comment

ID: 1352774
Ok, im sorry but i don't know how to choose what expert to give the points to.

Can i give points to both of you?

Pierre
0

LVL 10

Expert Comment

ID: 1352775
It's nothing wrong with your answer, but if his version doesn't have Circle than it doesn;t have Ellipse also...but i think the person has mistakenb something and it does have both,,, probably....anyway, even if s/he doesn't have it my soltion will still work... Yeah, I argued 'cuz the person was trying to get the point w/o giving any help... At least that's what happened at the last topic I argued about points and answers... The person that needed help was giving away 500 points and the other person just said I'll do your program and locked the question. He didn't show up in a couple of days, but at the same time another person did the program and it worked perfectly so he was trying to get the credit. He couldn't do it 'cuz the other guy had locked the question w/o giving any help... I'm not about the points, but I like to get the credit that i deserve.

I think you are a great person, and that your answr was correct, but if he doesn't have the Circle() procedure, he won't have the Ellipse() also so therefore, it's inncorrect... Even the person said that my procedure helped him do his job, which means that I deserve the credit... I don't wanna waste my time if i don't get any credit for it. Actually I think I have not wasted my time here since I learned a lot of things here on EE and I really respsect that. Don't worry Wang, it's not you. I've given the correct answr so many times and the other people get the credit most of the time 'cuz they answered first and there are times when their proposed answrs are incorrect...

-Viktor
--Ivanov
0

LVL 10

Expert Comment

ID: 1352776
Pierre it's Ok, I understand you're new to EE, so it's okay. Keep the points for some important questions, no need to wasted them on me. Just to tell, you. If you like someone's answer better than the one that is proposed you just reject the current and ask the person who helped you out to answer(lock) the question so you can accept his/her answer and give the credit for his work.

Happy New Year ( well almost :)

-Viktor
--Ivanov
0

Author Comment

ID: 1352777
Hello.

I am new to the experts exchange and i don't know how to choose wich expert to give the credits to.

HOW DO I CHOOSE WHICH EXPERT TO GIVE THE CREDITS TO?

I am sorry if i gave the credits to the wrong expert because procedure circle is the answer i can use not ellipse.

Pierre
0

Author Comment

ID: 1352778
But how can i choose how to reject the only think i can do is add a comment?
0

LVL 10

Expert Comment

ID: 1352779

-Viktor
0

LVL 10

Expert Comment

ID: 1352780
There is an option that says REJECT. You click on that and probably press the button that says Submit, I don't remember how it is because I don't have any questions openned at the moment...

-Viktor
0

LVL 4

Expert Comment

ID: 1352781
Hi, vik, agree with you this time, cuz I met such situation many times in this site too -- some one even propose an answer with same contents as my already-posted comment :)

Also I had thought of one who have no circle function could not access elipse either, however, after checking methods of TCanvas, I see there is no circle methods at all, but with Ellipse. So until now I insist that my answer is correct and deserve the points, although this is not the problem, right? :)

Good luck every one!

Happy new Year!

Wang
0

LVL 10

Expert Comment

ID: 1352782
WAng, that's exactly what I was talking about so I agree with you. About the TCanvas I also agree that there is no Circle procedure the way to do it is using Ellipse(), but it can also be done in an easier manner as I proposed... so I think as long as Pierre is satisfied, then there is no problem. Let's just forget all this and be friends...

Happy New Year!

-Viktor
--Ivanov
0

LVL 4

Expert Comment

ID: 1352783
Cheers!

Wang
0

LVL 10

Expert Comment

ID: 1352784
Cheers!

Viktor
0

LVL 1

Expert Comment

ID: 1352785
Try API Ellipse function - draws an ellipse too.

BOOL Ellipse(
HDC  hdc,           // handle of device context
int  nLeftRect,  // x-coord. of bounding rectangle's upper-
//left corner
int  nTopRect,   // y-coord. of bounding rectangle's upper-
//left corner
int  nRightRect, // x-coord. of bounding rectangle's lower-
//right corner
int  nBottomRect // y-coord. bounding rectangle's f lower-
//right corner
);
0

LVL 10

Expert Comment

ID: 1352786
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
###### Suggested Courses
Course of the Month5 days, 16 hours left to enroll