Reputation: 17237
I would like to know how to calculate the minimum size of a display layer so that it will always cover up it's canvas regardless of it's rotation.
The image below depicts a canvas (black rectangle) with the dimensions of 1280 width x 800 height.
Center-aligned and center-registered, so that the canvas is completely covered at 0 degrees (image 1) and 90 degrees (image 2), a gradient display layer has been resized proportionately from 1280 width x 800 height (same size of the canvas) to 2048 width x 1280 height, so that the original minimum length matches the maximum length of the canvas. However, as shown in image 3, some angles will not completely cover the canvas by using this basic proportionate-resizing logic.
How can I determine the minimum size (without excess) for the gradient display layer so that when it's center-aligned and center-registered, regardless of it's angle, it will always cover the canvas?
Upvotes: 1
Views: 1030
Reputation: 660377
Suppose you were doing it with a circular, rather than rectangular, gradiant layer. Obviously if the circle is of the minimum size that covers the canvas, it can be rotated arbitrarily and still cover the canvas.
The diameter of that circle is the diagonal of the canvas. The rectangle you seek is the smallest rectangle which can contain that circle: a square whose side is the diameter of the circle.
This gives you the answer for any shape of "canvas": you've just got to find the smallest circle whose center is at the desired point of rotation that contains the whole canvas.
Upvotes: 5
Reputation: 424
re-posting as an answer:
wouldn't it just be a square whose sides equal the diagonal of the black rectangle? (or sqrt(1280^2 + 800^2))
Upvotes: 1
Reputation: 63
The width of the screen has to be at least larger then the diagonal of the canvas, and the height must be at least larger then the maximum of the width and height of the canvas:
Width = sqrt(x^2 + y^2) = sqrt(1280^2 + 800^2) = 1509.4
Height = max(x,y) = 1280
where x is the width of the canvas and y is the height
Upvotes: -1