> Hi everybody, 

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

> 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 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 presume that the "little circle" (lc) should be concentric
        to the endpoint (ep).  Let's suppose you want the circle's
        size to be "r" (think radius)

        I don't see any geometry here. I think that all you have to do 
        is subtract (one offset from each of the x and the y of the
        endpoint) and multiply (simply double the offset) to get the
        lengths of the bounding box (square).

        Here's a picture that might help:

                    x----------+                       
                    |  /^^^^\  |                                         
                    | /      \ |            
                    |(   *    )|            
                    | \      / |
                    |  \____/  |              
                    +----------+           

                The "*" is the endpoint of your line, and the center
                of my incredibly poor circle.

        I'm guessing (with *no* knowledge of Java programming) that
        the x would be the location of the point specified by the
        bouding box (relative to the center of our circle (ep)).
        If that's the case you want to subtract a constant about from
        ep[x] and from ep[y] (the x and y co-ordinates of ep).  Let's
        call these offsets dx and dy respectively.  Thus the upper
        left of our bounding box is at the co-ordinates (dx, dy) for
        any ep[x,y].  

        That's more easily expressed like:

                corner(x) = ep(x) - offset
                corner(y) = ep(y) - offset

        If your function call calls for the co-ordinates of the
        lower right corner you'd change both signs to "+", if
        it requires the upper right you'd add the x and subtract
        the y (assuming that you're using x for horizontal and 
        y for vertical and that these co-ordinates use upper left
        as the origin, like every other computer video graphics
        co-ordinate API I've ever seen), etc.

        (note -- you want a square so the offset is constant --
        i.e. you use the same value for both (unless you have
        to adjust for some uneven aspect ratio).  
        
        So, now all we have to do is figure out the length of 
        the edges of the square.  This will be a simple constant 
        (relative to the offset).  We just double our offset and
        use it for the lengths of both sites of our bounding 
        box.  We know that the * in my diagram will be at the
        center of the square (it is a by product of our method
        of construction).  Our offset is co-incidentally the
        radius of our circle (unless this "drawOval" function
        does something bizarre).

        I'm presuming that the parameter to your drawOval 
        form a bounding box (a form into which the a 
        maximally sized circle will be inscribed).  It 
        would be possible to create a function to "exscribe"
        a circle *around* a rectangle --- but that would be
        much harder to use by programmers since you'd have to
        use the Pythagorean theorem to calculate the radius and
        to figure out any interections betwee the circle that that
        generated and things like the edge of the screen).


> 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 have no idea what the co-ordinates of the start point
        have to do with this, unless you want to radius of the 
        circle to vary with the overall length of the line, or 
        something like that.

        This is a pretty basic question, and your Java documentation
        should include some examples and diagrams to explain this.

        I still can't see why you expect there to be some mysterious
        "geometry" in this --- unless it is simply an utter failure
        to describe the problem (or to understand it on my part).

> Thank you. Please Help.
> Sincerely 
> mich
> P.S.
>  How can I join the newsgroup?

        What newsgroup?  This is a mailing list.

--
Jim Dennis  (800) 938-4078              [EMAIL PROTECTED]
Proprietor, Starshine Technical Services:  http://www.starshine.org

Reply via email to