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 UPDATES VIA RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Home / Coding / Coding: Huwag gumawa ng masama ...

Coding: Don't make mistakes when resizing objects! Coding: Huwag gumawa ng mga pagkakamali kapag pagpapalit ng sukat ng mga bagay! Preserve the initial ratio correctly! Panatilihin ang mga unang ratio ng tama!

Posted on 17. Posted on 17. Jun, 2009 by Dragos in Coding Hunyo, 2009 sa pamamagitan ng Dragos sa Coding

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Ako ay tempted maraming beses na gawin mabilis na adjustment sa aking code, nang hindi isinasaalang-alang ang ilang mga pangunahing mga prinsipyo ng matematikal na. 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 sa mga halimbawa kung ang isang kahon ay unang ng lahat ng mga 100px taas at 60px malawak, at pagkatapos ay mapansin ko na ang kahon na ito ay hindi akma ang lugar kung saan ito ay inilaan upang mailagay, ano ako did ay magbawas 10 px mula sa lapad ng kahon, para sa mga ito upang magkasya ang ilang mga lugar, at sa parehong oras ko bawas 10 px mula sa taas din, pag-iisip na ginagawa kaya ko iningatan ang ratio ng unang laki ng kahon. In fact this is not true! Sa katunayan ito ay hindi totoo!

Here's why: Narito kung bakit:

The ratio of the initial box is 100px/60px=1.66 Ang ratio ng unang box ay 100px/60px = 1.66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 Sa pangalawang kaso ang ratio ay: (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! Kaya, kung ang iyong ginamit upang mag-aplay sa parehong pamamaraan bilang ko ay upang mabilis na palitan ang sukat ng mga bagay, limutin buongpaligid ito, dahil ito ang mali! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Sa halip na gamitin ang lumang paraan mula sa paaralan upang matukoy kung ang isang variable na mula sa dalawang fractions, pagpepreserba ng 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). Bumalik sa halimbawa sa itaas, upang alamin ang bagong halaga taas ng kahon ng gusto ko bang gamitin ang formula na ito: 100px/60px = (100px-10px) / x, kaya x = 60px * 90px/100px = 54px (sa halip ng hindi tama ang halaga ng 50px). That's it! That's it!

Translate this post Isalin ang post na ito


No related posts. Walang mga kaugnay na post.

    blog comments powered by Disqus blog comments powered by Disqus