簡単な PyX グラフを使用していくつかのパスを生成してみましょう。

パスは、解析モードで読み取った SVG ファイルから取得することもできます。
PyX パスを取得したら、PyX 機能を使用してパスに関する詳細情報を取得できます。次の単純なバージョンでは、各パスに沿っていくつかのポイントを計算し、それらの距離を合計します。(PostScript ポイントで機能する で終わるメソッド名を使用して実行し_pt
ます。PyX ユニットを使用するよりも少し高速です。また、最初にすべてのパスを明示的にノルムパスに変換しました。これは必須ではありませんが、一部の関数呼び出しを減らすのに役立ちます初めの。)
完全なコードは次のとおりです (サンプル パスを生成するためのグラフを含む)。
import math
from pyx import *
# create some data (and draw it)
g = graph.graphxy(width=10, x=graph.axis.lin(min=0, max=2*math.pi))
qpi = g.plot(graph.data.function("y(x)=sin(x)"))
opi1 = g.plot(graph.data.function("y(x)=sin(x)+0.1*sin(10*x)"))
opi2 = g.plot(graph.data.function("y(x)=sin(x)+0.2*sin(20*x)", points=1000))
g.writePDFfile()
# get the corresponding PyX paths
qpath = qpi.path.normpath()
opath1 = opi1.path.normpath()
opath2 = opi2.path.normpath()
# now analyse it
POINTS = 10
qpath_arclen_pt = qpath.arclen_pt()
qpath_points_pt = qpath.at_pt([qpath_arclen_pt*i/(POINTS-1) for i in range(POINTS)])
for opath in [opath1, opath2]:
opath_arclen_pt = opath.arclen_pt()
opath_points_pt = opath.at_pt([opath_arclen_pt*i/(POINTS-1) for i in range(POINTS)])
print(sum(math.sqrt((qpoint_x_pt-opoint_x_pt)**2 + (qpoint_y_pt-opoint_y_pt)**2)
for (qpoint_x_pt, qpoint_y_pt), (opoint_x_pt, opoint_y_pt) in zip(qpath_points_pt, opath_points_pt)))
プログラムは次のように出力します。
25.381154890630064
56.44386644062556
これは、破線が点線よりも実線に近いことを示しています。
また、接線、曲率、アークレン自体などを比較することもできます...必要に応じて多くのオプションがあります。