Java 如何在旋转前获得旋转坐标的位置?

Java 如何在旋转前获得旋转坐标的位置?,java,algorithm,math,rotation,Java,Algorithm,Math,Rotation,我正在尝试旋转图像,旋转后的图像有一些孔或缺少像素。为了得到填充缺失像素的颜色,我需要得到缺失像素在未旋转图像中的位置 要计算旋转后的像素坐标,请执行以下操作 double rotationAsRadiant = Math.toRadians( 360 - rotationInDegrees ); double cos = Math.cos( rotationAsRadiant ); double sin = Math.sin( rotationAsRadiant ); int xAfterRo

我正在尝试旋转图像,旋转后的图像有一些孔或缺少像素。为了得到填充缺失像素的颜色,我需要得到缺失像素在未旋转图像中的位置

要计算旋转后的像素坐标,请执行以下操作

double rotationAsRadiant = Math.toRadians( 360 - rotationInDegrees );
double cos = Math.cos( rotationAsRadiant );
double sin = Math.sin( rotationAsRadiant );
int xAfterRotation = (int)( x * cos + y * sin );
int yAfterRotation = (int)( -x * sin + y * cos );

如何获得计算x后旋转和y后旋转时使用的x和y?

颠倒公式,如:

double rotationAsRadiant = Math.toRadians( rotationInDegrees );
double cos = Math.cos( rotationAsRadiant );
double sin = Math.sin( rotationAsRadiant );
for (int xAfter = 0; xAfter < width; xAfter++) {
    for (int yAfter = 0; yAfter < height; yAfter++) {
        int xBefore = (int)( xAfter * cos + yAfter * sin );
        int yBefore = (int)( -xAfter * sin + yAfter * cos );
        // paint pixel xAfter/yAfter using original from xBefore/yBefore
        ...
    }
}
double rotationAsRadiant=数学toRadians(旋转度);
双余弦=数学余弦(旋转辐射);
双正弦=数学正弦(旋转辐射);
for(int-xAfter=0;xAfter
这样,您肯定会用最接近精确位置的原始像素填充结果图像的所有像素。不会有洞

您最初的方法是由“给定源像素在目标图像中的位置”这一问题驱动的。无法保证结果将覆盖所有像素(您已经看到了孔)


我的方法是“对于给定的目标像素,我在哪里可以找到它的源?”

x
y
是这个公式的输入-我不确定我是否理解您的要求。你对反转函数感兴趣吗?你也可以只旋转一个负角度。猜测一下:你是在两个嵌套的循环中为
x
y
做这个公式吗?这很可能是问题的根本原因,如果我的猜测是正确的,我可以使用不同的方法提出解决方案。是的,我想反转函数。在不知道x和y输入的情况下,如何从xAfterRotation和YaafterRotation变量中获取x和y输入?您不能将
360-旋转度
替换为
旋转度
?这将撤消旋转。我不太确定你在问什么。我正在旋转图像,通过使用嵌套的for循环遍历所有像素来表示x和y是。