calculate the points between two objects

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mario baccheschi
Posts: 13
Joined: Mon Oct 26, 2009 7:30 pm

calculate the points between two objects

Post by mario baccheschi » Thu Jan 07, 2010 5:55 pm

I tray to explain better... ( I hope)
IF I have two objects...I have two LOC ... an X,Y for the first object and an other LOC for the second
so i want calculate the all points ( the all X,Y ) between the two LOC
I want also move an other object to the points which i have found
thanks Mario

MANY THANKS TO Craig Newman

BUT.........
the calculation must be automatic not moving the mouse...
Last edited by mario baccheschi on Fri Jan 08, 2010 3:09 pm, edited 4 times in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: calculate the points between two objects

Post by bn » Thu Jan 07, 2010 6:38 pm

Hi Mario,
could you explain in a little more detail what you want the x,y for, eg. do you want them from the center of an object or a border. Do you want a straight line? Do you want to move the objects along these x,y?
regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: calculate the points between two objects

Post by dunbarx » Thu Jan 07, 2010 9:03 pm

I made a gadget to answer another post recently. I am showing you this so you can play with it and hopefully get some ideas. On a new card, make a straight line graphic at an angle on the screen. This will be "grc 1". Make a button, and name it "test". Put this into its script:

Code: Select all

local x1,x2,y1,y2,xDff,yDiff,slope

on mouseEnter
     put item 1 of line 1 of the points of grc 1 into x1
      put item 2 of line 1 of the points of grc 1 into y1
      put item 1 of line 2 of the points of grc 1 into x2
      put item 2 of line 2 of the points of grc 1 into y2
      
      put y2 - y1  into yDiff
      put x2 - x1  into xDiff
      if xDiff <> 0 then put yDiff / xDiff into slope
end mouseEnter

on mouseMove
   if the mouse is down then 
      put the mouseLoc
      switch 
         case x1 > x2 
            if  the mouseH < x1 and the mouseH > x2  then set the loc of btn "test" to the mouseH & "," & (the mouseH - x1) * slope + y1
            break
         case x1 <x2
            if  the mouseH > x1 and the mouseH < x2  then set the loc of btn "test"  to the mouseH & "," & (the mouseH - x1) * slope + y1
            break
         case x1 = x2
            if  the mouseV > item 2 of the topleft of grc 1 and the mouseV < item 2 of the botRight  of grc 1
            then set the loc of btn "test"  to x1 & "," & the mouseV
            break
      end switch
   end if
end mouseMove

Drag the button. It may take a couple of clicks and drags to initialize its location. It follows the line graphic from one end to the other. I added a line of code to track the loc in the message box.

If you really want a list of all the points between two reference points, you can see that the slope will give you a way to make a list of these. It may not be perfectly accurate, since the math may not follow the pixels, but it will be close. Write back if this is not what you wanted.

Craig Newman

Post Reply