R
R
RSV2013-07-05 10:50:41
Programming
RSV, 2013-07-05 10:50:41

How to uniformly scale down subareas in a given area

Given:
Some square area with equal sides of size N by N points. Let's call it canvas.
The canvas is divided into several rectangles (let's call them slots). Slots can be from 2 to 8 (depending on the current configuration).
The original dimensions of the slots and the coordinate of the upper left corner of each slot relative to the upper left corner of the canvas are known.
Initially, the slots completely cover the area of ​​the canvas with their area and do not go beyond the borders of the canvas.
The question is how to implement a proportional reduction of all slots by a certain factor X.
When reducing, each slot should, if possible, maintain its proportions (the ratio of width to height, or it is possible to change the proportions, but so that the slots that initially had equal sizes relative to each other, after reduction, also have equal sizes relative to each other), and change their position within the canvas, so that the distance between adjacent slots and the distance between the slot and the edge of the canvas are the same.
After the reduction, each slot must have the same adjacent slots on each side as before the reduction.

for example, the initial configuration of 8 slots
postimg.org/image/5cz56qncr/
result after reduction
postimg.org/image/63rvcipq3

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DrAlan, 2013-07-05
@DrAlan

The slot is a rectangle. Find the center of the rectangle and decrease it relative to this center. That is, the centers of the rectangles are preserved when moving, if the rectangle has decreased by half, then its left corner has moved down and to the right by a quarter of the size along the axis along which it has decreased.
XY start position of the upper left corner of the rectangle.
WH - width and height.
K is the scaling factor (Wnew = W*X for halving K = 0.5)
Xnew = X + W*(1-K)/2
Ynew = Y + H*(1-K)/2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question