swift - Swift - 删除相交的线
问题描述
帮助!如何删除相交的线,这样我就只有外部形状了?
我需要对此进行哪些更改才能删除相交线?
let width = 300
func circle(withRadius radius: CGFloat) -> UIView {
let path = UIBezierPath(arcCenter: CGPoint(x: width * (1/2), y: width * (1/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true)
path.append(UIBezierPath(arcCenter: CGPoint(x: width * (1/3), y: width * (2/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true))
path.append(UIBezierPath(arcCenter: CGPoint(x: width * (2/3), y: width * (2/3)), radius: 80, startAngle: .zero, endAngle: .pi * 2, clockwise: true))
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.black.cgColor
shapeLayer.lineWidth = 3.0
backView.layer.addSublayer(shapeLayer)
return backView
}
解决方案
在一般情况下,您需要求解一个二次方程来计算圆相交的点。圆的方程是 (x-x0)^2 + (y-y0)^2 = r^2,其中 (x0,y0) 是圆心。但是我发现了一些类似的点来确定宽度和半径的值。
let width: CGFloat = 300
let radius: CGFloat = 80
let point1 = CGPoint(x: width * (1/2), y: width * (1/3))
let point2 = CGPoint(x: width * (1/3), y: width * (2/3))
let point3 = CGPoint(x: width * (2/3), y: width * (2/3))
circle(center: point1, withRadius: radius, startAngle: .pi - .pi/10, endAngle: .pi * 2 + .pi/10)
circle(center: point2, withRadius: radius, startAngle: .pi / 3.5, endAngle: .pi / 3.5 + .pi * 1.11)
circle(center: point3, withRadius: radius, startAngle: .pi * 1.6, endAngle: .pi * 1.72 + .pi)
func circle(center: CGPoint, withRadius radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat) {
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.black.cgColor
shapeLayer.lineWidth = 3.0
backView.layer.addSublayer(shapeLayer)
}
推荐阅读
- java - Volley GET JsonObjectRequest 未按顺序执行,响应稍后到达
- php - 找不到类“App\Http\Controllers\Auth\GuzzleHttp\RequestOptions”
- javascript - 向外部服务器发送 POST 请求时,Node 给我一个“证书链中的自签名证书”错误
- python - logits 和 labels 必须具有相同的第一维,得到 logits 形状 [32,1] 和标签形状 [80000]
- python - TypeError:只能将元组(不是“浮动”)连接到元组
- angular - querySelectorAll 不能与 Angular 一起使用,但可以在控制台中使用
- html - css 混合/模糊/合并背景图像
- javascript - 如何使用 Rxjs First() 运算符仅获取一个项目
- r - 用于分析多个 csv、创建变量和在 R 中按组计算 NA 的用户定义函数
- typescript - 你如何在 Typescript 中使用命名路由器视图?