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… บ้าน / รหัส / รหัส: อย่าทำผิดพลาด ...

Coding: Don't make mistakes when resizing objects! รหัส: อย่าทำผิดพลาดเมื่อปรับขนาดอบเจกต์! Preserve the initial ratio correctly! รักษาอัตราส่วนเริ่มต้นอย่างถูกต้อง!

Posted on 17. โพสต์ใน 17. Jun, 2009 by Dragos in Coding มิ.ย., 2,009 โดย Dragos ใน รหัส

I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. ฉัน tempted หลายครั้งที่จะปรับเปลี่ยนอย่างรวดเร็วรหัสของฉันโดยไม่มีการพิจารณาหลักการพื้นฐานทางคณิตศาสตร์บาง. 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 จากความกว้างของช่องที่เพื่อให้พอดีกับพื้นที่บางส่วนและในเวลาเดียวกันฉัน subtracted 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. แทนที่จะใช้วิธีการเก่าจากโรงเรียนเพื่อตรวจสอบตัวแปรจากสอง fractions, รักษาอัตราส่วน. 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 100px/60px-10px) / x ดังนั้น x = 60px * 90px/100px = 54px (แทนค่าที่ไม่ถูกต้อง 50px). That's it! ที่มัน

Translate this post แปลบทความนี้


No related posts. ไม่มีบทความที่เกี่ยวข้อง.

    blog comments powered by Disqus บล็อกความคิดเห็นขับเคลื่อนโดย Disqus