Rotating an image changes its dimensions?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Sun Feb 21, 2016 6:23 am

That is an authorative answer :D
Do you remember the 'accuracy' of the first intel chips?
shiftLock happens

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: Rotating an image changes its dimensions?

Post by thatkeith » Mon Feb 22, 2016 4:47 pm

Fascinating stuff. But I do think that some of the answers have gone off on a slight tangent (pun intended) that doesn't necessarily relate to the problem I observed. Setthing the angle of something to 1 will of course mess with its size, but that's not what I was doing. Try this:

1. Drop an image item onto a card. That image will be 120px square.
2. Test it by querying:

Code: Select all

put the width of image 1
3. Now is 'set the angle' to set the angle of that image to 90 degrees. Note: I am NOT setting it to 1 degree first or setting it to 91 degrees. It's being set to precisely 90 degrees.

Code: Select all

set the angle of image 1 to 90
4. Now check the image item's width. It will be 121px, as will its height.
5. Set the angle to 180 and it grows another pixel. Set it to 90 again and it grows a further 1 pixel.

I totally understand that rounding is a factor when setting the angle of something to a non-right-angle, er, angle. But why is it even a consideration when the angle is 90, 180 or 270 degrees?
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10352
Joined: Wed May 06, 2009 2:28 pm

Re: Rotating an image changes its dimensions?

Post by dunbarx » Mon Feb 22, 2016 5:43 pm

Hi.

I just tried a few things:

1- I verified that my earlier test image increased by 1 pixel only at -90.
2- Then I changed height/width to 120,120.
3- Noticed no change at all anymore, setting angles to successive 90° increments.:

Code: Select all

on mouseUp
   set the angle of img 1 to the angle of img 1 + 90
   put the width of img 1 && the height of img 1 into fld 2
end mouseUp
But never saw what you did, that the increment accumulated, growing the image over successive settings.

4. Locked the loc.
5- Now I get 1 pixel increment at 180 AND 270. Sticks when I unlock the loc.

6- imported a new image, set its ht/wd, and locked loc. Ran the angle setting thing, Now it stays at 120,120 all day.

On LC 6.7, OS 10.9

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Tue Feb 23, 2016 1:06 am

@Craig
If you lockloc the size of an image then it should rotate inside that locked box and LC should adjust its size to fit in that locked box, this is just a different game.
An image of locked size 120x80 must stay at size 120x180 whatever angle you rotate it to.

@thatkeith
did you check that your image has no threeD or border activated?
I tested with the attached image at 0 and 90 degrees.
8.0.0-dp15: No change (200x150 rotates to 150x200)
7.1.2-rc3: No change (200x150 rotates to 150x200)
6.7.9-rc3: No change (200x150 rotates to 150x200)

In LC 8 (has a slider) one can watch the image changing its angle while the rect is visible.

In case this depends on OS/Hardware:
Above tests made with Mac 10.11.3/IntelHDGraphics4000.
Attachments
autobahnKlein.jpg
autobahnKlein.jpg (8.8 KiB) Viewed 6815 times
shiftLock happens

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Fri Feb 26, 2016 7:34 am

Hi all,

now I have an example, that changes size here with LC 6/7/8 and a rotation by -90 degrees.
Supports your hypothesis of a bug, because after rotating the point changes where the OFFSET occurs.
1. Take the attached rectangular picture
2. Rotate it by 90 or -90 degrees
3. The size switches from 12x484 to 484x13.

Why may this be a bug and not a a rounding error?

Look at the attached screenshot. The offset I see here is marked (two times).
Now make a line graphic (as my red one) and drag that over and along the image: the offset location of the image changes. You can even push the offset along the image like a fold.

Do you also see such offsets with your example image, or reports it simply a changed size?

Hermann
Attachments
rotatedImage.png
image at 90 degrees (or -90 degrees)
rotatedImage.png (8.45 KiB) Viewed 6796 times
baseImage.png
image at 0 degrees
baseImage.png (698 Bytes) Viewed 6796 times
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Rotating an image changes its dimensions?

Post by bn » Fri Feb 26, 2016 9:12 am

Just wanted to add some fine arts to the discussion about rotate command and images:

use the slider and slide it about 15 to 20 times back and forth and enjoy.

Kind regards
Bernd
Attachments
ImageRotate 3.rev.zip
(2.86 KiB) Downloaded 228 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Fri Feb 26, 2016 11:41 am

Hi Bernd,

the most beautiful demo of the cumulative effect I've seen until now.
We could use this as a wanted "exploding effect".

If we use
     -- sum up trunc(pValue) in a variable SumValue
    set angle of img "aball.png" to 0; add trunc(pValue) to SumValue
    set angle of img "aball.png" to SumValue
