Skip navigation
tony.bell
Currently Being Moderated

Rotation angle

Jul 9, 2009 7:48 AM

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.

 
Replies
  • Currently Being Moderated
    Jul 9, 2009 8:02 AM   in reply to tony.bell

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2009 8:09 AM   in reply to Toto RoToTO

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2009 9:50 PM   in reply to tony.bell

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 14, 2009 10:22 AM   in reply to Sanjay Kumar

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 14, 2009 7:49 PM   in reply to A. Patterson

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 15, 2009 7:21 AM   in reply to Sanjay Kumar

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 17, 2009 2:02 PM   in reply to tony.bell

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 13, 2009 10:26 AM   in reply to Sanjay Kumar

    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 :-)
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 13, 2009 10:52 AM   in reply to xtraMike

    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' ).

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 13, 2009 11:16 AM   in reply to A. Patterson

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points