Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATransform3D: Calculate height after perspective transform

I have a layer with a height of 50, and I'm rotating it about the x axis. . . How can I calculate the height as the rotation proceeds?

CATransform3D subLayerTransform = CATransform3DMakeTranslation(0, 0, 0);
subLayerTransform.m34 = -1 / 1800; //How does height relate to perspective and angle?
subLayerTransform = CATransform3DTranslate(subLayerTransform, 0, 0, 0);
subLayerTransform = CATransform3DRotate(subLayerTransform, 45 * (M_PI / 180), 1, 0, 0);
_transitionLayer.sublayerTransform = subLayerTransform;
like image 562
Jasper Blues Avatar asked Oct 22 '22 09:10

Jasper Blues


1 Answers

To rotate about the y axis

  • y' = y*cos q - z*sin q
  • z' = y*sin q + z*cos q
  • x' = x

And the height is y1 - y0. Therefor to calculate the new y1 and y0:

CGFloat y0 = 0;
CGFloat y1 = 50;
CGFloat z = -1800; //This relates to the m34 perspective matrix.

y0 = y0 * cos(radians(45)) - z * sin(radians(45));
y1 = y1 * cos(radians(45)) - z * sin(radians(45));

CGFloat newHeight = y1 - y0;
like image 53
Jasper Blues Avatar answered Oct 30 '22 03:10

Jasper Blues