简体   繁体   English

是obj.style.WebkitTransform =“rotate(”+ degree +“deg)”; 非常精准?

[英]Is obj.style.WebkitTransform = “rotate(”+degree+“deg)”; very accurate?

Will the rotate function be not exactly accurate when I inspect it in small degree values like 1 deg? 当我以1度的小度值检查它时,旋转功能是不是完全准确?

Because I noticed that, my calculation results are correct but there are chances the object tilts a little bit more or less. 因为我注意到了,我的计算结果是正确的,但是物体有可能倾斜一点点或更少。

I create a 1 hour count-down clock with the js-control-css rotation, but it have some chances going a little misalignment, while the calculated values are correct. 我使用js-control-css旋转创建一个1小时的倒计时时钟,但它有一些机会略微错位,而计算的值是正确的。 http://jsbin.com/exIFAPIS/1/ ( you can adjust the start time at the beginning of the javascript called "sendTime") http://jsbin.com/exIFAPIS/1/ (您可以调整javascript开头的开始时间,称为“sendTime”)

Could any one help me out or give some hints or possible reasons? 任何人可以帮助我或给出一些提示或可能的原因吗?

Thanks so much! 非常感谢!

First of, awesome timer bud! 首先,令人敬畏的计时器萌芽!

The whole thing works pretty well, so well in fact that I really wanted to solve your problem just to see it work perfectly. 整个过程非常好,事实上我真的很想解决你的问题只是为了让它完美运行。

The issue is that the rotate is off by only a degree. 问题是旋转只有一定程度的关闭。 This seems small but its actually a large margin of error for the rotate property to be viable. 这似乎很小,但实际上旋转属性可行的误差很大。 Otherwise it'd be easy to tell in normal day to day applications. 否则,在日常应用中很容易辨别。 Such as basic 90 and 180 degree transformations. 如基本的90度和180度变换。 181-179 is a big difference. 181-179是一个很大的区别。

To illustrate this point check out this fiddle: 为了说明这一点,请查看这个小提琴:

http://jsfiddle.net/agconti/x8PFL/1/ http://jsfiddle.net/agconti/x8PFL/1/

html: HTML:

<div id="div-1"><p>reference text</p></div>
<div id="div-2"><p>reference text</p></div>
<div id="div-3"><p>reference text</p></div>
<div id="div-4"><p>reference text</p></div>

css: CSS:

div { 
    width: 100px; 
    height:100px; 
    border: 1px solid black; 
    display:inline-block;
}
p{ margin: 25%; text-decoration:underline;}
#div-2 {
    -webkit-transform: rotate(179deg);
    -moz-transform: rotate(179deg);
    transform: rotate(179deg);
}

#div-3 {
    -webkit-transform: rotate(181deg);
    -moz-transform: rotate(181deg);
    transform: rotate(181deg);
}
#div-3 {
    -webkit-transform: rotate(181deg);
    -moz-transform: rotate(181deg);
    transform: rotate(181deg);
}
#div-3 {
    -webkit-transform: rotate(181deg);
    -moz-transform: rotate(181deg);
    transform: rotate(181deg);
}
#div-4 {
    -webkit-transform: rotate(179.8deg);
    -moz-transform: rotate(179.8deg);
    transform: rotate(179.8deg);
}

You can see that even in div-4 there is a level of distortion (aka its not perfectly straight ). 你可以看到,即使在div-4也存在一定程度的失真(也就是说它不是完全直的)。 That means that the rotate property is reasonably accurate up to 1 decimal place 这意味着rotate属性相当精确,最多可达1位小数

( +/- 1 decimal place if you bring it to 179.9deg ). (如果你把它带到179.9deg小数点后+/- 1)。 So to answer your first question; 那么回答你的第一个问题; yes, the rotate property is accurate to at least 1 degree. 是的,rotate属性精确到至少1度。

Because your example is off by at approximately 0.5 degrees (after adjusting it by eye), it seems clear that your calculation must be off and not the rotate property, since 0.5 degrees is well within the property's tolerance.[1] 因为你的例子在大约0.5度(在通过眼睛调整之后)关闭了,所以你的计算似乎必须关闭而不是旋转属性,因为0.5度完全在属性的容差范围内。[1]

[1](STD +/- 1 deg --> 5 deg is 5 times the standard deviation, (this is loosely said of course)). [1](STD +/- 1度 - > 5度是标准偏差的5倍,(当然,这是松散的))。

I'm not ruling out that cumulative rounding from your calculations could cause the error, it seems unlikely given the tests. 我不排除你的计算累积舍入可能导致错误,考虑到测试似乎不太可能。 If you check your math and are still running into the error, to protect yourself against precision loss, you could do you decimal calculations as integers and divide the result for the your transform value. 如果检查数学并且仍然遇到错误,为了防止精度损失,可以将十进制计算作为整数,并将结果除以转换值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM