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 Aktualizací přes RSS | E-mail Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Home / Kódování / Coding: Nenuťte mis ...

Coding: Don't make mistakes when resizing objects! Kódování: Don't dělají chyby při změně velikosti objektů! Preserve the initial ratio correctly! Zachovat původní poměr správně!

Posted on 17. Publikováno před: dne 17. Jun, 2009 by Dragos in Coding Června 2009 od Dragos v Kódování

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Byl jsem mnohokrát v pokušení udělat rychle upravit svůj kód, aniž by brala v úvahu několik základních matematických principů. 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. Pro příklady, pokud je box je především 100px vysoký a 60px široký, a pak jsem si všimla, že toto pole nezapadá místo, kde byl určen k umístění, co jsem udělala, bylo odečíst 10 px od šířky okna pro to, aby se vešly nějaké oblasti, a zároveň jsem odečteno 10 px z výšky také, myslet si, že to jsem měl poměr původní velikosti krabice. In fact this is not true! Ve skutečnosti to není pravda!

Here's why: Zde je proč:

The ratio of the initial box is 100px/60px=1.66 Poměr původní pole je 100px/60px = 1.66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 V druhém případě je poměr: (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, pokud jste použili použít stejnou techniku jako já rychle změnit velikost objektů, zapomeň na to, jak je to špatně! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Místo toho použijte starou metodu ze školy určit proměnné ze dvou frakcí, zachování poměrů. 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). Zpět na výše uvedeném příkladu, aby zjistil výšku novou hodnotu do pole bych použít tento vzorec: = 100px/60px (100px-10px) / x, takže x = 60px * 90px/100px = 54px (místo nesprávné hodnoty 50px). That's it! To je ono!

Translate this post Translate this post


No related posts. Žádné související příspěvky.

    blog comments powered by Disqus blog připomínky powered by Disqus