gpt4 book ai didi

Java 2d 爆炸饼图分段

转载 作者:行者123 更新时间:2023-12-01 09:44:52 25 4
gpt4 key购买 nike

我试图在饼图的一段(弧)与其中心之间添加一些距离(例如 10px),但没有成功,这是我迄今为止尝试过的:

enter image description here

int value = 20; // example
double arcAngle = (value * 360 / 100);
double angle = 360 - (arcAngle / 2); // direction to add the distance to (center of arc)
double newX = pieCenterX + Math.cos(angle * Math.PI / 180.0) * 10;
double newY = pieCenterY + Math.sin(angle * Math.PI / 180.0) * 10;

// then drawing the arc with new x and y
g.fill(new Arc2D.Double(newX, newY, bounds.getWidth(), bounds.getHeight(), startAngle, arcAngle, Arc2D.PIE));

理想情况下我应该得到这样的结果:

enter image description here

我不太了解如何解决这个问题,因此我的代码取 self 在其他地方找到的示例。

最佳答案

通常零角度是OX方向(右)。所以你必须修正90度(如果你的坐标系是逆时针的话)

double angle = 90 + 360 - (arcAngle / 2); 

关于Java 2d 爆炸饼图分段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38147310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com