Hi Chantal, [EMAIL PROTECTED] wrote on 10/08/2008 03:13:30 AM:
> I've looked into the transformation matrices and I came up with the > following idea. > I can calculate the matrix after my three transformations. > If I want the image to be in the correct place I have to do a final matrix > transformation: > > current_matrix = transformation_matrix . desired_matrix > > I have a couple of questions: > - Will the above idea give me the desired result Possibly, it can be a useful a tactic to use the current matrix to map points and check if they land where you want them to, and if they don't calculate a correction matrix. > - Is my assumption correct that if I rotate the image not around the > origin, but some other point that the matrix looks as follows: > cos(a) -sin(a) cx > sin(a) cos(a) cy > 0 0 1 No this is not correct. Rotating about a point is roughly equivalent to the sequence of transforms: translate(-cx, -cy) rotate(a) translate(cx, cy) The final combined matrix for that is: cos(a) -sin(a) (x - x*cos(a) + y*sin(a)) sin(a) cos(a) (y - x*sin(a) - y*cos(a)) > - Is my assumption correct that the desired matrix I want looks like this: > 1 0 width_transform > 0 1 height_transform > 0 0 1 If all you want to do is translate the image then yes, your matrix will be as you show it. BTW I have some more comments below... > > What I want is to add a image from disk to my document. > > That image has the correct sizes to fit into a rectangle I draw right > > after placing the image. > > That image is rotated 90 degrees, so I have to rotate it back. Because of > > the rotation, I have to scale the image back to it's original size. To be clear on this rotation has no effect on the images size. So this statement on the face of it doesn't make sense to me. I suspect what is happening is that you are setting the image width and height to that of the destination rectangle, since the image element by default will shrink the image to fit the width and height given your image size changes, but what you should really do if you need to rotate the image is swap the width and height of the image element in anticipation of the rotation to come. > > This all works fine, I have a rotated image at the right size. Now I want to > > place the image into my rectangle. When I try to place the image at the > > correct place (as I think it should be) it doesn't place the image at the > > correct position (it is placed somewhat higher and more to the left as I > > expect it to be). If the image is not square then rotating it around it's center will cause the image to extend either to the left (when the rotation goes portrait to landscape) or above (when the rotation goes landscape to portrait). To get a feel for what happens place something like a credit card so it is nicely aligned with the top left corner of a sheet of paper. Put your finger down on the middle of the card and rotate the card around that point. The left or top edge of the card should end up sticking out from the edge of the paper. This is the 'translate' that the center rotation adds to the image. If you know that you are only going to be doing 90deg rotations you might consider rotating about the origin and then manually translating the image back (try it again with the card, the translate is just the 'old' width vertically (for counter clock wise rotation) and the 'old' height horizontally (for clock wise rotation). > > I think it has something to do with the changed coordinate systems due to > > the rotation and scaling. I can place the image manually with some values > > to the right position, but I like to have a generic solution, because not > > all the documents I generate have the same measurements and sizes. > > > > Is there such a generic solution? Yes, I hope the above at least helps you understand what is happening. > > I hope this clarifies what I want to do, and what exactly is wrong. It helps some. > >> Can you describe what you want where? Simply saying what you > >> have is wrong isn't enough for anyone to help you fix it... > >> > >> > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] >