Solved

How to calculate a circle?

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

by:viktornet
Comment Utility
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
Comment Utility
I'm curious again of which comment/answer helped u the most. o O

Merry Christmas!

-Viktor
--Ivanov
0
 

Author Comment

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

Pierre
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Cheers!

Wang
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Cheers!

Viktor
0
 
LVL 1

Expert Comment

by:slautin
Comment Utility
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
Comment Utility
slautin..... he's got the answer already...no need to continue discussion....
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now