Page 1 of 1
calculate the points between two objects
Posted: Thu Jan 07, 2010 5:55 pm
by mario baccheschi
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...
Re: calculate the points between two objects
Posted: Thu Jan 07, 2010 6:38 pm
by bn
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
Re: calculate the points between two objects
Posted: Thu Jan 07, 2010 9:03 pm
by dunbarx
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