我想将一条贝塞尔曲线分成一条带有n条直线的多边形链.线的数量取决于2条连接线之间的最大允许角度.我正在寻找一种算法来找到最佳解决方案(即尽可能减少直线的数量).
我知道如何使用Casteljau或Bernstein polynomals分割贝塞尔曲线.我尝试将bezier分成两半来计算直线之间的角度,如果连接线之间的角度在一定的阈值范围内,则再次分开,但我可能会遇到快捷方式.
是否有可用于执行此转换的已知算法或伪代码?
我想让 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) 作为填充封闭区域的UIBeizerPath支撑fill()。我的要求是如何从得到的封闭区域UIBeizerPath()相同fill()方法使用。如果我能在寻找 beizerpath 的面积和周长方面得到帮助,我将非常感激。
假设我想获得字母“A”中的封闭区域,我可以获得所有beizerPath CGPoints但不能将子路径定义为 evenOdd 规则用于获取所需的字段属性并最终获取区域。我很想知道如何fill()获得封闭区域。
我得到beizerPath了这个解决方案中的字体,并希望获得从中绘制的任何字体的区域。
我怎么能做到这一点。
我目前正在使用此代码为角色的绘制设置动画:
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) ios ×3
swift ×3
cgpath ×2
uibezierpath ×2
algorithm ×1
bezier ×1
objective-c ×1
polyline ×1
uikit ×1