Calculate Height for Image/Video based on Aspect Ratio and Width - formula

I have a width: 240
I have aspect ratio: 2.40
I need to get the height based on those two variables. What's the formula?

Definition of the ratio:
ratio = width / height
Formula:
height = width / ratio = 240 / 2.40 = 100

example of calculating 2:40 . using javascript programming language.
var width = 240 ;
var rat1 = 2;
var rat2 = 40;
var ratio = width / rat1;
var calculated_height = ratio * rat2;

Related

Calculate width in scss

I have a little question, I don't understand what does it mean in css file
(100% - 60px) / 2) = ?????
Thanks for help
(100% - 60px) / 2) = ?????
in CSS the syntax to this expression will be :
calc(calc(100% - 60px)/2);
which means :
let's suppose we are talking about a property such as width, then for the current element in which we are writing this CSS, its width will be equal to px value of(100% of parent width) minus 60 px and its output divide by 2, then the result will be converted back to % and that will be the %value of width of Current element.
and the other way :
(100% parent width) = X px;
X px - 60 px = Y px;
(Y px converted to %) = Z %;
z % / 2 = result in %;

calculating pixel size from ppi

I need some help to verify that i have made my calculations correct.
I want to determine number of pixels in the span of 13.6 millimeters for a specific device that is 224,17 pixels per inch.
( if 1 inch = 224.17ppi therefor: 1 centimeter = 569.39ppcm therefor: 1 millimeter = 5.69 ppmm )
I calculate 13.6mm = 77.35 pixels
(224.17 pixels / 1 inch) * (1 inch / 25.4 mm) * 13.6 mm = 120 pixels
you can user converter for your ease like
http://endmemo.com/sconvert/millimeterpixel.php

Manipulating a fraction

I know this isn't really a computing question (more of a maths problem), however it will lead on to scaling screen resolutions.
I am faced with equation for scaling a image scale = desired height / current height
Example shows to find the scale of desired height = 3 current height = √3 / 2
Scale = 3 / (√3 / 2)
The example states this is equal to 3 * (2 / √3)
Can anyone please shed some light to how they got from 3 / (√3 / 2) to 3 * (2 / √3)
Thanks
Let:
x = p/q
y = r/x
You can transform:
y = r/x <=> y*x = r
Then you substitute the value of x:
y*x = y*p/q = r
Which itself transforms to:
y*p = r*q
Which eventually become:
y = r*q/p

How to revert a transformation?

I have a following transformation when doing some kind of zoom/upscaling of a point. My goal is to calculate an offset based on this scale.
My problem is that when going from a big scale to a smaller scale I'd of course have the offset to be the same. Eg if I scale from 3 to 4 and back from 4 to 3, the offset on scale of 3 should always be the same.
But with my formula, it is not. And I cannot get my head around what I'm doing wrong:
px = 200
offset = 0
scale: 1, and goes always +-1
calculation based on forumla: newOffset = oldOffset +- px / scale;
scale = 2 => offset = 0 + 200 / 2 = 100
scale = 3 => offset = 100 + 200 / 3 = 166,67
scale = 4 => offset = 166,67 + 200 / 4 = 216,67
How can I revert the scaling?
scale = 3 => offset = 216,67 - 200 / 3 = 150 # //it should evaluate to 166,67
The offsets are defined by a recursion relation:
offset(0) = 0
offset(i) = offset(i-1) + px/(i+1)
Or, if we were to write out the first few terms,
offset0 = 0
offset1 = offset0 + px/2 = 100
offset2 = offset1 + px/3 = offset0 + px/2 + px/3 = 166.67
offset3 = offset2 + px/4 = offset0 + px/2 + px/3 + px/4 = 216.67
So the offsets are equal to a constant, offset0, plus the first N terms of the harmonic series (the sum of terms 1/n for n = 2,3,...) scaled by px.
There is no closed form algebraic expression for the first N terms of the harmonic series, so either store the numbers and look them up as needed, or recompute the value when you "rescale".

Image scaling geometry

