从笛卡尔转换 3d 对象并将其绘制在地理投影上

问题描述 投票:0回答:0

我正在尝试使用 Plotly 在特定纬度(度)、经度(度)和高度(米)的 3d 地理平面上绘制 3d 气球。气球是在笛卡尔坐标系中使用

get_balloon
函数生成的。 我目前正在努力将这些笛卡尔坐标转换为地理坐标,但它变形了。

import numpy as np
import plotly.graph_objects as go

def get_balloon(radius):
    upper_radius = 0.8 * radius
    lower_radius = 0.05 * radius
    mid_height = 0.6 * radius
    major_axis = 1.5 * radius

    # Create the theta and phi values for the spherical coordinate system
    theta = np.linspace(0, 2 * np.pi, 200)
    phi = np.linspace(0, np.pi, 100)

    # Create a meshgrid from theta and phi
    theta, phi = np.meshgrid(theta, phi)

    # Convert the spherical coordinates to Cartesian coordinates
    upper_x = upper_radius * np.sin(phi) * np.cos(theta)
    upper_y = upper_radius * np.sin(phi) * np.sin(theta)
    upper_z = major_axis + mid_height + upper_radius * np.cos(phi)

    lower_x = lower_radius * np.sin(phi) * np.cos(theta)
    lower_y = lower_radius * np.sin(phi) * np.sin(theta)
    lower_z = major_axis - mid_height + (major_axis/4) * np.cos(phi)

    # Combine the coordinates for the upper and lower parts of the balloon
    x = np.concatenate((upper_x, lower_x))
    y = np.concatenate((upper_y, lower_y))
    z = np.concatenate((upper_z, lower_z))

    return x,y,z


def plot_balloon(radius):
    x,y,z = get_balloon(radius)
    fig = go.Figure(data=go.Surface(x=x, y=y, z=z, colorscale='Reds', showscale=False))
    fig.show()

# Call the function with the radius of the balloon
plot_balloon(radius=1)

我是这样改造的(不知道对不对)

def plot_balloon_at_geolocation(lat, lon, altitude, radius):
    # Earth's effective radius (in meters)
    earth_radius = 6371e3  # average radius

    # Generate balloon
    x, y, z = get_balloon(radius)

    # Adjust the x, y, z coordinates of the balloon to place it at the desired geolocation
    x = x / earth_radius + lon  # divide by earth_radius to convert to degrees
    y = y / earth_radius + lat  # divide by earth_radius to convert to degrees
    z = z + altitude  # altitude is already in meters
    
    # Plot the balloon
    fig = go.Figure(data=go.Surface(x=x, y=y, z=z, colorscale='Reds', showscale=False))
    fig.update_layout(title="3D Balloon at Latitude {}, Longitude {}".format(lat, lon))
    fig.show()

# Call the function
plot_balloon_at_geolocation(lat=32, lon=-88, altitude=60, radius=1)

python math geolocation plotly-python geo
© www.soinside.com 2019 - 2024. All rights reserved.