- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个看起来像这样的 CustomPainter
:
class MyPainter extends CustomPainter {
Offset left, top, right, bottom;
MyPainter({this.left, this.top, this.right, this.bottom});
@override
void paint(Canvas canvas, Size size) {
Paint pp = Paint()
..color = Colors.blue
..strokeCap = StrokeCap.round
..strokeWidth = 10;
Paint p = Paint()
..color = Colors.red
..style = PaintingStyle.stroke
..strokeWidth = 2;
Path ph = Path();
ph.moveTo(left.dx, left.dy);
ph.quadraticBezierTo(top.dx, top.dy, right.dx, right.dy);
canvas.drawPoints(PointMode.points, [left, top, right, bottom], pp);
canvas.drawPath(ph, p);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
这是结果:https://imgur.com/a/m4i6WEA
但是我想要曲线,通过控制点。像这样:https://imgur.com/a/cumbAVz
我该怎么做?!
最佳答案
需要根据需要的点top
计算内部控制点P1
坐标
首先,粗略评估那个点的参数t
。让它为 1/2
(如果 top
位于曲线中间附近)。使用二次贝塞尔公式:
P(t) = P0 * (1-t)^2 + 2 * P1 * t * (1-t) + P2 * t^2
top {for t=1/2} = P0 * 1/4 + P1 * 1/2 + P2 * 1/4
P1 = 2 * top - (P0 + P2) / 2
在组件中:
P1.dx = 2 * top.dx - (left.dx + right.dx) / 2
P1.dy = 2 * top.dy - (left.dy + right.dy) / 2
最后
ph.quadraticBezierTo(P1.dx, P1.dy, right.dx, right.dy);
关于dart - 路径 quadraticBezierTo : curve pass the control point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54319537/
在此link我们已经解决了设计 wave quadraticBezierTo,但那是 wave quadraticBezierTo 的一半,我想要像这个屏幕截图一样的完整设计: 现在我的问题是我们如何
我正在尝试制作如下图所示的形状... 我不知道如何让它像图片一样...... 我的代码... ClipPath( clipper: MyClipper(), child: Contai
在上面的场景中,x1 和 y1 和 x2 和 y2 是什么点??? 对于 Path path = Path(); path.quadraticBezierTo(x1, y1, x2, y2) 最佳答案
在上面的场景中,x1 和 y1 和 x2 和 y2 是什么点??? 对于 Path path = Path(); path.quadraticBezierTo(x1, y1, x2, y2) 最佳答案
我有一个看起来像这样的 CustomPainter: class MyPainter extends CustomPainter { Offset left, top, right, bottom
我是一名优秀的程序员,十分优秀!