動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)
背景
pySpherepts > Jupyter > 結果の座標を球面上に表示する実装 v0.1 > 余分な点が見える (奥側の点のようだ)
Matploblibにて球面上の点の表示をしていたが、上記のようにMatploblibでは隠面の点が隠されることなく描画される。
任意のelevationとazimuthに対して、隠面の点を非表示にする。
処理
- 点を実際に回転する
- 回転した点の座標でx > 0となるポイントだけを表示対象とする
- 回転していない点を表示リストに加える
回転については以下などの資料にある回転行列を用いる。
https://en.wikipedia.org/wiki/Rotation_matrix
code
plotSphNodes_171127.py v0.3
にて実装した。
主な処理は下記。
thetaの正負扱いやphiの正負扱いは実際の座標系を考慮した。
回転は先にazimuth方向で回転をしないと失敗することを確認した。
def extractFrontPoints(data, elevation, azimuth):
xx, yy, zz = np.hsplit(data, 3)
# 1. prepare the rotation matrix
theta = np.radians(elevation)
phi = np.radians(azimuth)
# 1-1. rotation for theta around the y axis
rottht = [
[np.cos(theta), 0.0, np.sin(theta)],
[0.0, 1.0, 0.0],
[-np.sin(theta), 0.0, np.cos(theta)],
]
# 1-2. rotation for phi around the z axis
rotphi = [
[np.cos(-phi), -np.sin(-phi), 0.0],
[np.sin(-phi), np.cos(-phi), 0.0],
[0.0, 0.0, 1.0],
]
# 2. Plots in the hidden side are removed
# since the code will display hidden plots
xs, ys, zs = [], [], []
for axo, ayo, azo in zip(xx, yy, zz):
# 2-1. rotatio in theta and phi
# **rotate in theta firstly will fail**
wrk = np.matmul(rotphi, [axo, ayo, azo])
axr, ayr, azr = np.matmul(rottht, wrk)
# 2-2. extract only front points
if (axr > 0):
xs += [axo]
ys += [ayo]
zs += [azo]
xx, yy, zz = xs, ys, zs
return xx, yy, zz
結果
elevation = 30.0, azimuth = 60.0
elevation = 70.0, azimuth = 45.0
備考
描画に失敗する組合せもあるのか裏側のみ表示される場合がある。
(elevation=30.0, azimuth=135.0)
優先度は低いので、作業はここで止めておく。