获取方位角接近 0 的位置的 point.x

发布于 2024-12-16 10:52:12 字数 1555 浏览 2 评论 0原文

我正在开发自己的增强现实引擎。

在此 教程 中,我找到了如何使用 iPhone 的方位在屏幕上显示点屏幕尺寸和相机视野:

+ (CGPoint) calculatePositionFor:(float)deltaOrient screenSize:(CGSize)screenSize fov:(float)fov
{
    CGPoint point;

    CGFloat x = (screenSize.width / 2.0f) + (deltaOrient * (screenSize.width / (fov / 2.0f)));
    CGFloat y = screenSize.height / 2.0f;

    point = CGPointMake(x, y);

    return point;
}

其参数为:

deltaOrient:是位置的方位减去设备航向。 screenSize: iPhone 的屏幕尺寸。 fov: 相机的视野。

它工作正常,直到我想显示北部附近的位置。当设备航向从 1 度变为 359 度时,它不起作用。

我收到此日志:

2011-11-16 15:10:16.067 AREngineDemo[310:707] Beta: 7.005, Heading: 2.504323, X: 234.424377
2011-11-16 15:10:16.104 AREngineDemo[310:707] Beta: 7.005, Heading: 1.504323, X: 250.961853
2011-11-16 15:10:16.117 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.149 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.172 AREngineDemo[310:707] Beta: 7.005, Heading: 359.504333, X: -5669.451660
2011-11-16 15:10:16.195 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.217 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.244 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551

X 坐标从 247 变为 -5669。这是一个错误。

我想知道如何解决它,我还不知道如何解决。

有什么线索吗?

I'm developing my own augmented reality engine.

In this tutorial I've found how to display a point on screen using its bearing, iPhone screen size and camera field of view:

+ (CGPoint) calculatePositionFor:(float)deltaOrient screenSize:(CGSize)screenSize fov:(float)fov
{
    CGPoint point;

    CGFloat x = (screenSize.width / 2.0f) + (deltaOrient * (screenSize.width / (fov / 2.0f)));
    CGFloat y = screenSize.height / 2.0f;

    point = CGPointMake(x, y);

    return point;
}

Its parameters are:

deltaOrient: is location's bearing minus device heading.
screenSize: iPhone's screen size.
fov: camera's field of view.

It works fine until I want show a location near North. When device heading goes from 1 degree to 359 degrees it doesn't work.

I get this log:

2011-11-16 15:10:16.067 AREngineDemo[310:707] Beta: 7.005, Heading: 2.504323, X: 234.424377
2011-11-16 15:10:16.104 AREngineDemo[310:707] Beta: 7.005, Heading: 1.504323, X: 250.961853
2011-11-16 15:10:16.117 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.149 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.172 AREngineDemo[310:707] Beta: 7.005, Heading: 359.504333, X: -5669.451660
2011-11-16 15:10:16.195 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.217 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.244 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551

X coodinate goes from 247 to -5669. This is an error.

I'm trying to wonder how to fix it, I don't know how yet.

Any clue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2024-12-23 10:52:12

看起来 deltaOrient 的计算很幼稚。当它从0到359时,它可能等于359而不是-1。这显然是一个问题。

我想不出一个好的简单的解决方案来解决这个问题,但你至少可以通过像这样的 hack 来测试:

if(deltaOrient > 180) deltaOrient -= 360;
else if(deltaOrient < -180) deltaOrient += 360;

It looks like the calculation of deltaOrient is naive. When it goes to 359 from 0, it's probably equal to 359 instead of -1. That's obviously an issue.

I can't think of a good and simple solution to the problem, but you could at least test by doing a hack like this:

if(deltaOrient > 180) deltaOrient -= 360;
else if(deltaOrient < -180) deltaOrient += 360;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文