I know this is probably pretty easy for people on this site but I am no mathematician so I thought I would ask here. I am looking for a formula for scaling a rectangle from an arbitrary point as in NOT THE CENTER. The point will always be inside the rectangle however and the scale is also arbitrary.
[Math] How To Scale A Rectangle
geometry
Related Solutions
First of all, there may be multiple rectangles that satisfy your conditions, e.g.
if you want specific angle of rectangle, or
if you want to specify a point on the boundary.
However, there is a special case where there is at most only once rectangle, i.e. if you assume that it has to touch both of your boundaries. In such case it is easy to compute it. Place the origin (point $(0,0)$) in the center of the boundary (the center of the circle), and let $(C_x,C_y)$ be the top right boundary corner (the boundary rectangle has size $2C_x \times 2C_y$ ). Let $(x,y)$ be the top right vertex of small rectangle, then it satisfies conditions ($\alpha > 0$ means counterclockwise rotation):
\begin{align*} \left[\begin{matrix}x'\\\ C_y\end{matrix}\right] &= \left[\begin{matrix}\cos\alpha&-\sin\alpha\\\sin\alpha&\cos\alpha\end{matrix}\right]\left[\begin{matrix}x\\\y\end{matrix}\right] \\\ \left[\begin{matrix}C_x\\\ y'\end{matrix}\right] &= \left[\begin{matrix}\cos\alpha&-\sin\alpha\\\sin\alpha&\cos\alpha\end{matrix}\right]\left[\begin{matrix}x\\\ -y\end{matrix}\right] \end{align*}
where $x'$ and $y'$ are just placeholders. Extracting appropriate rows from those formulae, we can transform that into one equation (notice the lack of minus sign in the matrix):
\begin{align*} \left[\begin{matrix}C_x\\\ C_y\end{matrix}\right] &= \left[\begin{matrix}\cos\alpha&\sin\alpha\\\sin\alpha&\cos\alpha\end{matrix}\right]\left[\begin{matrix}x\\\ y\end{matrix}\right] \end{align*}
with solution being:
\begin{align*} \left[\begin{matrix}\cos\alpha&\sin\alpha\\\sin\alpha&\cos\alpha\end{matrix}\right]^{-1} \left[\begin{matrix}C_x\\\ C_y\end{matrix}\right] &= \left[\begin{matrix}x\\\ y\end{matrix}\right] \\\ \sec{2\alpha}\left[\begin{matrix}\cos\alpha&-\sin\alpha\\\ -\sin\alpha&\cos\alpha\end{matrix}\right] \left[\begin{matrix}C_x\\\ C_y\end{matrix}\right] &= \left[\begin{matrix}x\\\ y\end{matrix}\right] \end{align*}
Please note, that this may not have a proper solution if $\alpha$ is to big!
Edit: Ok, I missed the comment about maximizing the area. Then again, consider this example:
The gray figure is a rhombus (it was created by rotating the black rectangle by $2\alpha$ ). To get the inscribed rectangle with the greatest area, consider the case when the rhombus would be a square--the greatest area would be when each rectangle vertex splits the rhombus edge in half (because then it is also a square and that is the rectangle with greatest area and given perimeter). But we can scale our rhombus (that may not be a square) so that is a square, obtain the solution there, and then scale back (the area will scale accordingly)! In conclusion the rectangle of greatest area will split the rhombus edges in half.
How to compute it? You could do it using the same approach:
\begin{align*} \left[\begin{matrix}x'\\\ C_y\end{matrix}\right] &= \left[\begin{matrix}\cos\alpha&-\sin\alpha\\\sin\alpha&\cos\alpha\end{matrix}\right]\left[\begin{matrix}x\\\y\end{matrix}\right] \\\ \left[\begin{matrix}x''\\\ -C_y\end{matrix}\right] &= \left[\begin{matrix}\cos(-\alpha)&-\sin(-\alpha)\\\sin(-\alpha)&\cos(-\alpha)\end{matrix}\right] \left[\begin{matrix}x\\\ -y\end{matrix}\right] \end{align*}
However, one can do it simpler: the vertex of the inscribed rectangle splits the gray edge in half, so $$2x\sin\alpha = C_y = 2y\cos\alpha\,.$$ This works if $C_x > C_y$, otherwise you need to do the same for $C_x$ instead. Moreover, even if $C_x > C_y$, you still need to check if the rotated rectangle fits into the boundary (because it may be that $C_x = C_y + \varepsilon $ ), if not, the solution from previous part will do.
Hope that helps ;-)
Let $x$ and $y$ denote the centers of $X$ and $Y$, respectively. The vector connecting them can be computed as $$ v = y-x. $$ If $s$ is the scaling factor, to achieve what you need you just need to modify the center of $Y$, namely replacing $y$ with the new center $$ a + s\cdot v = (a_1, a_2) + (s\cdot v_1,\; s\cdot v_2). $$ See the pictures below for the geometric intuition.
Related Question
- [Math] How to calculate the new x y coordinate for a rectangle when centering it within a rectangle
- [Math] the ratio of a circle’s diameter to a rectangle’s width so that the circle covers the rectangle exactly
- [Math] Rectangle Rotation and Scale
- Geometry – Scaling Rectangle B to Cover Rectangle A at Any Rotation
- Scale a rectangle by a percentage
Best Answer
If you have a function for scaling the rectangle from the center (I'm thinking you mean the rectangle is scaled and the center of the rectangle does not move), then you can combine that function with a pair of translations to achieve a transform that scales the rectangle while keeping some arbitrary other point fixed. Suppose you want to scale by $s$ and keep a point $p$ fixed. Then your function should transform a vertex, $v$, of the rectangle like:
$v\mapsto s(v - p) + p$.
This is essentially combining three simple transformations. First we send the fixed point you want to the origin $v' = v - p$. Then we scale everything $v'' = s v'$. Finally, we undo the first translation, to get back to the original coordinate system, $v''' = v'' + p$.