在缩放时翻译x,y [英] Translating x,y while scaling

查看:316
本文介绍了在缩放时翻译x,y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制x,y坐标,其中窗口大小为600px乘600px。 (0,0)将在左上角。
(300,300)窗口中间。
(600,600)将在右下角。
我试图将纬度/经度(以弧度表示)转换为像素,然后绘制它们。
我计算1px =? lat by

I'm trying to graph x,y coordinates where the window size is 600px by 600px. (0,0) would be in the top left. (300,300) middle of the window. (600,600) would be in the bottom right. I am trying to translate latitude/longitude in radians to pixels and then plotting them. I'm calculating 1px = ? lat by

`fabs(lborder+rborder)/600`

我通过获取顶部和底部边框计算lon。
当我想为特定的纬度或经度找到特定位置时:

I calculated lon by taking the top and bottom borders. Then when I want to find a specific position for a specific lat or lon:

lat/(previous # calculated above)



<分数,我不知道如何移动他们,我不知道如何将它们的中心在300,300左右的界限变化。

Problem is my window goes from 0,0 to 600,600 as explained above and I can get negative points and I'm not sure how to move them and I don't know how to center them around 300,300 when the bounds change.

目前,只要我使中心(0,0)在(x,y),而不是像素,点被绘制在他们应该去的地方。
例如,如果x是-1到1,y是-3到3,(300px,300px)将是(0,0)。

At the moment, as long as I make the center (0,0) in terms of (x,y), not pixels, points get plotted where they're supposed to go. For example, if x is -1 to 1 and y is -3 to 3, (300px,300px) would be (0,0).

如果我改变界限说x -.5到1和y -3到.5,(300px,300px)将是(.25,1.25)。然而,上面的计算与这些数字。

If I change the bounds to say x -.5 to 1 and y -3 to .5, (300px,300px) would be (.25, 1.25). However, the calculations above with these numbers.

1.5/600 = .0025 ----> 1px = .0025lat.
3.5/600 = .0058 ----> 1px = .0058lon.

然后取中点(.25,1.25):

Then taking the midpoint (.25,1.25):

.25/.0025 = 100px
1.25/.0058 = 215px

$

任何想法都是非常有帮助的。

Any ideas would be extremely helpful.

推荐答案

如果你想调整坐标到中心,那么也许这样吗?

If you would like to adjust the coordinates to the center, then maybe somthing like this?

Coord coordsFromCenter(Coord old_coord, float height, float width)
{
    Coord new_center;

    float new_x_center = width/2.0;
    float new_y_center = height/2.0;

    new_center.set_x(old_coord.get_x() - new_x_center);
    new_center.set_y(old_coord.get_y() - new_y_center);

    return new_center;
}

这篇关于在缩放时翻译x,y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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