用Java画圆弧
我需要在Java中绘制一个起始角度350和结束角度20的饼图。我遵循的坐标系如下:-
|0
|
270-----------90
|
|180
这里的问题是起始角度大于结束角度。反之亦然我有设法画出弧线。任何帮助都会很棒。
I need to draw a Pie Arc in Java with start angle 350 and end angle 20.The cordinate system I follow is as follows:-
|0
|
270-----------90
|
|180
The problem here is that the start angle is greater than the end angle.For the other way round I have managed to draw the arc.Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将有一个起始角度和一个“延伸”角度,而不是结束角度。所以,我认为您绘制弧线不会有问题。
或者,您可以使用 Arc2D 类也是如此。还有一点需要注意的是,在java中,这是默认的协调机制。
You will have a start angle and an 'extent' angle and not an end angle. So, I don't think you would be having problem drawing an arc.
Alternatively, you can use the Arc2D class as well. One more thing to note that in java, this is the default co-ordinate mechanism.
使用(450 - 角度) % 360 切换角度。概念450=180+270;
Use (450 - angle) % 360 to switch angles. Concept 450 = 180 + 270;
扩展 @bragbog 的工作代码,我不得不经历类似的情况,我必须将类似于 OP 的坐标系统转置为 Java 坐标系统。
这就是我的想法:
这可能会令人困惑,但是 Java 系统和我正在使用的系统,45 和 225 保持不变,因此转置系统在其斜率上翻转(其中 45 和 225 具有与任一轴的角度相同)
absModAngle 确保生成的角度在 [0 - 360) 范围内。
我创建了附加图像,但没有足够的代表来添加它。本质上
Extending on what @bragbog 's working code, I had to navigate through a similar situation where I had to transpose the co-ordinate system similar to that of the OP to the Java co-ordinate system.
This is what I came up with:
It may be confusing, but the Java system and the system I was working with, had 45 and 225 remain the same so the transpose being the systems are flipped on it's slope (where 45 and 225 have the same angle from either axis)
The absModAngle ensures my resulting angle is within my [0 - 360) range.
I created an additional image, but I don't have enough rep to add it. Essetentially