Java:在可调整大小的组件中调整旋转形状的大小

问题描述

我正在尝试在可调整大小的组件中调整旋转形状的大小。

用于在旋转我正在使用的形状后调整组件的大小:

int newWidth = (int) ((rect.width * Math.abs(Math.cos(angle))) + (rect.height * Math.abs(Math.sin(angle))));
int newHeight = (int) ((rect.height * Math.abs(Math.cos(angle))) + (rect.width * Math.abs(Math.sin(angle))));

效果很好。

用于将旋转后的形状调整到组件中,以便旋转后的形状边界保留在我正在使用的组件中:

shapeBounds.width = ((int)((componentBounds.width * Math.abs(Math.cos(angle))) + (int)((componentBounds.height * Math.abs(Math.sin(angle)))))) - (int)(componentBounds.width * Math.abs(Math.sin(angle)));
shapeBounds.height = ((int)((componentBounds.height * Math.abs(Math.cos(angle))) + (int)((componentBounds.width * Math.abs(Math.sin(angle)))))) - (int)(componentBounds.height * Math.abs(Math.cos(angle)));

不幸的是,这不能正常工作,并且形状尺寸没有准确地调整到组件尺寸。

有人知道如何解决这个问题吗?

最好的问候并感谢一百万。

在可调整大小的组件中调整旋转形状的大小

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)