- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在转换我的 View ,但总是会发生一些奇怪的事情,我的意思是我使用以下代码计算角度:angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
并且 View 旋转但不正确。我的意思是它以正确的方向旋转,但角度总是不准确,约为 +/- 0.05 弧度。当我再次点击时, View 会旋转到正确的位置。有什么建议吗?将角度精确到逗号后的 5 个位置对我来说很重要。
Some NSLog to show you the problem:
First rotation first tap and second tap
2012-01-07 01:01:26.283 Wheel[9080:707] Angle: 0.598412
2012-01-07 01:01:29.281 Wheel[9080:707] Angle: -0.070008
Second rotation first tap and second tap
2012-01-07 01:01:31.103 Wheel[9080:707] Angle: -0.679809
2012-01-07 01:01:32.450 Wheel[9080:707] Angle: 0.092595
Third rotation first tap and second tap
2012-01-07 01:01:35.745 Wheel[9080:707] Angle: 0.607844
2012-01-07 01:01:36.945 Wheel[9080:707] Angle: -0.064927
Fourth rotation first tap and second tap
2012-01-07 01:01:41.073 Wheel[9080:707] Angle: -0.635756
2012-01-07 01:01:41.920 Wheel[9080:707] Angle: 0.052361
而且忘了告诉你,条件,点差越远越不准确。
编辑:
Circle *view = (Circle *) [self view];
for (CircleThumb *thumb in view.subviews) {
CGPoint point = [thumb convertPoint:thumb.centerPoint toView:nil];
CircleThumb *shadow = [[view.overlayView subviews] lastObject];
CGPoint centralPoint = [shadow convertPoint:shadow.centerPoint toView:nil];
CGRect shadowRect = [shadow.superview convertRect:shadow.frame toView:nil];
if (CGRectContainsPoint(shadowRect, point) == YES) {
CGPoint pointInShadowRect = [thumb convertPoint:thumb.centerPoint toView:shadow];
if (CGPathContainsPoint(shadow.arc.CGPath, NULL, pointInShadowRect, NULL)) {
CGAffineTransform current = view.transform;
CGPoint center = view.window.center;
CGPoint currentTouchPoint =centralPoint;
CGPoint previousTouchPoint = point;
long double angle = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
[UIView animateWithDuration:0.3f animations:^{
[view setTransform:CGAffineTransformRotate(current, angle)];
}];
[view.delegate circle:view didMoveToSegment:thumb.tag thumb:thumb];
NSLog(@"Angle: %Lf ", angle);
break;
}
}
}
这是“- touchesEnded: withEvent:”实现的一部分的代码
我正在制作类似于 Convert bot 中的控件。我的应用程序和 convertbot 的“轮子”看起来很相似,但我使用的是自定义绘图。
所以 Circle 是我们旋转的 UIView。 Circle 有 subview - CircleThumbs。 thumb 代表圆的单个部分。点计算正确但我不会解释为什么,因为没有必要。
最佳答案
阿坦计算永远不会完全正确。然后你让 iOS 再次计算出角度的 cos 和 sin(cgaffinetransformRotate 就是这样做的)。所以你在堆积三角函数的不准确性。而且由于您只计算与前一个角度的差异,我想您也在多次触摸事件中累积了不准确之处。
如果是旋转某物,则没有理由使用三角函数或角度。您可以使用线性代数完全实现这一点。像这样:
v.x = touch.x - center.x; v.y = touch.y - center.y;
float length = sqrt(v.x*v.x + v.y* v.y);
if (length < 5 ) break;
v.x /= length; v.y /= length;
// the rotation matrix is
// v.x -v.y
// v.y v.x
rot.x = previous.x * v.x + previous.y * v.y;
rot.y = previous.x * v.y - previous.y * v.x;
CGAffineTransform rotate = CGAffineTransformMake( rot.x, rot.y, -rot.y, rot.x, 0,0);
...
[view SetTransform:CGAffineTransformConcat ( current, rotate )];
...
previous.x = v.x;
previous.y = v.y;
此伪代码计算当前点的归一化向量(也存储了前一个点的向量)。然后我们定义一个矩阵,将先前的向量旋转到新的向量中。该矩阵与现有转换连接在一起。
如果旋转不是总是从前一个状态计算,而是从初始状态计算,那就更好了。诀窍是只为触地得分计算“先前”。
关于iphone - CGAffineTranformRotate atan2 不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8766128/
当然,您可以将剩余文件大小除以当前下载速度,但如果您的下载速度波动(而且它会波动),这不会产生很好的结果。有什么更好的算法可以产生更平滑的倒计时? 最佳答案 安exponential moving a
对于一个业余项目,我正在尝试对齐照片并创建 3D 图片。我基本上在一个钻机上有 2 个相机,我用来拍照。我会自动尝试以您获得 3D SBS 图像的方式对齐图像。 它们是高分辨率图像,这意味着需要处理大
当然,您可以将剩余的文件大小除以当前的下载速度,但如果您的下载速度波动(而且会波动),这不会产生很好的结果。什么是产生更平滑倒计时的更好算法? 最佳答案 安exponential moving ave
我有一个数据集,其中包含患有糖尿病和未患有糖尿病的人。我想使用这些数据训练一个模型来计算糖尿病状况未知的人的风险概率。我知道在培训中没有被诊断出糖尿病的人大多数都没有糖尿病,但很可能其中一些人可能患有
let parent = path[row-1] let child = path[row] let indexOfChild = matrix[parent.obje
我正在编写一些使用 Element.getBoundingClientRect 的代码(gBCR),加上内联样式更新,以执行计算。 这不适用于一般网站,我不关心或不感兴趣是否有“更好的 CSS 方式”
我有一个很大的 csv 文件,其中包含大量脏数据,我想通过消除所有不是绝对必要的值来稍微清理一下它。 Here是我正在谈论的文件。 它有以下组件: 网站,标题,开始日期,开始日期,雇主,地点,纬度,
有谁知道一个库,它为 Java 提供了一个错误不高于 1-2 毫秒的 Thread.sleep()? 我尝试了 sleep 、错误测量和 BusyWait 的混合,但在不同的 Windows 机器上我
UiApp有DateBox和 DateTimeFormat 对于那个类(class)。但是,不存在诸如 TimePicker 或 TimeBox 这样的东西,用户可以通过明确指定的方式(例如通过使用
因此,我使用 sklearn 的 svm.SVC 模块编写了一个程序来学习 mnist 数据集,出于某种原因,每当我计算其准确性为 100% 时。这似乎好得令人难以置信,这是预期的吗? from sk
我当前找到了 gpytorch ( https://github.com/cornellius-gp/gpytorch )。它似乎是将 GPR 集成到 pytorch 中的一个很棒的包。第一次测试也呈
我正在使用 QT Creator 5.9 创建一个简单的 Web 浏览器模型,我的 EditLine/Text Box 有问题: 1.如何在转到不同的网站/页面后自动更新显示的 URL 字符串。 2。
我在 Linux 上尝试 time -p 命令,我写了一些代码来浪费 CPU 周期: #include using namespace std; int main() { long int c;
亲爱的程序员/脚本编写者/工程师/其他人, 问题:我目前正在为 Android 3.2 平板电脑开发增强现实应用程序,但在获取准确的罗盘读数方面遇到一些问题。我需要确切地知道平板电脑所面向的 (z)
我最近一直在尝试了解 Apache Spark 作为 Scikit Learn 的替代品,但在我看来,即使在简单的情况下,Scikit 收敛到准确模型的速度也远远快于 Spark。例如,我使用以下脚本
如果不是,它的准确性如何? 我想在下载之前知道图片的大小。 最佳答案 HTTP Content-length header 是否格式错误?是的。 您是否应该相信它能公平地表示消息正文的大小?是的。 关
这是一个关于 ngram 线性回归的问题,使用 Tf-IDF(术语频率 - 逆文档频率)。为此,我使用 numpy 稀疏矩阵和 sklearn 进行线性回归。 使用一元语法时,我有 53 个案例和 6
对于某些给定的固定宽度,如何计算特定标签 (NSTextField) 中字符串的高度? 我用谷歌搜索了各种方法并尝试了 this method from Apple .它的工作原理,除了高度变成一行对
我是一名优秀的程序员,十分优秀!