Solved

How to calculate a circle?

Posted on 1998-12-23
21
616 Views
Last Modified: 2008-02-01
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.

Please help me.

Pierre
0
Comment
Question by:pierre_andersson
  • 11
  • 4
  • 4
  • +2
21 Comments
 

Expert Comment

by:dungdna
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

by:
dwwang earned 150 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

by:viktornet
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 10

Expert Comment

by:viktornet
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

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

Merry Christmas!

-Viktor
--Ivanov
0
 

Author Comment

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

Pierre
0
 
LVL 10

Expert Comment

by:viktornet
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

by:dwwang
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

by:pierre_andersson
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

by:viktornet
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

by:viktornet
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

by:pierre_andersson
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

by:pierre_andersson
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

by:viktornet
ID: 1352779
I explained it above.... When you come to the qestion you have asked there are options you can choose from... You can't choose whose answer to accept directly because there is no way to do that. You need to decide which person help you the most. YOu can see it right at the top of each comment. e.g. viknet, dwwang, and yours is pierre_andersson. When you decide which comment or answer help you the most then if question is answered by a differen peron you reject his.her answer and ask the person who has helped you to answer it. In this case you shgould have rejected dwwang's answer and ask me to propose an answer. When you see that I've propposed an answer then you need to accept my answer with the grade you want. You can choose a grade from A, B, C and D. A is the best and D is the worst. That's how you do it, but don't worry, just learn how to do it from now on...

-Viktor
0
 
LVL 10

Expert Comment

by:viktornet
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

by:dwwang
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

by:viktornet
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

by:dwwang
ID: 1352783
Cheers!

Wang
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1352784
Cheers!

Viktor
0
 
LVL 1

Expert Comment

by:slautin
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

by:viktornet
ID: 1352786
slautin..... he's got the answer already...no need to continue discussion....
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question