# Issues with selecting a drawn circle on graphics

• July 30th, 2011, 11:49 AM
Diplo
Issues with selecting a drawn circle on graphics
In my program I want to first draw two circles then be able to connect them by drawing a line between them. If the line is in each of the circles, the line will draw between them. If not, the line doesn't get drawn. How would I go about this? Would I get the graphics location the circle occupies by calculating the area of the circle? If so, how? Or is there another way?

I've got the code that draws the circles but not sure if it would help find a solution. Let me know if so though and I'll post it.

• July 30th, 2011, 01:15 PM
Norm
Re: Issues with selecting a drawn circle on graphics
Can you explain what you are trying to do?
If you are drawing two circles in a paint method and then you want to draw a line between the two circles, that should be very easy.
Can you explain why drawing the line between the two circles is a problem?
Quote:

If the line is in each of the circles, the line will draw between them. If not, the line doesn't get drawn.
If you are drawing the lines, how does this happen?
Have you taken a piece of paper and drawn where the x and y and width and height of the circles are?
Then compute where on that drawing you want to draw you line. From that you should be able to compute the x and y values to draw the line.
• July 30th, 2011, 02:02 PM
dlorde
Re: Issues with selecting a drawn circle on graphics
Why can you not just draw a line between the centre-points of the two circles?
• July 31st, 2011, 06:21 AM
Diplo
Re: Issues with selecting a drawn circle on graphics
The program is for a shortest path algorithm. The user can draw the nodes (circles) and connect them with vertexs (lines), then calculate the shortest path between them. If they click somewhere on the screen that's a circle, drag across and let go on another circle, the vertex will draw. How do I check whether the place they click is a circle though?

The x and y values of the circle's centre will be stored, do I then calculate what other x and y values the circle occupies on the graphics? Hope I'm making sense!
• July 31st, 2011, 06:34 AM
Norm
Re: Issues with selecting a drawn circle on graphics
Quote:

How do I check whether the place they click is a circle though?
You have two x,y points: the mouse click and the center of the circle.
You also have the radius of the circle. Test if the distance between those two points is less than the radius of the circle.
There was an old Greek guy that had a theorem about right triangles that you could use to compute the distance. Something about squares of the sides of triangle.
• July 31st, 2011, 11:53 AM
Diplo
Re: Issues with selecting a drawn circle on graphics
OK thanks Norm, thought there might be a quicker way like getPixels when it's being drawn. Will use your suggestion though.