geometry-challenged

Trevor DeVore lists at mangomultimedia.com
Sat Jan 24 18:09:15 EST 2004


On Jan 24, 2004, at 2:26 PM, Richard Gaskin wrote:

> It seems I'm geometry-challenged today -- I know this should be 
> simple, but
> I'm stumped:
>
> I can draw a line object from the loc of one object to the loc of 
> another.
> But if I want to draw only in the space _between_ objects rather than
> intersect them, how do I get the points for the location where a line 
> object
> would meet the edge of the other objects if drawn all the way to their
> centers, as indicated by the "X"s below:
>
>
>     -----------------
>    |                 |
>    |     button1     |
>    |         \       |
>     ----------X------
>                \
>                 \
>            ------X----------
>           |       \         |
>           |     button2     |
>           |                 |
>            -----------------
>

Try something like this:

on mouseUp
   put item 1 of loc of button 2 - item 1 of loc of button 1 into tDeltaX
   put item 2 of loc of button 2 - item 2 of loc of button 1 into tDeltaY
   put atan2(tDeltaY, tDeltaX) into tRadianAngle
   put tRadianAngle * (180/pi) into tDegreeAngle
   put tDegreeAngle into field 1

   put ((width of button 1/2) * cos(tRadianAngle)) + item 1 of loc of 
button 1 into tNewX
   put ((height of button 1/2) * sin(tRadianAngle)) + item 2 of loc of 
button 1 into tNewY
   set loc of graphic 1 to tNewX,tNewY
   put cr & tNewX & ":" & tNewY after field 1
end mouseUp

You will need to add a buffer into tNewX and tNewY to get outside the 
button

-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com



More information about the use-livecode mailing list