相关疑难解决方法(0)

将贝塞尔曲线转换为多边形链?

我想将一条贝塞尔曲线分成一条带有n条直线的多边形链.线的数量取决于2条连接线之间的最大允许角度.我正在寻找一种算法来找到最佳解决方案(即尽可能减少直线的数量).

我知道如何使用Casteljau或Bernstein polynomals分割贝塞尔曲线.我尝试将bezier分成两半来计算直线之间的角度,如果连接线之间的角度在一定的阈值范围内,则再次分开,但我可能会遇到快捷方式.

是否有可用于执行此转换的已知算法或伪代码?

algorithm bezier polyline

7
推荐指数
2
解决办法
7350
查看次数

Swift:如何向封闭的 CGPath 添加点?

我想让 SKSpriteNodes 沿着字母轮廓移动。我有很多信件,但这是一个例子:

在此处输入图片说明

我希望精灵跟随红线。我发现这个答案主要涵盖了我的问题:Get path to trace out a character in an iOS UIFont

答案来自这个优秀且有效的示例代码:

 let font = UIFont(name: "HelveticaNeue", size: 64)!


var unichars = [UniChar]("P".utf16)
var glyphs = [CGGlyph](count: unichars.count, repeatedValue: 0)
let gotGlyphs = CTFontGetGlyphsForCharacters(font, &unichars, &glyphs, unichars.count)
if gotGlyphs {
    let cgpath = CTFontCreatePathForGlyph(font, glyphs[0], nil)!
    let path = UIBezierPath(CGPath: cgpath)
    print(path)
    XCPlaygroundPage.currentPage.captureValue(path, withIdentifier: "glyph \(glyphs[0])")
}
Run Code Online (Sandbox Code Playgroud)

但是我仍然遇到一个问题,因为我的精灵没有完成所有字母的完整路径,而是例如“P”停在这里(并从底部开始):

在此处输入图片说明

我尝试添加一些点,path例如:

CGPathAddLineToPoint(path, nil, 0, 0)
Run Code Online (Sandbox Code Playgroud)

但结果可能不起作用,因为添加的点在<Close>语句之后:

<UIBezierPath: 0x7889ff70; <MoveTo {25.950001, 55.800003}>,
 <LineTo {25.950001, 95.100006}>, …
Run Code Online (Sandbox Code Playgroud)

cgpath ios uibezierpath swift

4
推荐指数
1
解决办法
2051
查看次数

我如何获得 uibeizerPath 的面积和周长,因为 fill() 方法使用了封闭区域

作为填充封闭区域的UIBeizerPath支撑fill()。我的要求是如何从得到的封闭区域UIBeizerPath()相同fill()方法使用。如果我能在寻找 beizerpath 的面积和周长方面得到帮助,我将非常感激。

假设我想获得字母“A”中的封闭区域,我可以获得所有beizerPath CGPoints但不能将子路径定义为 evenOdd 规则用于获取所需的字段属性并最终获取区域。我很想知道如何fill()获得封闭区域。

我得到beizerPath了这个解决方案中的字体,并希望获得从中绘制的任何字体的区域。

我怎么能做到这一点。

core-graphics objective-c ios uibezierpath swift

4
推荐指数
1
解决办法
261
查看次数

用CGPaths和CAShapeLayers动画绘制字母

我目前正在使用此代码为角色的绘制设置动画:

var path = UIBezierPath()


    var unichars = [UniChar]("J".utf16)
    var glyphs = [CGGlyph](count: unichars.count, repeatedValue: 0)

    let gotGlyphs = CTFontGetGlyphsForCharacters(font, &unichars, &glyphs, unichars.count)
    if gotGlyphs {
        let cgpath = CTFontCreatePathForGlyph(font, glyphs[0], nil)
         path = UIBezierPath(CGPath: cgpath!)

    }
Run Code Online (Sandbox Code Playgroud)

从字符创建bezierpath(在本例中为"J").获取跟踪iOS UIFont中的角色的路径

然后我创建一个CAShapeLayer()并添加动画.

 let layer = CAShapeLayer()
   layer.position = //CGPoint
    layer.bounds = //CGRect()
    view.layer.addSublayer(layer)

    layer.path = path.CGPath

    layer.lineWidth = 5.0
    layer.strokeColor = UIColor.blackColor().CGColor
    layer.fillColor = UIColor.clearColor().CGColor
    layer.geometryFlipped = true

    layer.strokeStart = 0.0
    layer.strokeEnd = 1.0

    let anim = CABasicAnimation(keyPath: "strokeEnd") …
Run Code Online (Sandbox Code Playgroud)

core-animation uikit cgpath ios swift

2
推荐指数
1
解决办法
1534
查看次数