Coding: Don't make mistakes when resizing objects! الترميز : لا نخطئ عندما ريسيزينج الكائنات! Preserve the initial ratio correctly! الحفاظ على نسبة الأولي بشكل صحيح!
Posted on 17. نشر في 17. Jun, 2009 by Dragos in Coding يونيو ، 2009 من قبل دراكوش في الترميز
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 مقصف من عرض مربع ، لذلك لاحتواء بعض المناطق ، و في نفس الوقت كنت تطرح 10 مقصف من الارتفاع أيضا ، ظنا منهم أن يفعل ذلك ظللت نسبة الأحجام الأولي للصندوق. 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) / س ، وبالتالي س = 60px * 90px/100px = 54px (بدلا من قيمة غير صحيحة 50px). That's it! هذا كل شيء!
No related posts. لا الوظائف ذات الصلة.












































