Skip to content

Commit

Permalink
Make rotation math more comprehensible
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Sep 12, 2024
1 parent fb0e539 commit 32dedc3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Aardvark.OpenCV/ImageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public PixImage<T> Rotate<T>(PixImage<T> image, double angleInRadians, bool resi
// Compute bounds of rotated image
// See: https://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
var cos = rotMat.At<double>(0, 0);
var sin = rotMat.At<double>(1, 0);
var sin = rotMat.At<double>(0, 1);
var cosAbs = cos.Abs();
var sinAbs = sin.Abs();
dstSize.X = (long)(image.Width * cosAbs + image.Height * sinAbs + 0.5);
Expand All @@ -193,8 +193,8 @@ public PixImage<T> Rotate<T>(PixImage<T> image, double angleInRadians, bool resi
// Shift by -dstCenter -> rotate CW -> shift by srcCenter.
// See: https://math.stackexchange.com/questions/2093314/rotation-matrix-of-rotation-around-a-point-other-than-the-origin
var dstCenter = dstSize.XY.ToV2d() * 0.5;
rotMat.At<double>(0, 2) = -dstCenter.X * cos + dstCenter.Y * sin + srcCenter.X;
rotMat.At<double>(1, 2) = -dstCenter.X * sin - dstCenter.Y * cos + srcCenter.Y;
rotMat.At<double>(0, 2) = -dstCenter.X * cos - dstCenter.Y * sin + srcCenter.X;
rotMat.At<double>(1, 2) = dstCenter.X * sin - dstCenter.Y * cos + srcCenter.Y;
}

var dst = dstSize.CreateImageVolume<T>();
Expand Down

0 comments on commit 32dedc3

Please sign in to comment.