Scipy > API > Delaunay試してみた > QhullオプションがMATLABとは異なる


動作環境
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)

関連

MATLAB > API > Delaunay | Voronoi 試してみた
geometry > Voronoi を試してみた (2D, 3D)

Scipy

scipy.spatial.Delaunay

入力データ

delaunay_input_171118.txt
   0.0000000e+00   8.5065081e-01   5.2573111e-01
   0.0000000e+00  -8.5065081e-01   5.2573111e-01
   0.0000000e+00   8.5065081e-01  -5.2573111e-01
   0.0000000e+00  -8.5065081e-01  -5.2573111e-01
   5.2573111e-01   0.0000000e+00   8.5065081e-01
  -5.2573111e-01   0.0000000e+00   8.5065081e-01
   5.2573111e-01   0.0000000e+00  -8.5065081e-01
  -5.2573111e-01   0.0000000e+00  -8.5065081e-01
   8.5065081e-01   5.2573111e-01   0.0000000e+00
  -8.5065081e-01   5.2573111e-01   0.0000000e+00
   8.5065081e-01  -5.2573111e-01   0.0000000e+00
  -8.5065081e-01  -5.2573111e-01   0.0000000e+00

code v0.1

test_scipy_delaunay_171118.py
import numpy as np
from scipy.spatial import Delaunay

IN_FILE = 'delaunay_input_171118.txt'
xyz = np.genfromtxt(IN_FILE, delimiter='  ')
print("---xyz---")
print(xyz)

print("---dln---")
dln = Delaunay(xyz)
print(dln.simplices)
run
$ python3 test_scipy_delaunay_171118.py 
---xyz---
[[ 0.          0.85065081  0.52573111]
 [ 0.         -0.85065081  0.52573111]
 [ 0.          0.85065081 -0.52573111]
 [ 0.         -0.85065081 -0.52573111]
 [ 0.52573111  0.          0.85065081]
 [-0.52573111  0.          0.85065081]
 [ 0.52573111  0.         -0.85065081]
 [-0.52573111  0.         -0.85065081]
 [ 0.85065081  0.52573111  0.        ]
 [-0.85065081  0.52573111  0.        ]
 [ 0.85065081 -0.52573111  0.        ]
 [-0.85065081 -0.52573111  0.        ]]
---dln---
[[ 7 11  5  1]
 [ 7 10  3  1]
 [ 7  0  5  4]
 [ 7  2  6  8]
 [ 7 10  4  1]
 [ 7  5  4  1]
 [ 7  0  5  9]
 [ 7 11  3  1]
 [ 7 10  3  6]
 [ 7 11  5  9]
 [ 7  0  2  8]
 [ 7 10  4  8]
 [ 7 10  6  8]
 [ 7  0  2  9]
 [ 7  0  4  8]]

期待していた出力

上記の結果は下記と異なる。データセットの数が上記は15,下記は20個。上記では左端に7が出て、下記では左端の値が様々。

tri_bef_171118.txt
   3.0000000e+00   2.0000000e+00   7.0000000e+00   1.0000000e+00
   2.0000000e+00   3.0000000e+00   6.0000000e+00   1.0000000e+00
   4.0000000e+00   3.0000000e+00   6.0000000e+00   2.0000000e+00
   3.0000000e+00   1.0000000e+01   6.0000000e+00   1.0000000e+00
   1.1000000e+01   7.0000000e+00   2.0000000e+00   5.0000000e+00
   7.0000000e+00   2.0000000e+00   5.0000000e+00   1.0000000e+00
   8.0000000e+00   1.2000000e+01   6.0000000e+00   1.0000000e+01
   4.0000000e+00   1.2000000e+01   6.0000000e+00   8.0000000e+00
   4.0000000e+00   8.0000000e+00   6.0000000e+00   3.0000000e+00
   8.0000000e+00   1.0000000e+01   6.0000000e+00   3.0000000e+00
   5.0000000e+00   2.0000000e+00   6.0000000e+00   1.0000000e+00
   3.0000000e+00   1.1000000e+01   9.0000000e+00   1.0000000e+00
   3.0000000e+00   7.0000000e+00   1.1000000e+01   1.0000000e+00
   7.0000000e+00   5.0000000e+00   1.1000000e+01   1.0000000e+00
   1.1000000e+01   5.0000000e+00   9.0000000e+00   1.0000000e+00
   6.0000000e+00   1.2000000e+01   4.0000000e+00   2.0000000e+00
   3.0000000e+00   4.0000000e+00   7.0000000e+00   2.0000000e+00
   8.0000000e+00   4.0000000e+00   7.0000000e+00   3.0000000e+00
   1.1000000e+01   4.0000000e+00   2.0000000e+00   7.0000000e+00
   3.0000000e+00   7.0000000e+00   9.0000000e+00   1.1000000e+01

それぞれの定義の理解が必要だ。

code v0.2

https://stackoverflow.com/questions/36604172/difference-between-matlab-delaunayn-and-scipy-delaunay
Qhullのオプションの違いなのかもしれない。

test_scipy_delaunay_171118.py
import numpy as np
from scipy.spatial import Delaunay

IN_FILE = 'delaunay_input_171118.txt'
xyz = np.genfromtxt(IN_FILE, delimiter='  ')
print("---xyz---")
print(xyz)

print("---dln---")
dln = Delaunay(xyz, qhull_options="Qt Qbb Qc")
print(dln.simplices)
print("---coplanar---")
print(dln.coplanar)

Qzを付けないとエラーになる。

$ python3 test_scipy_delaunay_171118.py 
(前略)
---dln---
Traceback (most recent call last):
  File "test_scipy_delaunay_171118.py", line 10, in <module>
    dln = Delaunay(xyz, qhull_options="Qt Qbb Qc")
  File "scipy/spatial/qhull.pyx", line 1882, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:18174)
  File "scipy/spatial/qhull.pyx", line 434, in scipy.spatial.qhull._Qhull.__init__ (scipy/spatial/qhull.c:5799)
scipy.spatial.qhull.QhullError: QH6019 qhull input error: can not scale last coordinate.  Input is cocircular
   or cospherical.   Use option 'Qz' to add a point at infinity.

While executing:  | qhull d Qbb Qc Qt
Options selected for Qhull 2015.2.r 2016/01/18:
  run-id 950178010  delaunay  Qbbound-last  Qcoplanar-keep  Qtriangulate
  _pre-merge  _zero-centrum  Qinterior-keep  Pgood

Scipy > Delaunay > cocircular > 定義 | cospherical