直角坐标转换为极坐标的Java包

发布于 2024-08-24 04:33:36 字数 75 浏览 2 评论 0原文

我需要将直角坐标转换为极坐标。你能推荐一个我可以使用的库吗,我不想自己写这个。

这用于理解天文学图像文件中包含的元数据。

I need to convert rectangular coordinates to polar coordinates. Can you recommend a library that I can use, I would rather not have to write this myself.

This is used for making sense of metadata included in astronomy image files.

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

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

发布评论

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

评论(3

等往事风中吹 2024-08-31 04:33:36

我很确定标准库已经有这个了。如果存在虚数类型,它们正是这样做的(real = x,imag = y,arg(val)=角度,abs(val)=半径)。使用数学库(atan2、sin、cos 和 sqrt)也不是那么困难。

I am pretty sure the standard library already has this. If there are imaginary number types, they do precisely this (real = x, imag = y, arg(val) = angle, abs(val) = radius). Using the math library (atan2, sin, cos and sqrt) isn't that difficult either.

幻梦 2024-08-31 04:33:36

这不是就像两个函数吗?当然,您可以用任何语言搜索它并自行转换。

这是我做矩形的代码 ->在 C++ 中,极性(另一种方式非常简单)

Vector3 C2P (const Vector3 &v)
{
        float PI=3.14159260f;
        Vector3 polar;
       polar.x = v.Length();

       if (v.z > 0.0f) {
              polar.y = (float) atan ( v.z/sqrt (v.x * v.x + v.y * v.y));
       }
       else if (v.z < 0.0f) {
               polar.y = (float) -atan (sqrt (v.x * v.x + v.y * v.y) / v.z);
        }
        else {

                polar.y = 0.0;
        }


        if (v.x > 0.0f) {
                polar.z = (float) atan (v.y / v.x);
        }
        else if (v.x < 0.0f) {
               polar.z = (float) atan (v.y / v.x) + PI;
        }
        else if (v.y > 0) {
                polar.z = PI * 0.5f;
      }
     else {
              polar.z = -PI * 0.5f;
        }
       //polar.z=(polar.z/M_PI)*180;
       //polar.y=(polar.y/M_PI)*180;
       return polar;
}

注意结果是 x = 长度,y = 角度 1 z = 角度 2,以弧度为单位。

编辑:
我的代码是指我从某处窃取并使用过的一些代码。

isn't this just like 2 functions? surely you could just search for it in any language and convert it yourself.

here is my code to do rectangular -> polar (the other way is very easy) in c++

Vector3 C2P (const Vector3 &v)
{
        float PI=3.14159260f;
        Vector3 polar;
       polar.x = v.Length();

       if (v.z > 0.0f) {
              polar.y = (float) atan ( v.z/sqrt (v.x * v.x + v.y * v.y));
       }
       else if (v.z < 0.0f) {
               polar.y = (float) -atan (sqrt (v.x * v.x + v.y * v.y) / v.z);
        }
        else {

                polar.y = 0.0;
        }


        if (v.x > 0.0f) {
                polar.z = (float) atan (v.y / v.x);
        }
        else if (v.x < 0.0f) {
               polar.z = (float) atan (v.y / v.x) + PI;
        }
        else if (v.y > 0) {
                polar.z = PI * 0.5f;
      }
     else {
              polar.z = -PI * 0.5f;
        }
       //polar.z=(polar.z/M_PI)*180;
       //polar.y=(polar.y/M_PI)*180;
       return polar;
}

note the result is x = length, y = angle1 z = angle2, in radians.

EDIT:
by my code, I mean some code that I stole from somewhere and used like once.

迷路的信 2024-08-31 04:33:36

您要求的是地图投影库。最流行的开源库之一是 PROJ.4 并且有一个 Java 实现 它。

您必须决定要使用哪种投影。它们具有不同的属性。 墨卡托 很常见,也是 Google 地图使用的一种。墨卡托的缺点是不能在北极周围使用它。

What you are asking for is a Map Projection Library. One of the most popular open source libraries are PROJ.4 and there is one Java Implementation of it.

You have to decide what projection you want to use. They have different properties. Mercator is common and is the one that Google Maps is using. The disadvantage with Mercator is that you can not use it around the arcitc poles.

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