Coding: Don't make mistakes when resizing objects! Coding: Gör inga misstag när storleksändring objekt! Preserve the initial ratio correctly! Bevara den ursprungliga kvoten korrekt!
Posted on 17. Posted on 17. Jun, 2009 by Dragos in Coding Juni, 2009 av Dragos i Coding
I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Jag var frestad många gånger att göra snabba justeringar av min kod, utan att beakta några grundläggande matematiska principer. 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. Till exempel om en låda är först 100px lång och 60px bred, och sedan upptäcker jag att detta fält inte passar den plats där den var avsedd att släppas ut, vad jag gjorde var att subtrahera 10 px från bredden på rutan för att passa något område, och samtidigt som jag dras 10 px från höjden också, tänker att göra det jag höll tal av den ursprungliga storleken på rutan. In fact this is not true! I själva verket är detta inte sant!
Here's why: Här är anledningen:
The ratio of the initial box is 100px/60px=1.66 Förhållandet mellan den ursprungliga boxen 100px/60px = 1,66
In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 I det andra fallet blir förhållandet: (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! Så, om du använt för att tillämpa samma teknik som jag gjorde för att snabbt ändra storlek på objekt, glöm det, eftersom det är fel! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Istället använder den gamla metoden från skolan för att bestämma en variabel från två fraktioner, bevara nyckeltal. 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). Tillbaka till exemplet ovan, för att ta reda på den nya höjden värdet i rutan skulle jag använda denna formel: 100px/60px = (100px-10px) / x, så x = 60px * 90px/100px = 54px (i stället för felaktigt värde 50px). That's it! That's it!
No related posts. Inga relaterade tjänster.












































