Coding: Don't make mistakes when resizing objects! Codificació: No cometre errors en canviar la mida dels objectes! Preserve the initial ratio correctly! Preservar la relació inicial correctament!
Posted on 17. Publicat a 17. Jun, 2009 by Dragos in Coding Juny de 2009, per Dragos a la codificació de
I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Vaig estar temptat moltes vegades per a ajustaments ràpids al meu codi, sense tenir en compte alguns principis bàsics de matemàtiques. 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. Per exemples, si un quadre és, abans que res 100px d'alçada i 60px d'ample, i després m'adono que aquest quadre no encaixa en el lloc on estava destinada a ser col.locada, el que va fer va ser restar 10 px de l'amplada de la caixa, per tal que s'ajusti a alguna zona, i al mateix temps, em resta 10 px de l'alçada també, pensant que fer, així que va mantenir la relació entre la mida inicial de la caixa. In fact this is not true! En realitat això no és cert!
Here's why: Heus aquí per què:
The ratio of the initial box is 100px/60px=1.66 La relació entre el quadre inicial és 100px/60px = 1,66
In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 En el segon cas la proporció és: (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! Així que, si ha utilitzat per aplicar la mateixa tècnica que vaig fer ràpidament canviar la mida dels objectes, oblidar-se d'ell, ja que està malament! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. En el seu lloc utilitza el vell mètode de l'escola per determinar una variable de dues fraccions, conservant les proporcions. 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). Tornar a l'exemple anterior, per tal d'esbrinar el valor de la nova alçada de la caixa que faria ús d'aquesta fórmula: 100px/60px = (100px-10px) / x, de manera que x = 60px * 90px/100px = 54px (en lloc de la el valor incorrecte de 50px). That's it! Això és!
No related posts. No relacionats amb llocs.












































