如何使用drawline()将圆分成16个等分
我正在尝试将一个圆圈分成16 等于零件(使用8行),我尝试使用drawline()函数来实现这一目标,到目前为止,我已经很有趣了,但是现在除了我拥有的东西之外,我被困在中心水平和垂直线上是完美的,但是这两个对角线并没有真正从它们各自的象限的中心分裂,有些象限比其他象限大,这就是我到目前为止
class _AnimatedCircleState extends State<AnimatedCircle> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
child: CustomPaint(
size: Size(500, 500),
painter: Painter(),
),
),
),
);
}
}
定制器
class Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Offset p1(double dx, double dy) {
return Offset(dx, dy);
}
Offset p2(double dx, double dy) {
return Offset(dx, dy);
}
final paint = Paint()..color = Colors.black..strokeWidth = 2;
canvas.drawLine(p1(250, 0), p2(250, 500), paint);
canvas.drawLine(p1(415, 62.5), p2(85, 437.5), paint);
canvas.drawLine(p1(0, 250), p2(500, 250), paint);
canvas.drawLine(p1(415, 437.5), p2(85, 62.5), paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
我的实际问题是,有没有办法获取每行点1和点2的真实x,y坐标,我尝试使用我假设的角度来获得它们为22.5,因为360除以16个零件是22.5,所以我尝试分别为x和y将半径500乘以sin(22.5)和cos(22.5),但是这种数学逻辑并不能真正翻译好在这里的代码中,因为首先,我的起源点已经关闭,谈话过多, 谁能在这里帮助我,也许我要过度思考这个问题,我如何获得其余的X和Y坐标,以及如何使我已经直接通过象限的中心撞击的对角线
I'm trying to split a circle into 16 equal parts(using 8 lines), I've tried to achieve this using the drawLine() function, so far what I have is pretty interesting, but now I'm stuck, besides, with what I have, the center horizontal and vertical lines are perfect, but those two diagonal ones aren't really splitting through the center of their respective quadrant perfectly, some quadrants are bigger than others, here's what I have so far
Parent Class
class _AnimatedCircleState extends State<AnimatedCircle> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
child: CustomPaint(
size: Size(500, 500),
painter: Painter(),
),
),
),
);
}
}
CustomPainter
class Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Offset p1(double dx, double dy) {
return Offset(dx, dy);
}
Offset p2(double dx, double dy) {
return Offset(dx, dy);
}
final paint = Paint()..color = Colors.black..strokeWidth = 2;
canvas.drawLine(p1(250, 0), p2(250, 500), paint);
canvas.drawLine(p1(415, 62.5), p2(85, 437.5), paint);
canvas.drawLine(p1(0, 250), p2(500, 250), paint);
canvas.drawLine(p1(415, 437.5), p2(85, 62.5), paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
my actual question is, Is there a way to get the true x,y coordinates of each line's point1 and point 2, I tried getting them using the angle which I assumed to be 22.5 since 360 divided by 16 parts is 22.5, so I tried multiplying radius 500 by sin(22.5) and cos(22.5) for x and y respectively but this maths logic doesn't really translate well in code here because to begin with, my point of origin is off, too much talk,
could anyone help me out here, maybe I'm overthinking this, how can I get the rest of the x and y coordinates, and how do I make the diagonals which I already have strike directly through the center of their quadrants
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道颤抖或飞镖,但这可能会对您有所帮助。使用for循环您可以在22.5度绘制线条。
I don't know flutter or dart but this may help you. Using a for loop you can draw your lines at 22.5 degrees.