Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rotation angle

New Here ,
Jul 09, 2009 Jul 09, 2009

How do you get the rotation angle of a piece of artwork?

How do you rotate a piece of artwork?

I have searched the sample code and all include files for all the suites for "Angle", "Rotate", "Matrix" and there is no call I can see which will easily do either of these.

TOPICS
SDK
6.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Jul 09, 2009 Jul 09, 2009

You could take a look at Transfrom Art Suite.

doc:

Path art objects in Illustrator do not have transformation matrices associated
with them. Although you may be inclined to do so, you will not be able to
simply modify a path object’s current transformation matrix in order to
transform it. Path art objects are simply collections of connected line
segments.
Incidentally, Text art, Raster art, and Placed art, do have transformation
matrices associated with them. With these art types, you have to use specific
accessor functions to get and set each object’s current transformation
matrix.
The Transform Art Suite
The Transform Art suite exports a single function which transforms an arbitrary
art object by a given transformation matrix. This function operates on
all art types and therefore frees the developer from having to write special
transformation routines for the different art type

and use:

AIAPI AIErr TransformArt (
AIArtHandle art,
AIRealMatrix *matrix,
AIReal lineScale,
long flags );

and this to set matrix rotation:

/**    Initializes a transformation matrix to a single rotation.
@param m The matrix object.
@param angle New angle value in radians.
*/
AIAPI void (*AIRealMatrixSetRotate) ( AIRealMatrix *m, AIReal angle );

Regards,

Thomas.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 09, 2009 Jul 09, 2009

As an addendum: getting the rotation angle of art is mainly a matter of getting the matrix for the artwork and then pulling out the rotation from that. Getting the matrix an be tricky though. Every piece of artwork has a matrix associated with it somewhere, but other than specific kinds of art (e.g. kSymbolArt) I've never actually figured out how to get at this matrix. Its a little frustrating too, because there are some calculations you simply can't do without knowing that underlying matrix.

As for applying a rotation, Thomas is dead on the money above. There are some art types that provide more direct ways of applying a rotation (again, kSymbolArt comes to mind) but for the general case you can't beat AITransformArtSuite.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2009 Jul 13, 2009

I have looked through nearly every AI funtion in all the suites.  There are over 150 which accept a rotation angle in radians or a transformation matrix as a parametr to manipulation artwork.  I cannot find a single one which will return the rotation angle or current transformation matirx to me for a text artwork.  Surely AI has to provide this somewhere.  There are many many instances which I need to know the rotation anlge of text so I can add/manipulate other art with it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 13, 2009 Jul 13, 2009

You can use ITextFrame::GetMatrix to get the matrix of a TextFrame object. Ai does not store matrices on all kinds of objects. Though it definitely store matrices on Symbol instances, Bitmaps, Text, etc.

For bitmaps you can use GetRasterMatrix of AIRasterSuite.

For symbols you can use GetSoftTransformOfSymbolArt of AISymbolSuite.

From these matrices you can get the rotation, scale, translate etc. via AIRealMathSuite APIs

Sanjay Kumar,

Illustrator Engineering.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 14, 2009 Jul 14, 2009

You can use ITextFrame::GetMatrix to get the matrix of a TextFrame object. Ai does not store matrices on all kinds of objects. Though it definitely store matrices on Symbol instances, Bitmaps, Text, etc.

For bitmaps you can use GetRasterMatrix of AIRasterSuite.

For symbols you can use GetSoftTransformOfSymbolArt of AISymbolSuite.

From these matrices you can get the rotation, scale, translate etc. via AIRealMathSuite APIs

Thanks Sanjay -- always good to get some official word in here

If all artwork doesn't have a matrix stored, how does one get those rotated bounds we see sometimes? I mean, sure, you could ask for the rotated bounds using GetArtTransformBounds, but you need to know the angle at which to ask -- somehow the built-in AI annotator knows how to draw the edit handles at the right angle, but its not always obvious how to gernate that same bounding box.

For example, if you use the pen tool to draw some random polygon, then select it, it shows the bounds in AI. Now grab a corner and rotate it. The drawn bound handles also rotate. If I was given the handle to that polygon, I have no idea how I'd get those bounds. If I had the angle, sure, I'd just ask GetArtTransformBounds() with the angle. But given a simple path like that, how does one get the angle?

I'd always assumed there some kind of transformation matrix somewhere, but I guess that doesn't make sense for something like a path -- though I'd still like to know where the information is stored that indicates to the selection annotator how to draw that bounding box.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 14, 2009 Jul 14, 2009

The bounding box rotation is a special case and handled via some inner details stored with the art which is updated along with the art transformation and I think that is something which needs a lot of polishing before it can be exposed via API.

Currently it can be assumed that it is not available, Though the rotation for rectangle/ellipses can be found out manually, by calculations via the anchor points.

Here is simple algo for rect

1. First identify if the path is a rect

a. check if the path has 4 anchor points

b. check if the length of 0-3 and 1-2 are same

