• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rotating an object around the center of a view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rotating an object around the center of a view


  • Subject: Re: rotating an object around the center of a view
  • From: Erik Buck <email@hidden>
  • Date: Sun, 4 Mar 2007 23:32:15 -0500

There is always a current transformation matrix. When anything is drawn in in a view, the current transformation matrix is used to transform every drawn coordinate into the coordinate system of the parent view (usually all the way to the window's coordinates) even if that transformation is only a translation from bounds to frame.

Due to the wonders of linear algebra (matrix math), all affine transformations have exactly the same cost for transforming coordinate systems. An identity matrix has the same cost and the most complex form of transformation you can construct using combinations of translation, rotation, scale, and skew. [Note however that Cocoa may detect identity or transform only matrices and follow a special path as an optimization...]

So, whether you translate, rotate, scale, skew or not, you incur the same expense to draw. You might as well rotate the coordinate system because it is free (no extra cost).

In contrast, you invert a matrix which is a fairly expensive operation but it has constant cost. Then you transform every vertex in your "dial" which has the same cost as drawing approximately. Then you invert again. Then you finally draw and incur the full cost of transforming every drawn coordinate with the current transformation matrix. This doesn't even address the problem that not all valid affine transforms can be inverted, but that is another issue.

The traditional approach (as shown in the example code I already provided in this thread) is to save state which has a small constant cost, transform the current coordinate system [alter the current transformation matrix], draw in the transformed coordinate system, and restore the previously saved state which has a small constant cost.

The approach you use undoubtedly works. It isn't wrong. It just looks unusual and does not follow the established/traditional design/ pattern. Your approach is also probably less efficient which doesn't really matter in your application. You are also benefiting from the fact that the matrices you create are actually invertable ... some aren't.

I highly recommend reading an introductory graphics programming book that explains the matrix math, matrix concatenation, coordinate transformation, matrix inversion, etc. Many people like "Computer Graphics: Principles and Practice in C" by by James D. Foley (Author), Andries van Dam (Author), Steven K. Feiner (Author), John F. Hughes (Author). This is a common text book.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: rotating an object around the center of a view
  • Next by Date: Re: fopen() works only in debugger
  • Previous by thread: Re: rotating an object around the center of a view
  • Next by thread: NSArray instance variable and core data objects
  • Index(es):
    • Date
    • Thread