画像の一部を別の画像の回転バージョンに置き換えようとしています。画像ソースは、origin_source が image *this の orign_dest になるように表示する必要があります。また、ピクセルを置き換える前に、ソースを origin_source を中心に回転させる必要があります。
以下のコードは、R がミラー行列の場合に機能しますが、実際に回転行列にすると、結果の画像がずれてしまいます。なにが問題ですか?
void Image::imageApply(const Image& source,const Point& origin_dest,const Point& origin_source,const Point& direction)
{
Matrix22<double> R=transformRotationCreate(direction);
Point source_new_size=sqrt(2)*((Point){source.widthGet(),source.heightGet()});
Point blit_start=origin_dest;
for(unsigned int k=0;k<source_new_size.y;k++)
{
for(unsigned int l=0;l<source_new_size.x;l++)
{
Point point_source=(Point){l,k};
Point point_dest=point_source-origin_source;
point_dest*=R;
point_dest+=blit_start;
if(point_source.rectangleInIs((Point){0,0},(Point){source.widthGet(),source.heightGet()})
&&point_dest.rectangleInIs((Point){0,0},(Point){widthGet(),heightGet()}))
{
(*this)(point_dest)=source(point_source);
}
}
}
}
使用されるその他の関数を次に示します。
T=ダブル
template<class T>
struct Matrix22
{
T xx;
T xy;
T yx;
T yy;
};
方向は正規化されたベクトルです
inline Matrix22<double> transformRotationCreate(const Vector2d<double>& direction)
{
return (Matrix22<double>){direction.x, -direction.y, direction.y, direction.x};
}
また
Vector2d<T>& operator*=(const Matrix22<T>& M)
{
x=x*M.xx + y*M.xy;
y=x*M.yx + y*M.yy;
return *this;
}