Solved

How to calculate a circle?

Posted on 1998-12-23
613 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

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 150 total points
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

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

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

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

Merry Christmas!

-Viktor
--Ivanov
0

Author Comment

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

Pierre
0

LVL 10

Expert Comment

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

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

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

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

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

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

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

LVL 10

Expert Comment

-Viktor
0

LVL 10

Expert Comment

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

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

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

Cheers!

Wang
0

LVL 10

Expert Comment

Cheers!

Viktor
0

LVL 1

Expert Comment

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

0

Featured Post

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have toâ€¦
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi databaseâ€¦
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filledâ€¦
This tutorial demonstrates a quick way of adding group price to multiple Magento products.