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 Aktualizacje pocztą RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Strona główna / Coding / Kodowanie: Nie należy mis ...

Coding: Don't make mistakes when resizing objects! Kodowanie: Nie popełniać błędy podczas zmiany rozmiaru obiektów! Preserve the initial ratio correctly! Zachowania pierwotnego stosunku poprawnie!

Posted on 17. Zamieszczone w dniu 17. Jun, 2009 by Dragos in Coding Cze, 2009 Dragos w Coding

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. I wiele razy był kuszony do szybkiego dostosowania do mojego kodu, nie biorąc pod uwagę kilka podstawowych reguł matematycznych. 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. Na przykład, jeśli pole jest przede wszystkim 100px wysokości i szerokości 60px, a potem widzę, że to pole nie pasuje do miejsca, gdzie miała być umieszczone, co zrobiłem, było odjąć 10 px od szerokości pola, za to, aby dopasować jakimś miejscu, a jednocześnie mogę odjąć 10 px od wysokości również, myśląc, że robi tak trzymałem stosunek początkowej wielkości pudełka. In fact this is not true! W rzeczywistości nie jest to prawda!

Here's why: Oto dlaczego:

The ratio of the initial box is 100px/60px=1.66 Stosunek pierwotnego pole 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 W drugim przypadku wskaźnik ten jest: (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 więc, jeśli jest używana do zastosowania tej samej techniki, jak ja się szybko zmieniać rozmiar obiektów, zapomnij o tym, jak to się stało! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Zamiast używać starą metodę ze szkoły do określenia zmiennej z dwóch frakcji, zachowując proporcje. 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). Powrót do przykładu powyżej, aby dowiedzieć się nowa wartość wysokości pola użyję tego wzoru: 100px/60px = (100px-10px) / x, więc x = 60px * 90px/100px = 54px (zamiast nieprawidłowe wartości 50px). That's it! That's it!

Translate this post Translate this post


No related posts. No related posts.

    blog comments powered by Disqus blog komentarze powered by Disqus