Map 的鸟瞰图或 2.5D 渲染问题 [英] Problem with bird's eye view or 2.5D rendering of Map

查看:13
本文介绍了Map 的鸟瞰图或 2.5D 渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个转弯导航软件,我正在使用以下解决方案将我的道路线变成 2.5D 或 3D 视图

.

在您最初的问题中,您提到渲染图像的非仿射变换太慢了.看来您现在已经切换到在渲染线条之前对其进行转换,这已经足够快了.您现在唯一需要做的就是更改转换.

这是一个建议的变换.只需几个步骤,即可将您的 2D (x,y) 坐标转换为 2.5D (u,v) 坐标.我假设您使用的是 C#.

t = 0.3//倾斜角度 - 尝试不同的值X = x - w/2 ;Y = y - h/2 ;a = h/(h + Y*Math.Sin(t)) ;u = a*X + w/2 ;v = a*Y*Math.Cos(t) + h/2 ;

这里有一个参数t定义了倾斜的量,用弧度表示.我建议使用 0.3 左右的值,正负值.

我已经用铅笔和纸解决了这个问题,但没有运行它,所以如果这不起作用,请告诉我 .. 总是有可能存在转录错误.

更新:您要避免绘制任何具有点 (x,y) 的实体(线、多边形等),使得 a 是非正数.更好的是,为避免溢出,您应该避免在 a 时绘制,其中 epsilon 是一些小的正值,例如 0.05 或 0.1.

I'm developing a turn-by-turn navigation software and I'm using the following solution to make my lines of roads into 2.5D or 3D View

Draw 2.5D or 3D Map with C# from lines

However, above solution is quite okay for lines within the view port which is 0 < x < width and 0 < y < height . However there are lines that its points may have y < 0 or x < 0 or y > height or x > width and then the above solution gone crazy. Could anyone help me figure out how to solve the problem?

vvvv With 3D algorithm vvvv

.

vvvv Without 3D algorithm vvvv

Update:: After using this code

double x = p->x();
double y = p->y();

double t = -0.5;
x = x - w / 2;
y = y - h / 2;
double a = h / (h + y* sin(t));
double u = a * x + w / 2;
double v = a * y * cos(t) + h / 2;

p->setX(u);
p->setY(v);
return p;

The map become like following

I think there's something wrong with Y calculations when they go way beyond negative values. I'm using Qt and cracks at line seems bug with Qt renderer, not related to our original problem.

解决方案

The problem is that the transformation you are using does not map straight lines to straight lines. Rather, straight lines generally go to parabolas. You can see that in the example images, where the more-or-less-straight main road going from top to bottom in the 2D view is transformed to a curved road in the 2.5D view. You would see the same thing for the lines that "go crazy" in your example if you broke them up into shorter segments.

Mathematically, you can see what is going on by going back to the transform you're using:

x_ = (x - w/2)*(t1+(y/h)*(t2-t1)) + w/2
y_ = y

If we express a straight line as x = ay+b, then a point (ay+b,y) on this line maps to (ay+b - w/2)*(t1+(y/h)*(t2-t1)) + w/2,y). This expression looks complicated, but you can see that it evaluates to something like (c*y^2+d*y+e,y), for suitable values of c,d,e, which is a parabola.

So your best bet is to abandon this transform and switch to a perspective transform.

In your original question, you mentioned that a non-affine transform of a rendered image was too slow. It seems that you have now switched to transforming the lines before rendering them, and that is fast enough. The only thing you have to do now is change the transform.

Here's a suggested transform. It is a couple of steps, and takes your 2D (x,y) coordinates to some 2.5D (u,v) coordinates. I assume you're using C#.

t = 0.3 // tilt angle - try different values    
X = x - w/2 ;
Y = y - h/2 ;
a = h/(h + Y*Math.Sin(t)) ;
u = a*X + w/2 ;
v = a*Y*Math.Cos(t) + h/2 ;

There is a parameter t here that defines the amount of tilt, expressed in radians. I'd suggest playing with a value of somewhere around 0.3, plus or minus.

I've worked this out with pencil and paper, but not run it, so let me know if this doesn't work .. it's always possible that there's been a transcription error.

Update: You want to avoid drawing any entity (line, polygon, whatever) that has a point (x,y) such that a is non-positive. Better still, to avoid overflow, you should avoid drawing when a<epsilon, where epsilon is some small positive value like 0.05 or 0.1.

这篇关于Map 的鸟瞰图或 2.5D 渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