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 | אימייל Get updates via feedburner Get updates via twitter
Home / Coding / Coding: Don't make mis… דף הבית / Coding / Coding: אל תעשה רע ...

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, אז x = 60px * 90px/100px = 54px (במקום הערך השגוי של 50px). That's it! זהו זה!

Translate this post תרגם פירסום


No related posts. הודעות לא קשורות.

    blog comments powered by Disqus תגובות לבלוג powered by Disqus