Я пытаюсь заменить часть изображения на повернутую версию другой. Источник изображения должен выглядеть таким образом, чтобы origin_source заканчивался на orign_dest в изображении * this. Также источник должен вращаться вокруг 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);
}
}
}
}
Вот некоторые другие используемые функции:
Т = двойной
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;
}