Rotate a line?
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller
Rotate a line?
I have a line that is a radius vector in a circle. I want to rotate the line 30 degrees counter clockwise when I click on a button. Is that possible? (Rotate "angle" does not seem to work for a line graphics. Also I want to rotate around the end point of the line, like a upsidedown pendulum.)
uelandbob@gmail.com

 VIP Livecode Opensource Backer
 Posts: 3901
 Joined: Sat Mar 24, 2007 2:54 am
 Location: Palo Alto
Re: Rotate a line?
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Rotate a line?
Thanks Simon ,
but it doesn't quite answer my question. There was a link there that didn't work and the Harmonic oscillator stack didn't have a line for it's pendulum. So does it mean seems that there is no simple solution?
but it doesn't quite answer my question. There was a link there that didn't work and the Harmonic oscillator stack didn't have a line for it's pendulum. So does it mean seems that there is no simple solution?
uelandbob@gmail.com

 VIP Livecode Opensource Backer
 Posts: 3901
 Joined: Sat Mar 24, 2007 2:54 am
 Location: Palo Alto
Re: Rotate a line?
The link for that stack is under the image
"LiveCode Stack"
But there are a couple more simple versions in the previous link (3 pages)
Simon
Edit;
I see a line in the Pendulum tab???
"LiveCode Stack"
But there are a couple more simple versions in the previous link (3 pages)
Simon
Edit;
Sorry misread that.and the Harmonic oscillator stack didn't have a line for it's pendulum.
I see a line in the Pendulum tab???
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Rotate a line?
Yes but it disappears as soon as you start the pendulum.Simon wrote: I see a line in the Pendulum tab???
A rotation of a simple line shouldn't be rocket science, and the fact that LC has no support for it is somewhat dissapointing
uelandbob@gmail.com

 VIP Livecode Opensource Backer
 Posts: 3901
 Joined: Sat Mar 24, 2007 2:54 am
 Location: Palo Alto
Re: Rotate a line?
hmmm...
This doesn't work for you? It's my sad attempt, not as good as the others.
Simon
This doesn't work for you? It's my sad attempt, not as good as the others.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

 Livecode Opensource Backer
 Posts: 4337
 Joined: Fri Feb 19, 2010 10:17 am
 Location: Bulgaria
