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 | E-pasts Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Home / Coding / Coding: Nevajag padarīt mis ...

Coding: Don't make mistakes when resizing objects! Koda: Don't kļūdīties, ja izmēru maiņas objekti! Preserve the initial ratio correctly! Saglabāt sākotnējo attiecība pareizi!

Posted on 17. Posted on 17. Jun, 2009 by Dragos in Coding Jun, 2009 by Dragos in Coding

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Es labprāt vairākas reizes darīt ātri korekcijas manu kodu, neņemot vērā dažus vienkāršos matemātiskos principus. 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. Par piemēru, ja kaste ir vispirms 100px augsts un 60px plašs, un tad es paziņojis, ka šajā ailē neiederas vietā, kur bija paredzēts izvietot, ko es darīju bija atņemt 10 px no platumu lodziņā lai to piemērotu dažas zonas, un tajā pašā laikā man atņem 10 px no augstuma arī, domājot, ka tas es tur attiecība sākotnējo lielumu lodziņā. In fact this is not true! Patiesībā tas tā nav!

Here's why: Lūk, kādēļ:

The ratio of the initial box is 100px/60px=1.66 No sākuma kastē attiecība 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 Otrajā gadījumā attiecība: (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! Tātad, ja jūs izmantojāt, lai piemērotu pašu metodi kā es darīju, lai ātri mainītu izmēru objektiem, aizmirst par to, kā tas ir nepareizi! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Vietā izmantot veco metodi no skolas, lai noteiktu mainīgo no divām daļām, saglabājot proporcijas. 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). Atpakaļ uz iepriekš minētajam piemēram, lai uzzinātu jaunu augstuma vērtību lodziņā I'd lietot šo formulu: 100px/60px = (100px-10px) / x, SO x = 60px * 90px/100px = 54px (nevis nepareiza vērtību 50px). That's it! That's it!

Translate this post Tulkot šo ziņu


Related posts: Related posts:

  1. Coding: How to get code suggestions and function completion in Netbeans? Coding: Kā saņemt kodu ierosinājumus un darbību pabeigšanas NetBeans?
  2. Coding:How to fetch user profile data with SSI.php from a SMF forum database Coding: Kā ielādēt lietotāja profila datus ar SSI.php no SMF foruma datubāze

    blog comments powered by Disqus blog komentāriem powered by Disqus