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 Atualizações Via RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Home / Codificação / Codificação: Não faz mal ...

Coding: Don't make mistakes when resizing objects! Codificação: não cometer erros quando redimensionar objetos! Preserve the initial ratio correctly! Preserve a proporção inicial corretamente!

Posted on 17. Postado em 17. Jun, 2009 by Dragos in Coding Junho de 2009 por Dragos na Codificação

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Fui tentado várias vezes para fazer ajustes rápidos para o meu código, sem levar em consideração alguns princípios matemáticos básicos. 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. Para exemplos, se uma caixa é antes de tudo 100px de altura e 60px de largura, e então percebo que esta caixa não se encaixa no lugar em que estava destinado a ser colocado, o que eu fiz foi para subtrair 10 px de largura da caixa, para que caiba alguma área e, ao mesmo tempo, subtraído 10 px de altura também, pensando que assim eu continuei fazendo a relação entre o tamanho inicial do caixa. In fact this is not true! Na verdade isso não é verdade!

Here's why: Eis o porquê:

The ratio of the initial box is 100px/60px=1.66 A relação da caixa inicial é 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 No segundo caso, a relação é: (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! Então, se você usou a aplicar a mesma técnica que eu fiz rapidamente redimensionar objetos, esquecê-lo, porque é errado! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Ao invés disso use o velho método da escola para determinar uma variável de duas fracções, preservando as proporções. 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). Voltar para o exemplo acima, a fim de descobrir o novo valor da altura da caixa que eu use esta fórmula: = 100px/60px (100px-10px) / x, então x = 60px * 90px/100px = 54px (em vez de o valor incorreto de 50px). That's it! That's it!

Translate this post Traduzir este post


No related posts. No related posts.

    blog comments powered by Disqus blog comentários powered by Disqus