Re: Rotate a line?
Play around with this
Re: Rotate a line?
Blaming an IDE for not yet knowing how to do something is somewhat dissapointing.
Re: Rotate a line?
Here's a fresh copy of my Harmonic Oscillators stack:
https://www.dropbox.com/s/wwwrxqehi0173 ... e.zip?dl=0
The Pendulum Tab DOES show a pendulum WITH a line that does NOT disappear on my machine and many others. If your copy's pendulum line disappears, perhaps we can help you with that problem, first of all?
Cheers,
Roger
https://www.dropbox.com/s/wwwrxqehi0173 ... e.zip?dl=0
The Pendulum Tab DOES show a pendulum WITH a line that does NOT disappear on my machine and many others. If your copy's pendulum line disappears, perhaps we can help you with that problem, first of all?
Cheers,
Roger
Re: Rotate a line?
Thanks Roger ,RogGuay wrote:a pendulum WITH a line that does NOT disappear on my machine and many others. If your copy's pendulum line disappears, perhaps we can help you with that problem, first of all?
Roger
You are right. On my machine it disappears and is turned into a point. I'm running version 7.0.0 Build 10018 on a OS X Yosemite version 10.10.1.
As soon as I start to drag the M ball the line (the graphics called PL) disappears, or rather is turned into a point.
uelandbob@gmail.com
Re: Rotate a line?
Hi Bob,
you should always work with the latest version which is 7.02 already. http://downloads.livecode.com/livecode/
Eventual bugs from older version may have been fixed in the meantime
Best
Klaus
you should always work with the latest version which is 7.02 already. http://downloads.livecode.com/livecode/
Eventual bugs from older version may have been fixed in the meantime
Best
Klaus
Re: Rotate a line?
Thanks Klaus , I downloaded 7.02 and tried, but no luck the error persistsKlaus wrote:latest version which is 7.02 already.
uelandbob@gmail.com
Re: Rotate a line?
I just went through the process of trying to find livecode's builtin functions for manipulating geometry and trig and whatnot. They don't exist. Or, rather, there are a couple but they only work for graphics and they only use their "points" which have to be rounded off. After you work with text and buttons and stuff you kind of intuitively want to type "point the thing at the thing" and expect livecode to figure out how to rotate something to point at something else. But it doesn't, so you have to roll your own.
Here are some functions I wrote that solved my problem. They're kind of general so they should solve yours and if they don't they should be easy to reverse engineer. The basic idea is that you should keep the coordinate math separate from the existing controls and their points. When you're all done, round off your coordinates and set them as points.
rotateCoord
This function takes in a list of coordinates (like points but don't have to be whole numbers) and rotates them around their origin (0,0) by the same amount as the bearing (a list of two coordinates, which makes a line). You could convert it to just use a supplied angle instead of calculating it from the bearing.
Here are some functions I wrote that solved my problem. They're kind of general so they should solve yours and if they don't they should be easy to reverse engineer. The basic idea is that you should keep the coordinate math separate from the existing controls and their points. When you're all done, round off your coordinates and set them as points.
rotateCoord
This function takes in a list of coordinates (like points but don't have to be whole numbers) and rotates them around their origin (0,0) by the same amount as the bearing (a list of two coordinates, which makes a line). You could convert it to just use a supplied angle instead of calculating it from the bearing.
Code: Select all
function translateCoord coordinates,newOrigin
 coordinates = a list of coordinates (x,y cr x,y cr x,y etc)
 newOrigin = a coordinate (x,y)
repeat for each line tLine in coordinates
 translate along x axis
put item 1 of tLine + item 1 of newOrigin into tNewX
 translate along y axis
put item 2 of tLine + item 2 of newOrigin into tNewY
put return & tNewX & "," & tNewY after tNewCoord
filter tNewCoord without empty
end repeat
return tNewCoord
end translateCoord
function rotateCoord coordinates,bearing
 coordinates = list of coordinates (x,y cr x,y cr x,y etc)
 bearing = a list of two pairs of coordinates for orientation (x,y cr x,y)
 tested this, it's not the problem
put (item 1 of line 2 of bearing)  (item 1 of line 1 of bearing) into tDistX
put (item 2 of line 2 of bearing)  (item 2 of line 1 of bearing) into tDistY
 tested this, it's not the problem
put atan2(tDistX,tDistY) into tBearingAngle
repeat for each line tLine in coordinates
 calculate angle of coordinates
 tested this, it's not the problem
put atan2(item 1 of tLine,item 2 of tLine) into tAngle
 calculate coordinates' distance from origin
put sqrt((item 1 of tLine)^2 + (item 2 of tLine)^2) into tHypot
 calculate new x coordinate
put tHypot * cos(tAngle  tBearingAngle) into tNewX
 calculate new y coordinate
put tHypot * sin(tAngle  tBearingAngle) into tNewY
put return & tNewX & "," & tNewY after tNewCoord
end repeat
filter tNewCoord without empty
return tNewCoord
end rotateCoord
function batchRoundCoord coordinates
 coordinates = a list of coordinates (x,y cr x,y cr x,y etc)
repeat for each line tLine in coordinates
if tLine is empty then
put return after tNewCoord
else
 round the number off so it can be a point
put the round of item 1 of tLine into tNewX
put the round of item 2 of tLine into tNewY
put return & tNewX & "," & tNewY after tNewCoord
end if
end repeat
return tNewCoord
end batchRoundCoord
function divideLine coordinates,distance
 coordinates = a list of two pairs of coordinates (x,y cr x,y)
 distance = maximum length of each subdivision
put coordinates into tNewCoord
 calculate distance between coordinate pairs
put (item 1 of line 2 of coordinates)  (item 1 of line 1 of coordinates) into tDistX
put (item 2 of line 2 of coordinates)  (item 2 of line 1 of coordinates) into tDistY
put sqrt(tDistX^2 + tDistY^2) into tHypot
if distance < tHypot then
 divide distance in half
put (tDistX / 2) + item 1 of line 1 of coordinates into tMidX
put (tDistY / 2) + item 2 of line 1 of coordinates into tMidY
 coordinates for first half
put line 1 of coordinates into tFirstCoord
put return & tMidX & "," & tMidY after tFirstCoord
 coordinates for second half
put tMidX & "," & tMidY into tNextCoord
put return & line 2 of coordinates after tNextCoord
 call this function on each half
put return & divideLine(tFirstCoord,distance) after tNewCoord
put return & divideLine(tNextCoord,distance) after tNewCoord
else
return tNewCoord
end if
filter tNewCoord without empty
sort tNewCoord ascending
return tNewCoord
end divideLine

 VIP Livecode Opensource Backer
 Posts: 3901
 Joined: Sat Mar 24, 2007 2:54 am
 Location: Palo Alto
Re: Rotate a line?
Hi Bob,
Yes, I'm getting the same in 7.
It works in 6.7
Simon
Yes, I'm getting the same in 7.
It works in 6.7
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Rotate a line?
OK, I know what's wrong. LC V 7 requires that points of a line be handled differently than earlier versions. I will fix my Harmonic Oscillators stack and repost a link to it ASAP.
Thanks,
Roger
Thanks,
Roger