instead of
    rotate image "aball.png" by trunc(pValue) --> Bernd shows with that cumulative errors, see attachment

there is here close to no error visible (using scalefactor 2).

Hermann

p.s. Did you already write the report to QCC?
Attachments
exploding.png
Bernd's demo: image after repeated rotating
exploding.png (9.24 KiB) Viewed 6777 times
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Rotating an image changes its dimensions?

Post by bn » Fri Feb 26, 2016 11:55 am

Hi Hermann,
p.s. Did you already write the report to QCC?
no, I think they can not do anything about it and the lesson is to use "angle" not "rotate"
I think there is somthing about rotate in the QCC

As an aside: did you know that the big bang really was a multidimensional "rotate" command running in a endless loop.

Well here in the Forums they tell you the truth and prove it with sample stacks... :)

Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Fri Feb 26, 2016 12:22 pm

This is more interesting than all other work.

Code: Select all

on mouseUp
  set the text of image "aball.png" to the text of image "origImported"
  set the loc of image "aball.png" to 200,300
  repeat N
    repeat with i=1 to m
      rotate image "aball.png" by i
    end repeat
  end repeat
end mouseUp
N=4, m=360 yields an 1256 x 1408 image, looks chaotic.

N=0, the base is an 48 x 48 image:
N=0.png
N=0, the 'base' image
N=0.png (5.96 KiB) Viewed 6772 times
N=1, m=360 is an 146 x 171 image:
N=1.png
N=1, m=360
N=1.png (12.4 KiB) Viewed 6772 times
N=2, m=360 is an 319 x 291 image:
N=2.png
N=2, m=360
N=2.png (37.04 KiB) Viewed 6772 times
I'm currently thinking about how to determine N and m when a goal is given, say closest to 400 x 400. May be this requires chaos theory ...

WOW, from a simple ball, without own math, simply "rotate by", what a software!
Bernd, this is a highlight in your little-stacks-collection!
Must go to THERE!
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Rotating an image changes its dimensions?

Post by bn » Fri Feb 26, 2016 12:26 pm

Hermann,

please be careful with N. See above comment about "Big Bang"

The Universe is going to fill up with "Red Matter"

:) :)

Kind regards

Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Fri Feb 26, 2016 1:17 pm

Bernd, your warnings always sound for me like "This is very interesting, you should try that".

So I did.
Reporting from my full-red-screen (very active colour!):

N=6 yields an 6027 x 6798 image
N=7 still running, takes 6GB (of 8GB) RAM ...
N=7.png
Just now LC crashed, and didn't say any word ... Perhaps a dimension overflow (the 65535-limit for coordinates, that limits every object).

Still cannot see a clear pattern behind that "explosion effect", until now it's "main stream clustering" seems to approximate a logarithmic spiral, should have more N, up to 8, for testing that.

hh

Back to clean my desktop, I set a deadline for that ...

Nice: Writing "(up to 8" & ")" yields a smiley: (up to 8)
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Rotating an image changes its dimensions?

Post by bn » Fri Feb 26, 2016 2:52 pm

For ThatKeith,

here is a stack that lets you turn an image by 90 degrees counterclockwise without changing its dimensions.

It just turns the imageData. In case you have a png with varying transparencies one would have to turn the alphaData also.

Kind regards

Bernd
Attachments
rotateImageLeft90degrees.livecode.zip
(2.27 KiB) Downloaded 206 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Rotating an image changes its dimensions?

Post by [-hh] » Fri Feb 26, 2016 3:35 pm

@thatkeith
Was a really valuable thread you opened!
You should report the one-pixel offset as bug, we can confirm that.

I learned especially the fact that drawing lines between rotated vertices (=graphics) is producing less errors than rotating the pixels of vertices AND of the lines between them (=images). It's obvious now but I didn't see that when reading thatkeith's opening post.

@Bernd,
This is a valuable stack for a lot of users. Should go as a special case into the engine:
The (randomized) one pixel offset could be (at least partially) solved by handling the rotation by multiples of 90 degrees as special cases.

Why not a 'little stack' here and in your collection with all multiples of 90 degrees (for imagedata and alphadata)? You have it already nearly complete ...

Hermann
shiftLock happens

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: Rotating an image changes its dimensions?

Post by thatkeith » Mon Mar 07, 2016 5:36 pm

Hi all,

I'm using 'rotate image 10 by -90' instead of setting the angle and it's working fine. I'm very happy to have helped unearth this bug/buglet, but re reporting it... I don't know if I could possibly explain it as well as recent posters have with those 'big bang' examples. (Which look spectacular btw - I think we're not far from creating a virtual Large Hadron Collider!)

I'll look at the reporting process later, but don't let that stop anyone from doing it themselves. :)
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Post Reply