How to rotate a square
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
How to rotate a square
Good day all,
So, it's pretty simple what I am trying to do, but it's not sinking in...
How can I create a 100 px wide square, have the ability to rotate it and actually have it keep to right size?
Using LC 7.0.1 I was playing with the Polygon, Regular polygon, Rectangle, etc, etc and got the following:
- If I create a "Rectangle" 100 px wide, I can not rotate it
- If I create a "Regular Polygon" 100 px wide, I need to rotate it 45° to sit square, but the dimensions are smaller (the 100 px seems to reference the "width" when the square is standing on one corner
There's been lots of discussions about rotating "things" but this still seems to be a very difficult process
Attached is a screen shot of what I end up with.
--- ** EDIT ** ignore the image of the "Polygon"
Bottom line, is there a way to create a "Regular Polygon" object with a specified length of a side and be able to rotate it arbitrarily?
Thanks to all.
Dean
So, it's pretty simple what I am trying to do, but it's not sinking in...
How can I create a 100 px wide square, have the ability to rotate it and actually have it keep to right size?
Using LC 7.0.1 I was playing with the Polygon, Regular polygon, Rectangle, etc, etc and got the following:
- If I create a "Rectangle" 100 px wide, I can not rotate it
- If I create a "Regular Polygon" 100 px wide, I need to rotate it 45° to sit square, but the dimensions are smaller (the 100 px seems to reference the "width" when the square is standing on one corner
There's been lots of discussions about rotating "things" but this still seems to be a very difficult process
Attached is a screen shot of what I end up with.
--- ** EDIT ** ignore the image of the "Polygon"
Bottom line, is there a way to create a "Regular Polygon" object with a specified length of a side and be able to rotate it arbitrarily?
Thanks to all.
Dean
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: How to rotate a square
hmmm... this is a weird one.
Try just drawing a rectangle then this;
Or maybe you have already.
Simon
Try just drawing a rectangle then this;
Code: Select all
on mouseUp
set the style of grc 1 to regular
set the angle of grc 1 to the angle of grc 1 + 10
end mouseUp
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
Re: How to rotate a square
Thanks Simon,
Hadn't tried it like that yet, but did with same results. Once the Rectangle style is changed to a Regular polygon, it rotates up on one point and the given dimension is applied to the height/width (based on corner to corner). Rotating it 45° and it's too small again...
To see what I am seeing, I created a new mainstack and ran this code in the Message box:
Cheers,
Dean
Hadn't tried it like that yet, but did with same results. Once the Rectangle style is changed to a Regular polygon, it rotates up on one point and the given dimension is applied to the height/width (based on corner to corner). Rotating it 45° and it's too small again...
To see what I am seeing, I created a new mainstack and ran this code in the Message box:
Code: Select all
create invisible graphic "rectangle"
set width of graphic "rectangle" to 100
set height of graphic "rectangle" to 100
show graphic "rectangle"
wait 2 seconds
lock screen
set style of graphic "rectangle" to regular
set angle of graphic "rectangle" to 45
unlock screen
Dean
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
Re: How to rotate a square
OK, so here it goes again... For some reason, I couldn't get revRotatePoly to work earlier - it kept crashing LC 7.0.1, but now it seems to work - sort of.
If I
- it converts the rectangle to a polygon, it rotates it 45 deg (as specified), but the left side goes missing...
Cheers,
Dean
--- ** EDIT ** this same action happens with either a rectangle or a rounded rectangle, but NOT with a multi-sided irregular polygon
--- ** EDIT 2 ** If a rectangle is rotated using revRotatePoly, it appears as though the 5th set of points gets lost/ignored (the "closing" point). If these are manually entered after rotating the poly, the side closes up. Looks more like a bug at this point. I'll have to reload LC 6.7 and give it a try and submit a bug report if it continues.
If I
Code: Select all
revRotatePoly the name of graphic "Rectangle", 45
Cheers,
Dean
--- ** EDIT ** this same action happens with either a rectangle or a rounded rectangle, but NOT with a multi-sided irregular polygon
--- ** EDIT 2 ** If a rectangle is rotated using revRotatePoly, it appears as though the 5th set of points gets lost/ignored (the "closing" point). If these are manually entered after rotating the poly, the side closes up. Looks more like a bug at this point. I'll have to reload LC 6.7 and give it a try and submit a bug report if it continues.
Re: How to rotate a square
A graphic's dimensions always relate to a square, with the minimum measurements being that required to contain the graphic given its orientation. So while a rectangle can have a width of 100 and you can see the length of the side being 100, when you come to a regular polygon the width does not relate to the length of the side, it is the length of the area required to contain the graphic. The first point of a regular polygon at angle 0 is at the top centre, so a 4 sided regular polygon is equivalent to a square of angle 45 but the length of the sides will be reduced to fit the dimensions of the graphic bounding rect. In this case the width is the diagonal across the middle of the square, which is a simple calculation in terms of pythagoras to relate the sum of the squares of the two adjacent sides to the square of the hypotenuse. To expand the length of the sides of the 4 sided regular polygon to be 100, the width of the graphic has to be expanded to cater for the longer hypotenuse.
For other regular polygons the calculations are also possible, but I couldn't bring myself to make it a generic function
Code: Select all
on mouseUp
--with a rectangle graphic and a regular polygon of 4 sides on the card
set the width of grc "grcSquare" to (random (100) +50)
set the height of grc "grcSquare" to the width of grc "grcSquare"
set the loc of grc "grcSquare" to the loc of this card
put fnPyDim(the width of grc "grcSquare") into tPolyDim
set the width of grc "grcPoly" to tPolyDim
set the height of grc "grcPoly" to tPolyDim
set the angle of grc "grcPoly" to 45
set the loc of grc "grcPoly" to the loc of grc "grcSquare"
end mouseUp
function fnPyDim pSide
return sqrt(pSide * pSide * 2)
end fnPyDim
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
Re: How to rotate a square
Thanks SparkOut,
Thanks for your input, always valued. I guess I was a little lost as to why this occurs the way it does. Although there appears to be a small bug (I've submitted a bug report update) using revRotatePoly, the dimensions of the "Polygon" compared to a "Regular Polygon" are updated and maintained as they should be.
eg. The dimensions of a 100px x 100px Polygon, rotated 45 deg changes to 143px x 143px; rotate another 45 deg and the dimensions change again to 100px x 100px.
In the case of a Regular Polygon, the dimensions are always 143px x 143px, regardles of the angle of rotation of the graphic.
With the submitted bug report update, I hope the problem will be resolved using revRotatePoly instead of angle (at least for now...)
Cheers,
Dean
Thanks for your input, always valued. I guess I was a little lost as to why this occurs the way it does. Although there appears to be a small bug (I've submitted a bug report update) using revRotatePoly, the dimensions of the "Polygon" compared to a "Regular Polygon" are updated and maintained as they should be.
eg. The dimensions of a 100px x 100px Polygon, rotated 45 deg changes to 143px x 143px; rotate another 45 deg and the dimensions change again to 100px x 100px.
In the case of a Regular Polygon, the dimensions are always 143px x 143px, regardles of the angle of rotation of the graphic.
With the submitted bug report update, I hope the problem will be resolved using revRotatePoly instead of angle (at least for now...)
Cheers,
Dean
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How to rotate a square
Hi Dean,
try to set the opaque of the graphic to true before rotating. For a polygon it will close the shape by adding a final point that is the same as the first point of the graphic.
Once you have set it to opaque you can revert to opaque to false. The missing point will be part of the graphic.
Regarding dimensions of rectangle vs polygon of same size see this stack I uploaded here
http://forums.livecode.com/viewtopic.ph ... 31#p106602
I see you have commented on bug 12692 and Bug 13712
Could you post a stack that shows what exactly you are trying to do? Because the problems of this are in the "fine-print".
Do you use the effective points to convert from a Regular Polygon to Polygon?
As I said, try setting the opaque of the graphic to true do your rotating and if you don't want the graphic to remain opaque change it back to non-opaque.
Kind regards
Bernd
try to set the opaque of the graphic to true before rotating. For a polygon it will close the shape by adding a final point that is the same as the first point of the graphic.
Once you have set it to opaque you can revert to opaque to false. The missing point will be part of the graphic.
Regarding dimensions of rectangle vs polygon of same size see this stack I uploaded here
http://forums.livecode.com/viewtopic.ph ... 31#p106602
I see you have commented on bug 12692 and Bug 13712
Could you post a stack that shows what exactly you are trying to do? Because the problems of this are in the "fine-print".
Do you use the effective points to convert from a Regular Polygon to Polygon?
As I said, try setting the opaque of the graphic to true do your rotating and if you don't want the graphic to remain opaque change it back to non-opaque.
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How to rotate a square
Hi Dean,
if you use one of the top graphic objects from the palette then this works for me in LC 6.7.1 and LC 7.0.1 and the release candidates after that.
Kind regards
Bernd
if you use one of the top graphic objects from the palette then this works for me in LC 6.7.1 and LC 7.0.1 and the release candidates after that.
Code: Select all
on mouseUp
set the points of grc 1 to the effective points of grc 1
set the opaque of grc 1 to true
set the style of grc 1 to polygon
revRotatePoly the name of graphic 1, 45
end mouseUp
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
Re: How to rotate a square
@Bernd,
Thanks for the explanation, yes I did read the forum posting late last night and it makes *more* sense now...
As for a sample stack of what I am doing, this isn't something that actually I need, but I was walking through playing with LC when I tripped over it. I was unable to let go until I had it figured out (o.O)
Now another issue pops up, and maybe it is my inexperience with LC, but this is for others trying to figure it out If you resize a polygon and then try to rotate it, it will revert to the original size....
For example:
Create a random sized rectangle freehand using the tool palette tool, assume this rectangle is 106px x 128px
Open the Inspector and change the size to 100px x 100px (it is still of style "rectangle")
If you rotate this via code (like your sample code), the size of the rectangle reverts back to the original dimension of 106px x 128px
- you need to FIRST set the "Lock size and position" using the Inspector or set lockLoc of grc 1 to true
After you rotate the graphic you can turn the lockLoc off again and the polygon maintains the correct size.
Cheers,
Dean
Thanks for the explanation, yes I did read the forum posting late last night and it makes *more* sense now...
As for a sample stack of what I am doing, this isn't something that actually I need, but I was walking through playing with LC when I tripped over it. I was unable to let go until I had it figured out (o.O)
Now another issue pops up, and maybe it is my inexperience with LC, but this is for others trying to figure it out If you resize a polygon and then try to rotate it, it will revert to the original size....
For example:
Create a random sized rectangle freehand using the tool palette tool, assume this rectangle is 106px x 128px
Open the Inspector and change the size to 100px x 100px (it is still of style "rectangle")
If you rotate this via code (like your sample code), the size of the rectangle reverts back to the original dimension of 106px x 128px
- you need to FIRST set the "Lock size and position" using the Inspector or set lockLoc of grc 1 to true
After you rotate the graphic you can turn the lockLoc off again and the polygon maintains the correct size.
Cheers,
Dean
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: How to rotate a square
Dean-
I added a comment to bug report 13712 - the missing endpoint has been corrected in the engine but the rotation script is still awaiting a fix in the IDE library stack.
But please do file a new bug report on the resize thing... you're quite right that rotation after resizing the original graphic reverts the graphic to its original size. I *think* this is not the correct behavior, but it may also be the case that reverting to original size without locking the graphic is desired and/or necessary in some cases, and I'd like to get some feedback from the team before fixing it.
And thanks for uncovering this problem - it's another edge case we hadn't considered.
I added a comment to bug report 13712 - the missing endpoint has been corrected in the engine but the rotation script is still awaiting a fix in the IDE library stack.
But please do file a new bug report on the resize thing... you're quite right that rotation after resizing the original graphic reverts the graphic to its original size. I *think* this is not the correct behavior, but it may also be the case that reverting to original size without locking the graphic is desired and/or necessary in some cases, and I'd like to get some feedback from the team before fixing it.
And thanks for uncovering this problem - it's another edge case we hadn't considered.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
-
- VIP Livecode Opensource Backer
- Posts: 36
- Joined: Thu Jan 03, 2013 6:33 pm
- Location: Floating in the binary mist
Re: How to rotate a square
Hey Mark,
The bug report will have to wait for now. I repeated my exact steps to recreate the problem - and it worked as it is supposed to. Problem fixed itself!!!
Actually, I've run into odd occurrences now and then and should have known to reboot. It seems with LC, if running the IDE all day and enduring a couple "Hibernates", LC has some odd quirks, slow downs., etc. This resizing thing appeared to be an odd quirk that has fixed itself, but I'll keep it in my radar.
Cheers,
Dean
The bug report will have to wait for now. I repeated my exact steps to recreate the problem - and it worked as it is supposed to. Problem fixed itself!!!
Actually, I've run into odd occurrences now and then and should have known to reboot. It seems with LC, if running the IDE all day and enduring a couple "Hibernates", LC has some odd quirks, slow downs., etc. This resizing thing appeared to be an odd quirk that has fixed itself, but I'll keep it in my radar.
Cheers,
Dean
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: How to rotate a square
Ah, indeed. I had tested it with earlier versions, and it did as you described, but that seems fixed now in current 7.x incarnations.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev