2D 项目指向 3D 球体,每个国家/地区的单个对象
Project 2D points to 3D sphere, single object for every country
我正在使用 Maya,我正在尝试创建一个 3D 地球球体,其中所有国家/地区由对象分隔,以便稍后可以将文件导出到 Unity。
使用此代码,我创建了代表地球的平面。
我设法用所有国家的 2D geojson 点创建了一个地球平面。现在我正在尝试将这些点投影到 3D 球体。
用这段代码我创建了一个平面地球
# 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 球体上找到:
how map 2d grid points (x,y) onto sphere as 3d points (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
我试过了...
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"))
但结果是这样的一些奇怪的事情
to_3d_v3:
to_3d_v2:
to_3d:
请问有什么建议吗?
谢谢
由于您使用 x 和 y 作为经度和纬度,因此您应该将它们直接输入到将 latitude/longitude 投影到球体 how map 2d grid points (x,y) onto sphere as 3d points (x,y,z).
的公式中
另外,由于x
是水平位置,也就是说x
是经度。同样,y
是垂直位置,所以 y
是纬度。你把它们弄反了。
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)
)
我正在使用 Maya,我正在尝试创建一个 3D 地球球体,其中所有国家/地区由对象分隔,以便稍后可以将文件导出到 Unity。 使用此代码,我创建了代表地球的平面。
我设法用所有国家的 2D geojson 点创建了一个地球平面。现在我正在尝试将这些点投影到 3D 球体。
用这段代码我创建了一个平面地球
# 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 球体上找到:
how map 2d grid points (x,y) onto sphere as 3d points (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
我试过了...
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"))
但结果是这样的一些奇怪的事情
to_3d_v3:
to_3d_v2:
to_3d:
请问有什么建议吗?
谢谢
由于您使用 x 和 y 作为经度和纬度,因此您应该将它们直接输入到将 latitude/longitude 投影到球体 how map 2d grid points (x,y) onto sphere as 3d points (x,y,z).
的公式中另外,由于x
是水平位置,也就是说x
是经度。同样,y
是垂直位置,所以 y
是纬度。你把它们弄反了。
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)
)