Page 1 of 1
How to orient an image to a point ?
Posted: Sun Oct 01, 2017 3:48 pm
by jmburnod
Hi All,
I search a way to orient an image to a point.
Is there someone who have a function to get it ?
Thanks in advance
Best regards
Jean-Marc
Re: How to orient an image to a point ?
Posted: Sun Oct 01, 2017 3:52 pm
by Klaus
Bonjour Jean-Marc,
sorry, what do you mean with "orienting an image to a point"?
Best
Klaus
Re: How to orient an image to a point ?
Posted: Sun Oct 01, 2017 5:02 pm
by jmburnod
Hi Klaus,
I try to set the angle of an image according the mouseloc.
Jean-Marc
Re: How to orient an image to a point ?
Posted: Sun Oct 01, 2017 5:08 pm
by Klaus
Ah, thanks, will search my archives!

Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 1:13 pm
by dunbarx
Jean-Marc.
Well, this seems to be what you want, though the image does not seem to like it much, and does not respond very well:
Code: Select all
on mousemove
set the angle of me to the mouseH
end mousemove
So I am thinking I do not understand what you need, and am also not sure why the rotation of the img seems so sluggish.
Of course, the mouseH should be both set and scaled according to the loc and size of the image
Craig
Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 3:01 pm
by jmburnod
Hi Craig,
Imagine you have an image of arrow on cd.
When I clic somewhere on the card, arrow rotate and point to the mouseloc direction
Best
Jean-Marc
Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 8:25 pm
by bn
Hi Jean-Marc,
if I understand correctly what you want have a look at this stack.
It is based on
-- from Jim James Hurley
--
http://runtime-revolution.278305.n4.nab ... l#a4276694
click on every control/image/button
I just saw what exactly you wanted. You would have to adapt the scripts.
Kind regards
Bernd
Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 8:38 pm
by dunbarx
A bit wordy, but I left it as I made it. There is a fld 1 so I could see the angles.
Code: Select all
on mouseMove
if the optionKey is down then
put the loc of img 1 into imgLoc
put the mouseLoc into tMouseLoc
if item 1 of tMouseLoc = item 1 of imgLoc then pass mouseMove
put (item 2 of tMouseLoc - item 2 of imgLoc) / (item 1 of tMouseLoc - item 1 of imgLoc) into vector
put atan(vector) into tAngle ; put tAngle * (360 / (2* pi)) && vector
put trunc(tAngle * (360 / (2* pi))) into fld 1
set the angle of img 1 to trunc(tAngle * (360 / 2* pi))
end if
end mouseMove
The problem is it does not really work. The angles seem OK as one moves the cursor around (though one gets a problem at 90° and -90° if the "pass" line is not there), and there is still an issue with the quadrants, but within even a "working" quadrant, the image does not behave at all.
So.
Hermann, what am I doing wrong?
Everybody, what is up with the image angle setting?
Craig
Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 11:25 pm
by bn
Hi Craig,
this works for me
Code: Select all
on mouseMove
if the optionKey is down then
local tLocI, tMSL, tXI, tXm, tYI, tYm, dX, dY, tA2
put the loc of image 1 into tLocI
put the mouseloc into tMSL
put item 1 of tLocI into tXI
put item 1 of tMSL into tXm
put item 2 of tLocI into tYI
put item 2 of tMSL into tYm
put (tXI - tXm) into dX
put (tYI - tYm) into dY
put ((round(abs (atan2(dY,dX)*180/pi-180))) + 270) mod 360 into tA2
set the angle of image 1 to tA2
put tA2 into field 1
end if
end mouseMove
Kind regards
Bernd
Re: How to orient an image to a point ?
Posted: Mon Oct 02, 2017 11:50 pm
by dunbarx
Lovely.
Mine was hasty and did not even take into consideration proper x and y values. In fact, if I ran the cursor at a perfect 45°, the image does not rotate at all.
Craig
Re: How to orient an image to a point ?
Posted: Tue Oct 03, 2017 9:47 am
by [-hh]
You may have a look at Rotation Control:
http://forums.livecode.com/viewtopic.ph ... 11#p155611
The central function is very simple:
Code: Select all
-- x,y is the mouseLoc
-- x0,y0 is "the point", usually the loc of the image
-- The "90" determines that 0 degrees are at high noon.
constant pi180=57.29577951 -- 180/pi
function getAngle x,y,x0,y0
put x - x0 into dX; put y - y0 into dY
put max(1, sqrt(dX*dX+dY*dY)) into tR0
if dY < 0 then return 90 - acos(dX/tR0)*pi180
else return 90 + acos(dX/tR0)*pi180
end getAngle
Re: How to orient an image to a point ?
Posted: Tue Oct 03, 2017 11:11 am
by jmburnod
Hi Friends,
Thank a lot for help
Here is a stack use Hermann's "very simple central function"
Kind regards
Jean-Marc