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 Updates via RSS | E-post Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Avaleht / kodeerimise / Kood: Ära tee mis ...

Coding: Don't make mistakes when resizing objects! Kood: Ärge tehke vigu kui saneerimist objekti! Preserve the initial ratio correctly! Säilitada algne suhe õigesti!

Posted on 17. Postitatud 17. Jun, 2009 by Dragos in Coding Juuni, 2009 Dragos in Kood

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Mul oli kiusatus mitu korda teha kiireid muudatusi minu kood, võtmata arvesse teatud matemaatiliste põhimõtete alusel. 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. Näiteid, kui kast on kõigepealt 100px kõrge ja 60px lai ja siis märkan, et see kast ei sobi, kus ta pidi panna, mida ma tegin oli, et lahutada 10 px alates Kapsli laius, jaoks, mis sobib teatud valdkonnas ja samal ajal ma lahutatakse 10 px kõrguselt ka, mõtlesin, et teeme nii et ma hoida suhe esialgse suurusega kastis. In fact this is not true! Tegelikult see ei ole tõsi!

Here's why: Here's why:

The ratio of the initial box is 100px/60px=1.66 Suhe esialgu lahtrisse on 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 Teisel juhul on suhe: (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! Seega, kui kasutasite rakendada sama meetodit nagu tegin kiiresti suurust objekti, unusta see, kui see on vale! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Selle asemel kasutada vana meetodit koolist määrata muutuja kahe fraktsioonid, säilitades suhted. 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). Tagasi eespool toodud näide, et leida uus kõrgus väärtus lahtris ma kasutada: 100px/60px = (100px-10px) / x, et x = 60px * 90px/100px = 54px (mitte vale väärtuse 50px). That's it! That's it!

Translate this post Tõlgi see postitus


No related posts. Nr seotud ametikohta.

    blog comments powered by Disqus blog comments powered by Disqus