This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/17/coding-dont-make-mistakes-when-resizing-objects-preserve-the-initial-ratio-correctly/
UPDATES VIA RSS | Email Opdateringer via RSS | E-mail Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Hjem / Kodning / Coding: Må ikke gøre mis ...

Coding: Don't make mistakes when resizing objects! Coding: Du må ikke begå fejl, når resizing genstande! Preserve the initial ratio correctly! Bevare den oprindelige ratio korrekt!

Posted on 17. Sendt den 17. Jun, 2009 by Dragos in Coding Juni, 2009 af Dragos i Kodning

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Jeg var fristet mange gange til at lave hurtige justeringer til min kode, uden at tage hensyn til nogle grundlæggende matematiske principper. For examples if a box is first of all 100px tall and 60px wide, and then I notice that this box does not fit the place where it was intended to be placed,  what I did was to subtract 10 px from the width of the box, for it to fit some area, and at the same time I subtracted 10 px from the height also, thinking that doing so I kept the ratio of the initial sizes of the box. For eksempel hvis et felt er først og fremmest 100px høj og 60px bred, og så bemærker jeg, at dette felt ikke passer til det sted, hvor det var hensigten at blive puttet, hvad jeg gjorde, var at trække 10 px fra bredden af kassen, for at passe nogle områder, og på samme tid, jeg trækkes 10 px fra højden også, at tro, at gøre, så jeg holdt forholdet mellem den oprindelige størrelse i boksen. In fact this is not true! Faktisk er dette ikke sandt!

Here's why: Her er hvorfor:

The ratio of the initial box is 100px/60px=1.66 Forholdet mellem den oprindelige rubrik er 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 I det andet tilfælde forholdet er: (100px-10px) / (60px-10px) = 1,8

So, if you used to apply the same technique as I did to quickly resize objects, forget about it, as it's wrong! Så hvis du brugte til at anvende den samme teknik som jeg gjorde til hurtigt at ændre størrelse på objekter, glem det, da det er forkert! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. I stedet bruge den gamle metode fra skole til at bestemme en variabel fra to fraktioner, bevare forholdet. Back to the example above, in order to find out the new height value of the box I'd use this formula: 100px/60px=(100px-10px)/x, so x=60px*90px/100px=54px (instead of the incorrect value of 50px). Tilbage til eksemplet ovenfor, for at finde ud af den nye højde værdien af feltet jeg ville bruge denne formel: 100px/60px = (100px-10px) / x, så x = 60px * 90px/100px = 54px (i stedet for forkert værdi af 50px). That's it! That's it!

Translate this post Oversæt dette indlæg


No related posts. Ingen relaterede stillinger.

    blog comments powered by Disqus blog comments powered by Disqus