Perpendicular Segments
You are given a coordinate plane and three integers X, Y, and K. Find two line segments AB and CD such that:
- the coordinates of points
A,B,C, andDare integers; 0 <= Ax, Bx, Cx, Dx <= Xand0 <= Ay, By, Cy, Dy <= Y;- the length of segment
ABis at leastK; - the length of segment
CDis at leastK; - segments
ABandCDare perpendicular: if you draw the lines that contain them, the lines cross at a right angle.
The segments do not need to intersect. They are perpendicular as long as the lines they induce are perpendicular.
Return the eight coordinates as a single flat array:
[Ax, Ay, Bx, By, Cx, Cy, Dx, Dy]
Any valid construction is accepted. If multiple answers exist, return any one of them.
The official input guarantee is that an answer exists. For an axis-aligned rectangle, that guarantee is equivalent to 2 * min(X, Y)^2 >= K^2, so min(X, Y) can be smaller than K when the segments are diagonal.
Examples
Input: [1,1,1]
Output: [0,0,1,1,0,1,1,0]
Input: [3,4,1]
Output: [0,0,3,3,0,3,3,0]
Hints
An answer is guaranteed to exist, so you only need to construct one valid pair.
Let `M = min(X, Y)`. The square `[0, M] x [0, M]` has two diagonals: `(0,0)` to `(M,M)` and `(0,M)` to `(M,0)`. Each diagonal has length `M * sqrt(2)`.
The guarantee `2 * M^2 >= K^2` means `M * sqrt(2) >= K`, so both diagonals are long enough.
Perpendicular Segments
You are given a coordinate plane and three integers `X`, `Y`, and `K`. Find two line segments `AB` and `CD` such that: