How do you set the angle of a line graphic?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How do you set the angle of a line graphic?
Am I missing something that simple? One can set the angle of a polygon, but not a line.
Or can one?
Or can one make an angle-settable graphic into something that looks like a line?
Craig
Or can one?
Or can one make an angle-settable graphic into something that looks like a line?
Craig
Re: How do you set the angle of a line graphic?
Hey Craig,
Not sure i'll be of any help... but are you referring to a polygon shape and so on?
A 'line' can't have an angle by definition (it's just 2 points, you need 3 for an angle), unless i'm greatly misunderstanding the question?
Not sure i'll be of any help... but are you referring to a polygon shape and so on?
A 'line' can't have an angle by definition (it's just 2 points, you need 3 for an angle), unless i'm greatly misunderstanding the question?
Re: How do you set the angle of a line graphic?
I guess you could calculate the slope of your line from the coordinates for the two ends of your line.
Or if you knew the slope you wanted, and the coordinates of one end of your line, you could calculate the coordinates of the other end.
EE
Or if you knew the slope you wanted, and the coordinates of one end of your line, you could calculate the coordinates of the other end.
EE
-
- Livecode Opensource Backer
- Posts: 10115
- Joined: Fri Feb 19, 2010 10:17 am
Re: How do you set the angle of a line graphic?
I wonder why item 4 of the points of grc "PG2" is NOT returned, and what
I would expect to be item 4 is returned as item 3:
- -
Is this because there is no comma delimiter between the 2 lines?
And if so, how do I get the 4 items into their respective 'boxes'?
I would expect to be item 4 is returned as item 3:
- -
Is this because there is no comma delimiter between the 2 lines?
And if so, how do I get the 4 items into their respective 'boxes'?
-
- Livecode Opensource Backer
- Posts: 10115
- Joined: Fri Feb 19, 2010 10:17 am
Re: How do you set the angle of a line graphic?
Oh, the erotic frisson from answering one's own questions:
Code: Select all
on scrollBarDrag
put item 1 of line 1 of the points of grc "PG2" into fld "P1"
put item 2 of line 1 of the points of grc "PG2" into fld "P2"
put item 1 of line 2 of the points of grc "PG2" into fld "P3"
put item 2 of line 2 of the points of grc "PG2" into fld "P4"
end scrollBarDrag
Last edited by richmond62 on Sat Nov 21, 2020 9:25 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 10115
- Joined: Fri Feb 19, 2010 10:17 am
Re: How do you set the angle of a line graphic?
Well; there's no risk of this being described as perfect . . .
- -
- -
- Attachments
-
- Angler.livecode.zip
- Here's the stack.
- (2.7 KiB) Downloaded 230 times
Re: How do you set the angle of a line graphic?
This question came from the thread:
http://forums.livecode.com/viewtopic.php?f=7&t=34911
As soon as I wrote it, I realized that, as Stam pointed out, the question makes no sense on the face of it. And I am the one who used a single point as an origin, coupled sequentially with many other points as endpoints, all this to make a line act like a second hand.
Bernd had wonderful ideas in all this.
Anyway, I forgot to delete it.
I was really asking (myself?) for a method to draw a line given some parameters, something like:
I am just fooling around here, and the above has issues, like getting it to work properly in all quadrants. But it is getting late...
Craig
http://forums.livecode.com/viewtopic.php?f=7&t=34911
As soon as I wrote it, I realized that, as Stam pointed out, the question makes no sense on the face of it. And I am the one who used a single point as an origin, coupled sequentially with many other points as endpoints, all this to make a line act like a second hand.
Bernd had wonderful ideas in all this.
Anyway, I forgot to delete it.
I was really asking (myself?) for a method to draw a line given some parameters, something like:
Code: Select all
on mouseUp
drawLine "100,100",30,100 --Origin, Angle, tLength in pixels
end mouseUp
on drawline tOrigin,tAngle,tLength
create grc
set the style of last grc to "line"
add 90 to tAngle
put tan(tAngle / (180 / pi)) into tRatio
put tLength ^ 2 into hypot
put (1 / tRatio) ^ 2 + 1 into factor
put sqrt(hypot / factor) into y
put y / tRatio into x
set the points of last grc to tOrigin & "," & item 1 of tOrigin + y & "," & item 2 of tOrigin + x
end drawline
Craig
Re: How do you set the angle of a line graphic?
So it was simple to implement into all quadrants. But there is a micro-kludge embedded. Anyway. this creates a line graphic starting somewhere at any angle at any length:
Craig
Code: Select all
on mouseUp
drawLine "100,100",30,100 -- Origin, angle in degrees, length in pixels
end mouseUp
on drawLine tOrigin,tAngle,tLength
create grc
set the style of last grc to "line"
put tAngle mod 360 into tAngle
if tAngle = 0 then put 0.001 into tAngle
put tan(tAngle / (180 / pi)) into tRatio
put tLength ^ 2 into hypot
put (1 / tRatio) ^ 2 + 1 into factor
put sqrt(hypot / factor) into y
put y / tRatio into x
if tAngle <= 180 then
set the points of last grc to tOrigin & "," & item 1 of tOrigin + y & "," & item 2 of tOrigin + x
else
set the points of last grc to tOrigin & "," & item 1 of tOrigin - y & "," & item 2 of tOrigin - x
end if
end drawLine
You can do fun things like this:
[code]on mouseUp
repeat with y = 1 to 36
put y * 10 into fld 1
drawLine "100,100",y * 10,100
wait 3
end repeat
end mouseUp
Last edited by dunbarx on Tue Nov 24, 2020 3:38 pm, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 10054
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How do you set the angle of a line graphic?
AFAIK that only applies to "regular" (fixed symmetrical) polygons.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: How do you set the angle of a line graphic?
Richard.
Correct, which is the subject and solution of this thread. I made a gadget that draws a graphic where you need it at any angle at any length. Not technically the answer to my original question, but what I really meant and wanted.
Craig
Correct, which is the subject and solution of this thread. I made a gadget that draws a graphic where you need it at any angle at any length. Not technically the answer to my original question, but what I really meant and wanted.
Craig
-
- Livecode Opensource Backer
- Posts: 10115
- Joined: Fri Feb 19, 2010 10:17 am
Re: How do you set the angle of a line graphic?
NOT rocket science.
- Attachments
-
- Angled Line.livecode.zip
- Here's the stack
- (149.93 KiB) Downloaded 236 times
Re: How do you set the angle of a line graphic?
Richmond.
I had done something like this in the second hand thread, making a large regular polygon of 1800 sides, and setting the points of a line from its center to a point on the polygon. Change that second point at intervals locked to a one minute total travel, and you get a smooth second hand that actually tells time.
I know that neither of our gadgets are rocket science.
But yours does not "draw" a line, based solely on origin, angle and, crucially, length. That requires a right triangle, the tangent function and a kludge.
Craig
EDIT. By "right triangle" I really meant to recall the unit circle, where the x and y coordinates of a line segment drawn from the origin define the tangent function.
I had done something like this in the second hand thread, making a large regular polygon of 1800 sides, and setting the points of a line from its center to a point on the polygon. Change that second point at intervals locked to a one minute total travel, and you get a smooth second hand that actually tells time.
I know that neither of our gadgets are rocket science.
But yours does not "draw" a line, based solely on origin, angle and, crucially, length. That requires a right triangle, the tangent function and a kludge.
Craig
EDIT. By "right triangle" I really meant to recall the unit circle, where the x and y coordinates of a line segment drawn from the origin define the tangent function.
-
- VIP Livecode Opensource Backer
- Posts: 10054
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How do you set the angle of a line graphic?
FWIW I noticed the IDE provides a "Rotate Polygon" section in the "Objects" menu, and curious to see how it worked led me to this handler in revcommonlibrary.livecodescript:
It seems to support just about any angle provided in degrees, and works with both multi-sided polygons and line objects.
Code: Select all
# Parameters
# pGraphic : A reference to a graphic
# pAngle : The angle to rotate the graphic by
# Description
# Performs a rotation transformation whose origin is the loc of the graphic and
# whose magnitude is pAngle degrees. Preserves the topLeft of the graphic, but may
# cause distortion due to rounding errors.
command revRotatePoly pGraphic, pAngle
local tPoints, tFinalPoints
local tLoc
local tSinAngle, tCosAngle
local tCurrentH, tCurrentV, tTransformedH, tTransformedV
local tOrigLeft, tOrigTop
lock screen
lock messages
if the realPoints of pGraphic is empty then
put the effective points of pGraphic into tPoints
else
put the realPoints of pGraphic into tPoints
end if
put the loc of pGraphic into tLoc
put item 1 of tLoc into tOrigLeft
put item 2 of tLoc into tOrigTop
put sin(pi*pAngle/180) into tSinAngle
put cos(pi*pAngle/180) into tCosAngle
repeat for each line tPoint in tPoints
if tPoint is not empty then
put item 1 of tPoint into tCurrentH
put item 2 of tPoint into tCurrentV
put (tOrigLeft+(tCosAngle*tCurrentH)-(tSinAngle*tCurrentV), tOrigTop+(tCosAngle*tCurrentV)+(tSinAngle*tCurrentH) ) after tFinalPoints
end if
put cr after tFinalPoints
end repeat
delete char -1 of tFinalPoints -- is CR
if the style of pGraphic is among the items of "oval,rectangle,roundrect,regular" then
set the style of pGraphic to "polygon"
end if
set points of pGraphic to tFinalPoints
set the realPoints of pGraphic to tFinalPoints
set loc of pGraphic to tLoc
unlock messages
unlock screen
end revRotatePoly
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: How do you set the angle of a line graphic?
Richard.
That handler fails at the line:
That property is not yet defined, so there must be other stuff that happened before.
Anyway
There are ways, as the two threads mentioned indicate, to set the "length", "origin" and "angle" of an existing line graphic. None of these, however, draw such a graphic given only, er, a "length", "origin" and "angle". That is because a line graphic does not have any of those properties. They have to be given, and the graphic constructed from whole cloth.
Craig
That handler fails at the line:
Code: Select all
if the realPoints of pGraphic is empty then
Anyway
indicates that it does not deal with lines at all. Am I wrong?if the style of pGraphic is among the items of "oval,rectangle,roundrect,regular" then
There are ways, as the two threads mentioned indicate, to set the "length", "origin" and "angle" of an existing line graphic. None of these, however, draw such a graphic given only, er, a "length", "origin" and "angle". That is because a line graphic does not have any of those properties. They have to be given, and the graphic constructed from whole cloth.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 10054
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How do you set the angle of a line graphic?
So it would seem. I didn't try it in isolation before posting, only using the IDE's menu items.dunbarx wrote: ↑Mon Nov 23, 2020 6:55 pmRichard.
That handler fails at the line:That property is not yet defined, so there must be other stuff that happened before.Code: Select all
if the realPoints of pGraphic is empty then
I can't say I had occasion to study the code in depth. I just opened the IDE, made a line object, made a two-point polygon, ran the IDE's menu items on each, and grabbed the code to post it here. If I get time later I may explore it in more detail; if you have time you may find something useful by tracing out the calls from the menu items to that handler to make sure those are being used as-is, that there may not be special handling for other types elsewhere in the chain.Anywayindicates that it does not deal with lines at all. Am I wrong?if the style of pGraphic is among the items of "oval,rectangle,roundrect,regular" then
All I can say for sure, based on my test before posting, is that the IDE provides a means of adjusting the angle of both line and polygon objects by arbitrary degrees, so we know the answer is in there somewhere.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn