Scaling ratio of two different resolutions - math

I have two different resolutions, the original one is 567x756 (wXh), the one which I want to display is 768x1024 (wXh). How to find out the scaling ratio for these two resolutions? For example if the font size used in 567x756 resolution is 7 pts then what's the values I should multiply with the font size (7 pts) to display the text in 768x1024 resolution.

Whenever you hear "scaling", think "proportions":
You can set up a proportion, here:
old width new width
--------- = --------
old font new font
567 768
---- = -----
7 x
567*x = 5376
x = 9.48
So your new font is about 9.48, or 9 if you only want integers.
Alternatively, you could also use the height-to-height proportion in your calculations instead of width-to-width. Or use the average font height you'd get from doing either. Or do old_area/old_font^2 = new_area/new_font^2
If you want a way to find the scaling factor for any arbitrary new width:
old width new width
--------- = --------
old font new font
567 w
---- = ---
7 x
567*x = 7*w
x = (7/567) * w
Given your new w (or h, or w/e), the new font size is (7/567) * w

The aspect ratios are the same for both resolutions, so just take one dimension and use that as your scaling ratio, i.e.
1024/756
Which is about 1.35. Or if you want to scale in the other direction, 0.738

Related

How to subdivide the space inside a small multiple

I need to create small multiples (like the one shown in the picture) using ggplot2 where each circle occupies 70% of the total size of it's own small multiple and the remaining 30% is empty space.
I know the center and the radius of the circle.
Question: Is it possible to do this, and if so, how?
Area of ​​a circle = C = π * r²
Area of your square = S = width * length = side²
So just calculate C, so you can calculate how big S must be to fullfill your criteria. When you know S you know the side, which translates to how you have to set the axis limits for x and y.

How to compute delta X, Y when flattening a vector with shadows such that it's rendered at the same position?

I'm flattening a vector from a design tool (Sketch) to a PNG. A vector may have a shadow:
In this case the X and Y before flattening are 100x100 and the width and height before flattening are 100x100 too.
For automation reasons, I am automatically performing this vector to PNG flattening in the background (it's a CLI running on a server). The tool then gives me the PNG's new width and height, but unlike in the image below, the new or delta X and Y are unknown:
As you can see above, sometimes these vectors have shadows which will cause the frame of the image to be greater when flattened, such that the shadow is included in the exported image. However, this also means that the X and Y of the new frame have to be adjusted, such that the rendered portion of the new frame is still positioned at its original location.
That's why the new X and Y are 29x44 (with width and height 233x244).
The question is how to compute the new or delta X and Y based on the original vector's properties (incl. shadow props x, y, blur, spread) and/or the new flattened image's width/height (which are known).
Summary
I need to compute the delta X and Y such that the position of the rendered image is the same as before its frame was changed in size to include the shadow in its flattened form.
Take this test case:
Before flattening
frame x = 100
frame y = 100
frame width = 100
frame height = 100
shadow x = 0
shadow y = 20
shadow blur = 80
shadow spread = 0
after flattening:
frame x = 29 (*)
frame y = 44 (*)
frame width = 233
frame height = 244
I have all of the above values EXCEPT the after flattening frame x and y (marked with *). How do I develop a formula that computes this X, Y delta from the vector's frame and shadow properties and/or the new PNG's frame width/height?

determine box size needed

I am trying to calculate the size a big rectangle needed to pack smaller ones.he smaller rectangle have fixed know size and the big rectangle have a fixed width.
In the image, 6 rectangle can fit the big rectangle in which the initial w and height h1 . Now if give more small rectangle, how do i determine the height h2, h3, h4.
i initially went the bin packing route, but this didnt really help as it mainly focused on how many smaller rectangle can fit a big one, but i need instead how much size (height) is needed to fit a certain quantity of smaller boxes.
How do i find the heights h2, h3, and h4.
w = width of original rectangle
h1 = height of original rectangle
w and h1 is given say 300, 400
bh = small rectangles height
bw = small rectangles width
bh and bw is the same for all the rectangles and is given say 40, 40
sb = number of small boxes
three different sets are provided in this example, for each set the required height of the box needed to hold the small rectangles needs to be calculated
for the first set which has sb as 6, I need to find h2
for the second set which has sb as 7, I need to find h4
for the third set which has sb as 8, I need to find h3
It`s still a bit unclear to me. But here is a try to answer your question.
The number of boxes that fit in a single row is:
boxesInRow = floor(w / bw)
In order to fit n boxes, you need the following count of rows:
rows = ceil(n / boxesInRow)
And the height of this big box is then just:
height = rows * bh
Now comes the part where I am not sure. You say that sb is the number of boxes. However, for the first image (h2), you say that sb should be 6, but I count 9 boxes. So apparently, you ignore the first row. If this is really the case, the final formula is:
height = bh * (rows + 1)
= bh * (ceil(sb / floor(w / bw)) + 1)

Scaling a window while keeping ratios the same

I have a resizable window, and a graph which consists of 11 lines of different values ranging from 0 to 1000. What is the math I would use to compute this?
I want to have the data ranging from 0 to 1000 be so that it equals 0-1000 pixels on screen. But if I resize my window to say 640 / 480, the graph will adjust only will be less detailed.
This is a simple proportion: if 640 pixels bar represents value of 1000, value of Y will represent 640 * Y / 1000 pixels bar.
You did not specify a programming language.
In HTML you can size anything as %, so you calculate size as % of maximum - i.e. 550 (out of 1000 max) = 55%
If you use % size it will automatically adjust with screen/window size.
If you specify your programming language of choice we may be able to help you more

How to determine symbol size in x and y units

I would like to know the approximate dimensions of symbol in my plot area. I think that par()$ps only really refers to text size. So how is a symbol size calculated using the cex parameter? For example, below is a plot of a single point of size cex=10. Can i determine its size from the plot devices par parameters?
plot(50, 50, ylim=c(0,100), xlim=c(0,100), cex=10)
#click on outer x limits
p1 <- locator(n=1,typ="n")
p2 <- locator(n=1,typ="n")
#approx width in x units(~15)
abs(p1$x - p2$x)
Thanks for you help. -Marc
According to the documentation contained in ?par, we have that,
cin - R.O.; character size (width, height) in inches. These are the same measurements as cra, expressed in different units.
cra - R.O.; size of default character (width, height) in ‘rasters’ (pixels). Some devices have no concept of pixels and so assume an arbitrary pixel size, usually 1/72 inch. These are the same measurements as cin, expressed in different units.
On my machine, these values appear to be:
par("cin")
[1] 0.15 0.20
> par("cra")
[1] 10.8 14.4
So character magnification via cex ought to happen relative to these dimensions, presumably by scaling the horizontal and vertical dimensions separately (although I don't know that for sure).

Resources