Project 2D指向3D球体,每个国家/地区使用单个对象 [英] Project 2D points to 3D sphere, single object for every country

查看:87
本文介绍了Project 2D指向3D球体,每个国家/地区使用单个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maya,并且试图创建一个3D球形地球,其中所有国家/地区都被对象隔开,因此以后可以将文件导出到Unity. 借助此代码,我创建了代表地球的平面.

I'm using Maya and I'm trying to create a 3D sphere of the earth with all countries separated by objects, so I can later export the file to Unity. With this code i create planes that represent the Earth.

我设法用所有竞争的2D geojson点创建了一个地球平面.现在,我试图将这些点投影到3D球面.

I managed to create a plane of the Earth with 2D geojson points of all contries. And now I am trying to project those points to 3D sphere.

使用此代码,我创建了一个地球Earth

With this code I create a plane Earth

# EXAMPLE OF THE POINTS FORMAT

d = {"type":"FeatureCollection","features":[
{"type":"Feature","id":"ALB","properties":{"name":"Albania"},"geometry":{"type":"Polygon","coordinates":[[[20.590247,41.855404],[20.463175,41.515089],[20.605182,41.086226],[21.02004,40.842727],[20.99999,40.580004],[20.674997,40.435],[20.615,40.110007],[20.150016,39.624998],[19.98,39.694993],[19.960002,39.915006],[19.406082,40.250773],[19.319059,40.72723],[19.40355,41.409566],[19.540027,41.719986],[19.371769,41.877548],[19.304486,42.195745],[19.738051,42.688247],[19.801613,42.500093],[20.0707,42.58863],[20.283755,42.32026],[20.52295,42.21787],[20.590247,41.855404]]]}},
{"type":"Feature","id":"ARE","properties":{"name":"United Arab Emirates"},"geometry":{"type":"Polygon","coordinates":[[[51.579519,24.245497],[51.757441,24.294073],[51.794389,24.019826],[52.577081,24.177439],[53.404007,24.151317],[54.008001,24.121758],[54.693024,24.797892],[55.439025,25.439145],[56.070821,26.055464],[56.261042,25.714606],[56.396847,24.924732],[55.886233,24.920831],[55.804119,24.269604],[55.981214,24.130543],[55.528632,23.933604],[55.525841,23.524869],[55.234489,23.110993],[55.208341,22.70833],[55.006803,22.496948],[52.000733,23.001154],[51.617708,24.014219],[51.579519,24.245497]]]}}
...

for feat in d.get("features"):
    r = []
    coords = feat.get("geometry").get("coordinates")
    type = feat.get("geometry").get("type")
    for coord in coords:
        for c in coord:
            if type == "MultiPolygon":
                r = []
                for a in c:
                    r.append((a[0],a[1],0))
                poly = cmds.polyCreateFacet(p=r)
                poly = cmds.rename(feat.get("properties").get("name"))
            else:
                r.append((c[0],c[1], 0))

    if not type == "MultiPoligon":
    poly = cmds.polyCreateFacet(p=r)
        poly = cmds.rename(feat.get("properties").get("name"))

搜索如何将2d点投影到3d球体上:

Searching about how to project 2d points onto 3d sphere found:

如何映射2d网格点(x,y)作为3d点(x,y,z)到球上 https://forums.tigsource.com/index.php?topic=17522.0

我也寻找墨卡托投影 https://wiki.openstreetmap.org/wiki/Mercator#Elliptical_.28true. 29_Mercator_Projection https://en.wikipedia.org/wiki/Mercator_projection

I also looked up for Mercator Projection https://wiki.openstreetmap.org/wiki/Mercator#Elliptical_.28true.29_Mercator_Projection https://en.wikipedia.org/wiki/Mercator_projection

我尝试过...


def range_n(n, min, max):
    return ((n - min) / (max - min)) * (1 - 0) + 0

def to_3d_v3(x,y):
    # this points are the bounds of the points
    x = range_n(x, -180, 180)
    y = range_n(y, -85.609038, 42.688247)

    phi = y * 2 * math.pi
    z = 2 * x -1
    rho = math.sqrt(1-z*z)
    rho = 20

    x = rho * x
    y = rho * math.log(math.tan((y + math.pi/2)/2))

    return (rho * math.cos(x) * math.cos(y), rho * math.cos(x) * math.sin(y), rho * math.sin(x))

def to_3d_v2(x,y):
    x = range_n(x, -180, 180)
    y = range_n(y, -85.609038, 42.688247)

    z = -1 + 2 * x
    phi = 2 * math.pi * y
    theta = math.asin(z)
    return (math.cos(theta) * math.cos(phi), math.cos(theta) * math.sin(phi), z)

def to_3d(x,y):
    x = range_n(x, -180, 180)
    y = range_n(y, -85.609038, 42.688247)

    z = 2 * x -1
    phi = y * x -1
    rho = 1
    rho = math.sqrt(1-z*z)
    return (rho * math.cos(y), rho * math.sin(y), z)

# not a lof of changes
# just filtering all points with to_3d function
for feat in d.get("features"):
    r = []
    coords = feat.get("geometry").get("coordinates")
    type = feat.get("geometry").get("type")
    for coord in coords:
        for c in coord:
            if type == "MultiPolygon":
                r = []
                for a in c:
                    r.append(to_3d(a[0],a[1]))
                poly = cmds.polyCreateFacet(p=r)
                poly = cmds.rename(feat.get("properties").get("name"))
            else:
                r.append(to_3d(c[0],c[1]))
    #print(feat.get("id"), r)

    if not type == "MultiPoligon":
        poly = cmds.polyCreateFacet(p=r)
        poly = cmds.rename(feat.get("properties").get("name"))

但是结果是像这样的一些奇怪的事情

But the result was some weird things like this

to_3d_v3:

to_3d_v3:

to_3d_v2:

to_3d_v2:

to_3d:

有什么建议吗?

谢谢

推荐答案

由于您将x和y用作经度和纬度,因此应将它们直接输入公式中以将纬度/经度投影到球体上如何将2d网格点(x,y)映射到球体上作为3d点(x,y,z).

Since you're using x and y as longitude and latitude, you should feed them directly into the formula for projecting latitude/longitude to a sphere how map 2d grid points (x,y) onto sphere as 3d points (x,y,z).

此外,由于x是水平位置,因此表示x是经度.同样,y是垂直位置,所以y是纬度.你把它们倒退了.

Also, since x is horizontal position, that means x is longitude. Similarly, y is vertical position, so y is latitude. You had them backwards.

def to_3d_v4(x,y):
    #convert from degrees to radians
    longitude = math.radians(x)
    latitude = math.radians(y)

    # select a radius:
    radius = 10

    # project to 3d
    return (
        rho * math.cos(latitude) * math.cos(longitude), 
        rho * math.cos(latitude) * math.sin(longitude), 
        rho * math.sin(latitude)
    )

这篇关于Project 2D指向3D球体,每个国家/地区使用单个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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