UIBezierPath Arc 边缘的物理

Physics on the edge of a UIBezierPath Arc

我正在努力为弧线创建物理。绘制这条弧线我只需要将物理应用于所示的白线。用这段代码绘制。

let position = CGPoint(x: 0, y: 0)
let width = CGFloat(5)
let inner = 300/2-width
let outer = 300/2+width
let start = 3*CGFloat.pi/2-offset
let end = 3*CGFloat.pi/2+offset

let arc = UIBezierPath(arcCenter: position, radius: inner, startAngle: start, endAngle: end, clockwise: true)

let shape = SKShapeNode(path: arc.cgPath)
shape.strokeColor = SKColor.white
shape.lineWidth = 2
shape.fillColor = SKColor.blue
shape.physicsBody = SKPhysicsBody(polygonFrom: arc.cgPath)
shape.physicsBody?.isDynamic = false

self.addChild(shape)

自然物理学应用于整个形状。添加这段代码让我得到了一些更漂亮的东西

arc.addLine(to: CGPoint(x: outer * cos(end), y: outer * sin(end)))
arc.addArc(withCenter: position, radius: outer, startAngle: end, endAngle: start, clockwise: false)

但是与第一个一样,相同的物理学仍然适用。

如何为第二个弧线创建具有适当物理特性的弧线?

编辑:

显示物理效果并使用清晰的颜色,还包括浮动球。

解决了我的问题。这是物理发生器本身的问题。它只会创建凸多边形而不是凹多边形。所以我利用了 中看到的内容。

在我的代码中添加一个循环来创建圆弧的矩形让我得到了一些我可以使用的东西

let points = 8 //number of rectangles/2
var q = CGFloat(start)
var bodies = [SKPhysicsBody]()
for i in 1...(points*2)
{
    let parc = UIBezierPath()
    parc.move(to: CGPoint(x: inner * cos(q), y: inner * sin(q)))
    parc.addLine(to: CGPoint(x: outer * cos(q), y: outer * sin(q)))
    q += (offset/CGFloat(points))
    parc.addLine(to: CGPoint(x: outer * cos(q), y: outer * sin(q)))
    parc.addLine(to: CGPoint(x: inner * cos(q), y: inner * sin(q)))
    parc.close()
    bodies.append(SKPhysicsBody(polygonFrom: parc.cgPath))
}

//adjusting code to allow a physics body from multiple physics body instead of one
//shape.physicsBody = SKPhysicsBody(polygonFrom: arc.cgPath)
shape.physicsBody = SKPhysicsBody(bodies: bodies)