Created
September 28, 2025 19:11
-
-
Save jnm2/5d2eab3cd9461e55c7af3233f8948472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static SKMatrix MapUnitSquareToGivenPoints(SKPoint topLeft, SKPoint topRight, SKPoint bottomLeft, SKPoint bottomRight) | |
{ | |
var rightDiff = bottomRight - topRight; | |
var bottomDiff = bottomRight - bottomLeft; | |
var determinant = rightDiff.X * bottomDiff.Y - bottomDiff.X * rightDiff.Y; | |
var topDiff = topRight - topLeft; | |
var leftDiff = bottomLeft - topLeft; | |
var persp0 = -(bottomDiff.X * topDiff.Y - bottomDiff.Y * topDiff.X) / determinant; | |
var persp1 = (rightDiff.X * leftDiff.Y - rightDiff.Y * leftDiff.X) / determinant; | |
return new SKMatrix | |
{ | |
ScaleX = persp0 * topRight.X + topDiff.X, | |
SkewX = persp1 * bottomLeft.X + leftDiff.X, | |
TransX = topLeft.X, | |
SkewY = persp0 * topRight.Y + topDiff.Y, | |
ScaleY = persp1 * bottomLeft.Y + leftDiff.Y, | |
TransY = topLeft.Y, | |
Persp0 = persp0, | |
Persp1 = persp1, | |
Persp2 = 1, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment