UPDATES VIA   RSS  |  Email Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don’t make mis…

Coding: Don’t make mistakes when resizing objects! Preserve the initial ratio correctly!

Posted on 17. Jun, 2009 by in Coding

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. 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. In fact this is not true!

Here’s why:

The ratio of the initial box is 100px/60px=1.66

In the second case the ratio is: (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! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. 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). That’s it!

Translate this post
                    
                    

Related posts:

  1. WordPress: Best SEO iTranslator for WordPress, get free traffic from fully automated plugin script

  • Abiye12

    Thank so much.

    Tüm
    dünyadaki okey oyuncuları ile aynı platform içerisinde sohbet ederek canlı okey
    oynamaya hazır olun. http://www.okey-oyna.com sizi eğlenceye ve heyecana davet ediyor. İnternette görüntülü
    olarak okey oyna, gerçek kişilerle tanış, turnuva
    heyecanını yaşa. Dünyanın en büyük internet oyun portalı içerisine kayıt olun
    ve oynamaya hemen başlayın.