This is very programming related but a somewhat non-programming question. I am performing image scaling in a web based application and I need to maintain my image relative to a fixed location even though it scales anchored by its top, left corner. Hope the graphic make this possible.
The idea is that C is a fixed location that I want to maintain as my scaling origin rather than B which which is the current css behavior. C may or may not be within the actual image. So as the image scale, B needs to move relative to C. Example: if the image was scaled 50%, then B would move 1/2 the distance to C. If the image grew to 200% of its size, then B would move twice the distance away from C.
Ultimately looking for a formula for x & y for B given the location of C and a scaling factor for the image. Not sure the size of the image needs to be part of this but I have it if needed.
Thanks for any help!
Things I know:
I know the width and height of the
image rectangle.
I know the offset of B from A.
I know the offset of C from A.
I know the scale factor in percent of the image.
Effectively, you want to treat C as the origin, and just "move" B by the scaling amount. By treating it as a vector from C to B, and scaling it by the amount in question, you can do this fairly easily.
newBx = Cx - (Cx - Bx) * scale;
newBy = Cy - (Cy - By) * scale;
For example, with a scale of 0.5 (50%), this becomes:
newBx = 100 - (100 - 50) * 0.5
= 100 - 25
= 75 // 1/2 the distance to C
newBy = 100 - (100 - 25) * 0.5
= 100 - 37.5
= 62.5 // 1/2 the distance to C
With a scale of 2 (200%):
newBx = 100 - (100 - 50) * 2
= 100 - 100
= 0 // 2x the distance to C
newBy = 100 - (100 - 25) * 2
= 100 - 150
= -50 // 2x the distance to C
First you need to calculate the distance from B to C, then you just change that to scale, and that is where the new B is relative to C:
newB = C - (C - B) * scale
As you want the coordinates, it's the same function for x and y:
newBx = Cx - (Cx - Bx) * scale
newBy = Cy - (Cy - By) * scale
(The scale value used is not percentage but a size multiplier. An increase in size by 50% gives a scale of 1.5.)
So you want point C in the image which is currently at (C_x, C_y) to remain at the same position after scaling the image by a factor of s?
New position of C, say, C_new = (s*C_x,s*C_y).
And you want to move the image so that C_new = C.
Which means you'll have to shift B = (B_x,B_y) by (s*C_x-C_x,s*C_y-C_y), or the new origin of the image, say B_new is:
B_new = (B_x + s*C_x-C_x, B_y + s*C_y-C_y)
So now you can display the scaled image at B_new --- and C should remain fixed.
If I understand the problem:
X(b) = X(c) - Width*(1/3)
Y(b) = Y(c) - Height*(3/4)
The formula seems simple enough, but your sample image can't get any larger than 133x200 (scale = 133%) before it overruns Y=0 (which I assume is your northern limit).
If you want to stop it from moving past Y=0 or X=0, and push-out further to the south and east once it reaches either limit, one approach might be:
IIF(Height > 133, Y(b) = 0, Y(b) = Y(c) - Height*(3/4))
IIF(Width > 450, X(b) = 0, X(b) = X(c) - Width*(1/3))
I think scale should be converted to height and width, instead of using scale as a variable in these formulas, since your original image could be any size (assuming they're not always going to be 100x150 per your sample)
dave
here's a C# snippet that is tested to work:
void Main()
{
Application.Run(new form1());
}
public class form1 : Form
{
static Point C = new Point(100,100);
static Point origLocB = new Point(50,25);
static Size origSizeB = new Size(150,100);
Panel Rec = new Panel()
{
Left = origLocB.X,
Top = origLocB.Y,
Width = origSizeB.Width,
Height = origSizeB.Height,
BorderStyle = BorderStyle.FixedSingle,
};
NumericUpDown nud = new NumericUpDown()
{
Value = 1M,
Increment = .01M,
DecimalPlaces = 2,
Dock = DockStyle.Bottom,
};
public form1()
{
nud.ValueChanged += NumericUpDown_ValueChanged;
Controls.Add(nud);
Controls.Add(Rec);
}
public void NumericUpDown_ValueChanged(object sender, EventArgs e)
{
Rec.Location = new Point(((int)((origLocB.X - C.X) * nud.Value + C.X)),
((int)((origLocB.Y - C.Y) * nud.Value + C.Y)));
Rec.Size = new Size((int)(origSizeB.Width*nud.Value),
(int)(origSizeB.Height*nud.Value));
}
}
it really just echo's #Reed's Answer

Resources