close

利用open3d繪製一個球體,該球體的點雲圖每一點的顏色為紅色

1. 經度: phi的角度範圍0~2*pi   點數100

ChatGPT: 經度是地理上用來衡量地球表面東西方方向位置的一個坐標軸。經度的範圍通常從-180度到+180度

2. 緯度: theta的角度範圍 0~pi  點數10

ChatGPT: 緯度是地球表面上用來測量位置的一組座標之一,它是指地球表面上某一點與赤道之間的角度。緯度的範圍通常從南緯90度(赤道)到北緯90度(北極)。

自訂義一個球體

import numpy as np
import open3d as o3d

# Generate spherical coordinates
phi = np.linspace(0, 2 * np.pi, num=100)
theta = np.linspace(0, np.pi, num=10)

# Create a meshgrid from the spherical coordinates
phi, theta = np.meshgrid(phi, theta)
print("phi.shape: " + str(phi.shape))
print("theta.shape: " + str(theta.shape))

# Convert spherical coordinates to Cartesian coordinates
x = np.sin(theta) * np.cos(phi)
y = np.sin(theta) * np.sin(phi)
z = np.cos(theta)

print("x.shape: " + str(x.shape))
print("y.shape: " + str(y.shape))
print("z.shape: " + str(z.shape))

x_f = x.flatten()
y_f = y.flatten()
z_f = z.flatten()

print("x_f.shape: " + str(x_f.shape))
print("y_f.shape: " + str(y_f.shape))
print("z_f.shape: " + str(z_f.shape))

# Reshape the coordinate arrays to create a list of 3D points
points = np.column_stack([x.flatten(), y.flatten(), z.flatten()])
color = np.array([65535, 0, 0])
colors = np.tile(color, (len(points), 1))

print("points.shape: " + str(points.shape))
print("colors.shape: " + str(colors.shape))

# Generate a PointCloud
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
pcd.colors = o3d.utility.Vector3dVector(colors/65535)
o3d.visualization.draw_geometries([pcd])

phi. Shape: (10, 100)
theta.shape: (10, 100)
x.shape: (10, 100)
y.shape: (10, 100)
z.shape: (10, 100)
x_f.shape: (1000,)
y_f.shape: (1000,)
z_f.shape: (1000,)
points.shape: (1000, 3)
colors. Shape: (1000, 3)

最後輸出點雲圖

# Output a point cloud data file
o3d.io.write_point_cloud("sphere.pcd", pcd)

 

 

 

 

arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()