如何创建一个具有扭曲效果的NSAffineTransform? [英] How do I create an NSAffineTransform with a skew effect?
问题描述
我很喜欢在Cocoa中绘画,并在一个涉及六角网格的实验性应用上工作。为了简化这一点,我想倾斜坐标系,使Y轴向左旋转30度。我在Apple的可可绘图指南,这表明它是可能的:
结合非均匀缩放变换和旋转变换也可能会导致内容偏斜效果。
然而,我无法理解这将如何工作,或找到任何示例。
如何设置NSAffineTransform,使X轴保持水平,Y轴逆时针旋转30度? 解决方案不幸的是,有没有简单的方法来做到这一点,就像变换,旋转等一样。
您必须创建一个变换矩阵:
p> 0 tan(skewy)0
tan(skewx)0 0
0 0 1
使用 setTransformStruct:
与 NSAffineTransformStruct
:
typedef struct _NSAffineTransformStruct {
CGFloat m11,m12,m21,m22;
CGFloat tX,tY;
} NSAffineTransformStruct;
对于偏斜,m11,m22,tx和ty为零; m12是tan(skewx),m21是tan(skewy) Apple的文档中有更多关于矩阵的信息: https:/ /developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-BCIIICJI 希望这有助于! I'm quite new to drawing in Cocoa, and working on an experimental app involving a hexagonal grid. In order to simplify this, I want to skew the coordinate system so that the Y axis is rotated 30 degrees to the left. I came across this in Apple's Cocoa Drawing Guide, which indicates it is possible: Combining a non-uniform scaling transform with a rotation transform can also give your content a skewed effect. However, I cannot understand how this would work, or locate any examples. How can I set up an NSAffineTransform so that the X axis remains horizontal and the Y axis is rotated counteclockwise by 30 degrees? Unfortunately, there is no easy way to do this as you would with transforms, rotations, etc. You have to create a transform matrix: Using For skewing, m11, m22, tx, and ty are zero; m12 is tan(skewx) and m21 is tan(skewy) There is much more information on matrices in Apple's documentation: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-BCIIICJI Hope this helps! 这篇关于如何创建一个具有扭曲效果的NSAffineTransform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
0 tan(skewy) 0
tan(skewx) 0 0
0 0 1
setTransformStruct:
with an NSAffineTransformStruct
:typedef struct _NSAffineTransformStruct {
CGFloat m11, m12, m21, m22;
CGFloat tX, tY;
} NSAffineTransformStruct;