c. check if the length 0 - 1 and 2 - 3 are same

d. check if length 1 - 2 and 3 - 0 are same

e. check if the in/out points of all anchor are equal to p

2. Now get the angle for 0 - 1.

The angle for the segment 0 - 1 is the angle for the rect.

Note: The length and angle can be found out using the suite AIRealMathSuite.

Hope it helps.

Thanks,

Sanjay Kumar,

Illustrator Engineering.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 15, 2009 Jul 15, 2009

The bounding box rotation is a special case and handled via some inner details stored with the art which is updated along with the art transformation and I think that is something which needs a lot of polishing before it can be exposed via API.

Actually, this helps quite a bit to know. I few times I've been working on other aspects and having the idea lodged in my head that there was some matrix I simply didn't have access to would discourage me into thinking I didn't have all the tools I needed to do the work I was trying to accomplish. Knowing that this isn't the case (and I'll have to beat myself in the head next time I start to think it) will hopefully goad me into keep trying

As for the algo for determining the ellipse/rect angled bounds, that looks pretty good -- thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2009 Jul 15, 2009

Thanks.  At least I know the bounding box rotation specs are not available.  Although I think I can still figure out what i need.  Having compile Issue using the ATE namespace but when I figure them out I can use ITextFrame::GetMatrix to get the matrix/angle of the text art.  I can then rotate back to "0" and draw my rectangle around the text then.  When finished, I can rotate both back to the original angle.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 13, 2009 Oct 13, 2009

Hello Sanjar,

> For symbols you can use GetSoftTransformOfSymbolArt of AISymbolSuite.

> From these matrices you can get the rotation, scale, translate etc. via AIRealMathSuite APIs

Hmm, I can't find any functions in the AIRealMathSuite APIs like
angle = GetAngle( inMatrix) or
scaleX = GetScaleX( inMatrix) or
scaleY = GetScaleY( inMatrix) etc.
do you have any sample code (or is it somewhere hidden in the various samples of the SDK istelf) or has everyone to reinvent the wheel 😞
Thanks
Michael
PS.: In the moment I need only the angle of rotated symbols but who knows what I might need in the future 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 13, 2009 Oct 13, 2009

xtraMike wrote:

Hello Sanjar,

> For symbols you can use GetSoftTransformOfSymbolArt of AISymbolSuite.

> From these matrices you can get the rotation, scale, translate etc. via AIRealMathSuite APIs

Hmm, I can't find any functions in the AIRealMathSuite APIs like
angle = GetAngle( inMatrix) or
scaleX = GetScaleX( inMatrix) or
scaleY = GetScaleY( inMatrix) etc.
do you have any sample code (or is it somewhere hidden in the various samples of the SDK istelf) or has everyone to reinvent the wheel 😞
Thanks
Michael
PS.: In the moment I need only the angle of rotated symbols but who knows what I might need in the future 🙂

The functions you want are:

AIRealMathSuite::AIRealMatrixGetScale()

AIRealMathSuite::AIRealMatrixGetRotate()

The scale method gets you both x & y in one go (well, 'h' & 'v' ).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 13, 2009 Oct 13, 2009
LATEST

And they are so prominently at the end of the file

And thank you very mutch for opening my eyes.

Michael who thought he has look through the whole file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2009 Jul 17, 2009

I used the AITransformArtSuite as suggested.  Used example from sample code.  When I slect an art it does rotate it 45 degrees but throws it off the clipboard.  I do not see anyother parameter I am supposed to use.  Why doe it not rotate the art in place as you would manually?

AIArtHandle theArt

AIRealMatrix matrix;

AIReal angle, radians;

AIReal lineScale = 1.0;

long transformFlags = kTransformObjects;

angle = 45.0;

radians = sAIMath->DegreeToRadian (angle);

sAIMath->AIRealMatrixSetRotate (&matrix, radians);

error = sAITransformArt->TransformArt(theArt, &matrix, lineScale, transformFlags);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 17, 2009 Jul 17, 2009

I believe adding a rotation of 45 degrees like that rotates it around the origin, but I could be mistaken. It's been a while since I messed with matrices, but I believe to add a translation to the origin, then concat on your rotation, then concat the reverse translation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2009 Jul 17, 2009

Thanks Andrew.  That was it.  Had to change to the following.

error = sAIArt->GetArtBounds(theArt, &realArtworkBounds);

artCenter.h = realArtworkBounds.left + (realArtworkBounds.right-realArtworkBounds.left) / 2;

artCenter.v = realArtworkBounds.bottom + (realArtworkBounds.top-realArtworkBounds.bottom) / 2;

sAIMath->AIRealMatrixSetTranslate( &matrix, -artCenter.h, -artCenter.v );

sAIIMath->AIRealMatrixConcatRotate( &matrix, radians );

// move the object back to original position

sAIMath->AIRealMatrixConcatTranslate( &matrix, artCenter.h, artCenter.v );

Now if I can only easily find a way to get the angle of rotateion of a piece of text art

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines