I have a rectangle, and know the dimensions, coordinates of the 4 corner points and therefore the centre point.
If I scaled it up e.g. scalefactor * height, from its centre, how can I find the new corner point coordinates?
I have a rectangle, and know the dimensions, coordinates of the 4 corner points and therefore the centre point.
If I scaled it up e.g. scalefactor * height, from its centre, how can I find the new corner point coordinates?
On
By finding the center point of the rectangle, you can define four (eight actually, but keep reading) right triangles, with the center, the corner, and the center of the two "sides" (as distinct from the "top" and "bottom"). The two right-angle sides of these triangles are equivalent to the translations, in the X and Y dimensions, between the center point and each corner. They're also half the X and Y dimensions of the entire rectangle.
Knowing these measurements, to scale the rectangle while keeping the same center point, you simply have to scale the sides of these triangles by your scale factor to determine the offsets of the new corners from the same center point.
As the simplest example, consider a rectangle that is 2 units by 4 units centered at the origin (0,0). Its corners are (2,1), (2, -1), (-2, -1) and (-2, 1). To construct a rectangle with twice the dimensions of the original rectangle (which will quadruple its area), you simply subtract the center coordinate from these numbers (which is a "no-op" because the center is at 0,0), double that, then add the center coordinate again. This will produce a rectangle with corners at (4,2), (4,-2), (-4,-2) and (-4,2).
On
If you have any number of points $(P_i)_{i=1}^n =((x_i, y_i))_{i=1}^n $ and a center $C =(x_c, y_c) $, here's how I would expand by a factor $f$ around $C$:
The line through $C$ and $P_i$ is, in vector form, $L_i =C+t(P_i-C) $. This is $C$ for $t=0$ and $P_i$ for $t=1$.
To expand this by a factor of $f$ around $C$, just take $t=f$, so the point is $C+f(P_i-C) $. To get the coordinates, just compute coordinate-wise.
This works for any number of points and any number of dimensions.
Note that the basic idea is to transform the points so that the center is the origin, do what you want to do, and than transform back to the original coordinate system.
You need only multiplying the coordinates in the appropriate dimension by your scale factor. You need to mind what your origin is, however, as although the distance between the point will change, your origin will remain in the same place....
Hope it's clear enough.