I'm developing a game for the iPhone, and I have a situation where I have a graphic that the user can drag around the screen and there are some buttons the user can push to both rotate it and enlarge it. The graphic is located within a UIView, which is just a rectangular shape that fits tightly around it.(adsbygoogle = window.adsbygoogle || []).push({});

The thing I'm having trouble with is rotating the graphic, and then translating it so it fits within the UIView correctly. When the user pushes the button to rotate, the first thing I'm doing is calculating the correct size the UIView frame needs to be to fit the rotated object. Then I do the following:

Code (Text):- (CGAffineTransform) transform

{

CGAffineTransform transform = CGAffineTransformIdentity;

transform = CGAffineTransformRotate(transform, (M_PI * self.graphicRotationAngle) / 180);

transform = CGAffineTransformScale(transform, self.graphicSize.width / self.graphic.size.width, self.graphicSize.height / self.graphic.size.height);

transform = CGAffineTransformTranslate(transform, self.graphicSize.width - self.frame.size.width, self.graphicSize.height - self.frame.size.height);

return transform;

}

It makes sense to me that in order to translate the object back to the upper left corner (0,0), i have to subtract the new size of the frame width and height value, minus the non rotated images width and height, and that should give me the translation I need. Yet it's not working, do I have the correct order of operations?

Any help would be appreciated.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Translating Graphic back to Origin after Rotation

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - Translating Graphic Origin | Date |
---|---|

I Left translate back to I in SO(3) | Oct 3, 2017 |

Translation from vector calc. notation to index notation | Feb 2, 2015 |

Distance-preserving maps are compositions of rotations and translations | Dec 21, 2012 |

How to use a 4x4 Matrix to translate a point in 3D space | Dec 8, 2012 |

Game Theory - A graphical solution to all 2-person n x n strategy games? | Jun 10, 2010 |

**Physics Forums - The Fusion of Science and Community**