UIBezierPath二次曲线是一条直线

UIBezierPath Quadratic Curve is a Straight Line

我正在尝试创建一个弯曲的箭头以在 ab ARKit 场景中显示,但是,箭头杆的曲率只是在两侧呈现为一条直线。

func createTurnArrow(_ direction: Direction) -> SCNShape {
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 0.2, y: 0)) // A
    path.addLine(to: CGPoint(x: 0, y: 0.2)) // B
    path.addLine(to: CGPoint(x: 0, y: 0.1)) // C
    path.addQuadCurve(to: CGPoint(x: -0.3, y: -0.3), controlPoint: CGPoint(x: -0.3, y: 0.1)) // Curve 1
    path.addLine(to: CGPoint(x: -0.1, y: -0.3)) // D
    path.addQuadCurve(to: CGPoint(x: 0, y: -0.1), controlPoint: CGPoint(x: -0.1, y: -0.1)) // Curve 2
    path.addLine(to: CGPoint(x: 0, y: -0.2)) // E
    path.close()

    return direction == .left ?
      SCNShape(path: path.reversing(), extrusionDepth: self.defaultDepth) :
      SCNShape(path: path, extrusionDepth: self.defaultDepth)
}

我的直觉告诉我用这个函数创建一个节点:

SCNNode(geometry: createTurnArrow(.right))

应该产生这样的形状:

而是在箭头尾部没有任何曲线的情况下渲染它:

我已经尝试了一堆其他数学来获得二次曲线的当前控制点,但没什么好担心的。有什么想法吗?

编辑:

带有标绘点的原理图在哪里以及我对如何用曲线渲染它的假设。

阅读the SCNShape path documentation。它是这样说的:

The path’s flatness (see flatness in NSBezierPath) determines the level of detail SceneKit uses in building a three-dimensional shape from the path—a larger flatness value results in fewer polygons to render, increasing performance.

(因为你在 iOS,用 UIBezierPath 代替 NSBezierPath。)

UIBezierPath 的默认 flatness 是多少? the documentation 是这样说的:

The flatness value measures the largest permissible distance (measured in pixels) between a point on the true curve and a point on the rendered curve. Smaller values result in smoother curves but require more computation time. Larger values result in more jagged curves but are rendered much faster. The default flatness value is 0.6.

现在将默认平面度 (0.6) 与形状的整体大小 (0.5 × 0.5) 进行比较。请注意,平面度大于形状的大小!所以你的每条曲线都变平成一条直线。

将路径的平坦度更改为更适合您的形状的值,或将形状的比例更改为更适合默认平坦度的值。

let path = UIBezierPath()
path.flatness = 0.05 // <----------------------- insert this statement
path.move(to: CGPoint(x: 0.2, y: 0)) // A
path.addLine(to: CGPoint(x: 0, y: 0.2)) // B
// etc.