Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Digitizing Circles

Status
Not open for further replies.

kokoko12000

Programmer
Apr 14, 2003
13
0
0
US
Hi all,
I am new to Tcl/tk. I have problem to solve. I will attach the problem below. I am really not asking the solution for the problem, but I wanted to know from where to start solving the problem. I have a due in four days. So right now I cannot go through all the tutorial stuff to solve it. SO could anyone please suggest me what are the required topics/lessons should I go through to solve this particular problem.

Problem:
Design a program capable of digitizing circles. The system should start with a single window containing a grid of 20x20 points.

All points should start out grey. The user can then click to place the center of a circle, and then drag to set it's radius, similar to various graphics programs. The circle should be drawn on the screen.

When the user releases the mouse button, the program should highlight the points (make them blue) that correspond to the edge of the circle, in a way such that the points could be connected to reconstruct the circle.

Then, two additional circles should be created corresponding to the largest and smallest radius of the highlighted points.


Thank you.

Any suggestions are highyl appreciated.
 
The grid is matter of creating rectangles in a canvas.
Code:
canvas .c -height 200 -width 200
.c create rectangle 0 0 10 10 -fill gray -tags {rect0 rects}
Catching the center is matter of binding the rectangles with a clic proc that'll get the center coords.
Code:
.c bind rects <ButtonPress-1> {clic %x %y}
Tracing the growing circle is matter of binding the rectangles to a move proc that gets the coords.
Code:
.c bind rects <Motion> {move %x %y}
Getting the radius is matter of computing:
Code:
sqr((x2-x1)^2+(y2-y1)^2)
Tracing the circle is matter of creating an oval.
Code:
set circle_index [.c create oval (x1-radius) (y1-radius) (x1+radius) (y2+radius) -fill &quot;&quot; -tags circle]
Growing a circle is matter of redefining its coords.
Code:
.c coords circle <new coords>
Finding the end of the growing is matter of binding the rectangles to a release proc.
Code:
.c bind rects <ButtonRelease-1> {release}
Finding if a rectangle is overlapping the circle (or vice-versa) is matter of checking if the circle index appears in the result of a search.
Code:
set indexes [.c find overlapping x0 y0 (x0+10) (y0+10)]
if {[lsearch $indexes $circle_index]} { .c itemconfig rect$i -fill blue }

So, all is on the canvas page of the manual.
Learn after indexes and tags.

A warning: I oversimplified the expressions.

Good luck

ulis
 
ulis,
thanks for your suggestions. I greatly appreciate it.

Kiran.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top