I'm attempting to translate some code from Skia and I'm not sure exactly how SkMatrix works
SkMatrix pointTransform;
pointTransform.setRotate(-angle);
SkPoint transformedMidPoint;
pointTransform.mapPoints(&transformedMidPoint, &midPointDistance, 1);
SkScalar squareRx = rx * rx;
SkScalar squareRy = ry * ry;
SkScalar squareX = transformedMidPoint.fX * transformedMidPoint.fX;
SkScalar squareY = transformedMidPoint.fY * transformedMidPoint.fY;
// Check if the radii are big enough to draw the arc, scale radii if not.
// http://www.w3.org/TR/SVG/implnote.html#ArcCorrectionOutOfRangeRadii
SkScalar radiiScale = squareX / squareRx + squareY / squareRy;
if (radiiScale > 1) {
radiiScale = SkScalarSqrt(radiiScale);
rx *= radiiScale;
ry *= radiiScale;
}
pointTransform.setScale(1 / rx, 1 / ry);
pointTransform.preRotate(-angle);
SkPoint unitPts[2];
pointTransform.mapPoints(unitPts, srcPts, (int) SK_ARRAY_COUNT(unitPts));
SkVector delta = unitPts[1] - unitPts[0];I'm trying to figure out what the equivalent of transforms would be that are applied to the matrix using System.Numerics.
setRotatesetScalepreRotate
Would the following be accurate?
static float DegToRad(float deg) => deg * (MathF.PI / 180f);
// setRotate ?
Matrix3x2 pointTransform = Matrix3x2.CreateRotation(DegToRad(-angle));
// setScale ?
pointTransform.M11 = 1 / rx;
pointTransform.M22 = 1 / ry;
// preRotate ?
pointTransform *= Matrix3x2.CreateRotation(DegToRad(-angle));