Squared Frobenius Norm of a Reflect-and-Stretch Map
Problem statement
Let L be the line through the origin with direction vector (dx, dy). A linear transformation T from R^2 to R^2 leaves every point on L unchanged.
For any point P not on L, its image T(P):
- has the same orthogonal projection onto
LasP, - lies on the opposite side of
L, and - is
ktimes as far fromLasPis.
Let A be the 2 x 2 matrix of T. Return the squared Frobenius norm of A, which is the sum of the squares of its four entries. The answer is always a whole number.
The original question uses the line y = (3/4)x and twice the distance, which is the input dx = 4, dy = 3, k = 2.
Function
squaredFrobeniusNorm(dx: int, dy: int, k: int) → longExamples
Example 1
dx = 4dy = 3k = 2return = 5The projection onto L is P = [[16, 12], [12, 9]] / 25. Keeping the part along L and sending the perpendicular part to -2 times itself gives A = P - 2(I - P) = [[-2, 36], [36, -23]] / 25.
The squared entries sum to (4 + 1296 + 1296 + 529) / 625 = 3125 / 625 = 5.
Example 2
dx = 1dy = 0k = 1return = 2L is the x-axis and k = 1, so T is the reflection (x, y) -> (x, -y). Its matrix is [[1, 0], [0, -1]], and 1 + 1 = 2.
Example 3
dx = 0dy = -5k = 3return = 10L is the y-axis. T keeps y and sends x to -3x, so A = [[-3, 0], [0, 1]] and 9 + 1 = 10.
Constraints
-1000 <= dx, dy <= 1000dxanddyare not both01 <= k <= 10^6