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: Don't make mistakes when resizing objects! 编码:不要犯错误时缩放对象! Preserve the initial ratio correctly! 保留的初步比例正确!

Posted on 17.发布17。 Jun, 2009 by Dragos in Coding 2008年6月,由德拉戈什 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)/ x内,因此x = 60px * 90px/100px = 54px(而不是新的高度值在50像素不正确的值)。 That's it!就是这样!

Translate this post翻译这个职位


No related posts.没有相关的职位。

    blog comments powered by Disqus 博客评论 Disqus