注釈
完全なサンプルコードをダウンロードしたり、Binderを使ってブラウザでこのサンプルを実行するには、 最後に進んでください 。
表面の法線を計算します#
表面上の法線を計算します.
これで地球のサーフェスデータセットがロードされました.残念ながら,データセットには地形起伏を隠す均一な半径の地球が表示されます. pyvista.PolyData.compute_normals()
を使用して,データセット内のすべてのポイントで地球上の法線ベクトルを計算し,データセットで指定された値を使用してサーフェスを法線方向にワープし,誇張された地形レリーフを作成します.
# Compute the normals in-place and use them to warp the globe
mesh.compute_normals(inplace=True) # this activates the normals as well
次に,これらの法線を使用して,サーフェスをワープさせます.
warp = mesh.warp_by_scalar(factor=0.5e-5)
そして,見てみよう!
warp.plot(cmap="gist_earth", show_scalar_bar=False)
面またはセル法線を使用して,一般的な方向を向いているメッシュのすべての面を抽出することもできます.次のスニペットでは,メッシュを取得し,そのセル面に沿って法線を計算し,上向きの面を抽出します.
mesh = examples.download_nefertiti()
# Compute normals
mesh.compute_normals(cell_normals=True, point_normals=False, inplace=True)
# Get list of cell IDs that meet condition
ids = np.arange(mesh.n_cells)[mesh["Normals"][:, 2] > 0.0]
# Extract those cells
top = mesh.extract_cells(ids)
cpos = [
(-834.3184529757553, -918.4677714398535, 236.5468795300025),
(11.03829376004883, -13.642289291587957, -35.91218884207208),
(0.19212361465657216, 0.11401076390090074, 0.9747256344254143),
]
top.plot(cpos=cpos, color=True)
Total running time of the script: (0 minutes 40.802 seconds)