【问题标题】:Formula for CGPointApplyAffineTransform function in iOSiOS中CGPointApplyAffineTransform函数的公式
【发布时间】:2015-11-28 07:53:58
【问题描述】:

我正在尝试基于 iOS 代码在 Android 中仿射旋转矩阵

iOS有两个函数CGAffineTransformMakeRotationCGPointApplyAffineTransform用于计算

Step 1: CGAffineTransformMakeRotation();

Input: 

2.2860321998596191

Result: 
a = -0.65579550461444569, 
b = 0.75493857771840255, 
c = -0.75493857771840255, 
d = -0.65579550461444569, 
tx = 0, ty = 0

Formula: 

double A = Math.cos(RadiansRotated);

double B = -Math.sin(RadiansRotated);

double C = Math.sin(RadiansRotated);

double D = Math.cos(RadiansRotated);

我可以使用上面的公式计算第 1 步的 a,b,c,d

Step 2: CGPointApplyAffineTransform()

Input : 

x = 612.55191924649432, 
y = -391.95960729287646
And Matrix return from Step 1

Result: 
x = -105.80336653205421, 
y = 719.48442314773808

有人知道 ApplyAffineTransform 中使用的公式吗?

我需要第 2 步的帮助

我尝试过使用 Android 的 Matrix 类 - 不工作

我也尝试过使用 Java 的 AffineTransform - 不工作

【问题讨论】:

    标签: ios math quartz-graphics quartz-2d affinetransform


    【解决方案1】:

    CGAffineTransform 函数背后的数学原理在 “The Math Behind the Matrices” in the Quartz 2D Programming Guide 中进行了描述。

    使用仿射变换变换点的公式如下:

    x' = ax + cy + tx
    y' = bx + dy + ty

    顺便说一句,在你的第 1 步中,你把 b 和 c 的符号颠倒了,这具有反转旋转方向的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多