gpt4 book ai didi

rotation - 如何围绕其自身边界的中心旋转 UIBezierPath?

转载 作者:行者123 更新时间:2023-12-02 00:35:04 25 4
gpt4 key购买 nike

假设我们有一个 UIBezierPath...它的边界是完全正方形的...像这样:

func getExponentPath(rotate180: Bool) -> UIBezierPath {

// establish unit of measure (grid) based on this containing view's bounds... (not to be confused with this bezierpath's bounds)

let G = bounds.width / 5

let exponentPath = UIBezierPath()

let sstartPoint = CGPoint(x:(3.8)*G,y:(1.2)*G)
exponentPath.move(to: sstartPoint)
exponentPath.addLine(to: CGPoint(x:(5)*G,y:(1.2)*G))
exponentPath.addLine(to: CGPoint(x:(4.4)*G,y:(0.2)*G))
exponentPath.addLine(to: CGPoint(x:(5)*G,y:(0.2)*G))
exponentPath.addLine(to: CGPoint(x:(5)*G,y:(0)*G))
exponentPath.addLine(to: CGPoint(x:(3.8)*G,y:(0)*G))
exponentPath.addLine(to: CGPoint(x:(3.8)*G,y:(0.2)*G))
exponentPath.addLine(to: CGPoint(x:(4.4)*G,y:(0.2)*G))
exponentPath.addLine(to: sstartPoint)

exponentPath.close()

// this does not work:
// if rotate180 { exponentPath.apply(CGAffineTransform(rotationAngle: CGFloat.pi)) }

return exponentPath

}

如果旋转,此 bezierpath 仍需要在其包含 View 中占据完全相同的区域。

我只能假设这是行不通的,因为旋转中心存在一些问题,不是我想要的……尽管即使说“旋转 0”,我也会得到相同(错误)的结果。

那么路径如何围绕它自己的中心点旋转呢?

似乎应该有一个简单的线性代数矩阵乘法类型可以应用于点集。 =T

最佳答案

extension UIBezierPath
{
func rotateAroundCenter(angle: CGFloat)
{
let center = self.bounds.getCenter()
var transform = CGAffineTransform.identity
transform = transform.translatedBy(x: center.x, y: center.y)
transform = transform.rotated(by: angle)
transform = transform.translatedBy(x: -center.x, y: -center.y)
self.apply(transform)
}
}

关于rotation - 如何围绕其自身边界的中心旋转 UIBezierPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50012606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com