On Mon, 20 Jul 1998, Mihail Mihaylov wrote:

->Hi everybody,
->I am a programmer, but unfortunately I am not very good in Geometry and I 
->have the following problem:

me neither, let's see what we can come up with, baring in mind it is 03:33am

->
->I want to add a small circle at the end of a line. Whenever I drag the 
->line, with my mouse or rotate it around, I want the circle to get 
->updated appropriately and to be at the end of that line.
->Example:
->              Start point                     End point 
->                                              and the circle
->              |       
->              |                                    |                  
->              |                                    |  
->              V                                    V
->                                                                              
->              -------------------------------------o
->
->(something like that)
->
->I am writing that code in Java 1.1 ( I hope noone gets offended) and it's 

better than Visual Basic!

->almost ready, except for that little smart calculation part, where I have 
->to find out where exactly to draw the circle, based on the coordinates 
->of the edge's start and end points, which are passed to me, everytime 
->the edge (line) is moved or rotated. To make things even more 
->interesting, in Java the function for drawing circles has the following 
->prototype:
->
->       
->drawOval(int x, int y, int width, int height)
->
->where:
->      these coordinates specify a rectangle, in which my circle (ellipse) 
->should fit.
->
->I am really confused about how to choose that x,y point, that I should 
->pass to the above function, based on the start,end point coordinates of 
->the line.

i assume the x,y in that above refers to the top-left corner of this box.

What you'd need to do is find the co-ords of the end of the line where the
circle needs drawing (call it X,Y)

Then you'd draw the circle (in it's rectangle.. sounds 'different') at an
offset relative to that point (a bit of trial and error)

So you'd have a line from (x,y) to (X,Y) and the circle's co-ords would be
(X,y-k) (or it might be X,y+k depending on where Java sets 0,0) where k is 
whatever value that makes the circle 'look right'. The
first co-ord part (X) will be the same as the x co-ord of the line's end
(because then the circle will touch the line and look like it is stuck to it)

does that sound right?

Reply via email to