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 Оновлення через RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… Головна / кодування / Формат: Не робіть Mis ...

Coding: Don't make mistakes when resizing objects! Формат: не роблять помилок при зміні розмірів об'єкта! Preserve the initial ratio correctly! Зберегти первісний співвідношенні правильно!

Posted on 17. Опублікований 17. Jun, 2009 by Dragos in Coding Червень, 2009 Dragos в кодування

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. Для прикладу, якщо вікно в першу чергу 100px високий і широкий 60px, а потім я помітив, що ця коробка не підходить до місця, де він був призначений для розміщення, що я зробив, було відняти 10 PX від ширини вікна за це з урахуванням деяких областях, і в той же час я віднімається 10 PX з висоти і, думаючи, що це я все співвідношення первинних розмірів вікна. In fact this is not true! Насправді це не так!

Here's why: І ось чому:

The ratio of the initial box is 100px/60px=1.66 Відношення початкове вікно 100px/60px = 1,66

In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 У другому випадку це співвідношення складає: (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). Повертаючись до прикладу вище, для того, щоб дізнатися нове значення висоти вікна я б використав цю формулу: 100px/60px = (100px-10px) / г, так що X = 60px * 90px/100px = 54px (замість неправильні значення 50px). That's it! От і все!

Translate this post Перекласти цю посаду


No related posts. Немає відповідних посад.

    blog comments powered by Disqus Блог коментарі сила Disqus