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 Aktualizáciou cez RSS | E-mail Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Home / Kódovanie / Coding: Nenúťte mis ...

Coding: Don't make mistakes when resizing objects! Kódovanie: Nechcem robia chyby pri zmene veľkosti objektov! Preserve the initial ratio correctly! Zachovať pôvodný pomer správne!

Posted on 17. Publikované pred: dňa 17. Jun, 2009 by Dragos in Coding Júna 2009 od Dragos v Kódovanie

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Bol som mnohokrát v pokušení urobiť rýchlo upraviť svoj kód, bez toho, aby brala do úvahy niekoľko základných matematických princípov. 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. Pre príklady, ak je box je predovšetkým 100px vysoký a 60px široký, a potom som si všimla, že toto pole nezapadá miesto, kde bol určený na umiestnenie, čo som urobila, bolo odpočítať 10 px od šírky okna pre to, aby sa zmestili nejaké oblasti, a zároveň som odpočítalo 10 px z výšky tiež, myslieť si, že to som mal pomer pôvodnej veľkosti škatule. In fact this is not true! V skutočnosti to nie je pravda!

Here's why: Tu je prečo:

The ratio of the initial box is 100px/60px=1.66 Pomer pôvodný poľa je 100px/60px = 1.66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 V druhom prípade je pomer: (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! Takže, ak ste použili použiť rovnakú techniku ako ja rýchlo zmeniť veľkosť objektov, zabudni na to, ako je to zle! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Namiesto toho použite starú metódu zo školy určiť ukazovatele z dvoch frakcií, zachovanie pomerov. 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). Späť na vyššie uvedený príklad, aby zistil výšku novú hodnotu do poľa by som použiť tento vzorec: = 100px/60px (100px-10px) / x, takže x = 60px * 90px/100px = 54px (miesto nesprávne hodnoty 50px). That's it! To je ono!

Translate this post Translate this post


No related posts. Žiadne súvisiace príspevky.

    blog comments powered by Disqus blog pripomienky powered by Disqus