次のような球メッシュの 3D 座標を生成するアルゴリズム (疑似コード) を探しています。

水平方向と横方向のスライスの数を構成可能にする必要があります
緯度(水平)が M 行、経度(垂直)が N 行ある場合、
(x, y, z) = (sin(Pi * m/M) cos(2Pi * n/N), sin(Pi * m/M) sin(2Pi * n/N), cos(Pi * m/M) )))
{ 0, ..., M } の各 m と { 0, ..., N-1 } の n に対して、それに応じてドット間に線分を描画します。
編集:極で「緯度線」を数えるかどうかを決定する必要があるため、必要に応じてMを1または2で調整する必要があります
これは、テストせずに頭のてっぺんから外れています。良い出発点になるかもしれません。
これにより、double を使用する場合に、最も精度の高い、最も正確でカスタマイズ可能な結果が得られます。
public void generateSphere(3DPoint center, 3DPoint northPoint
, int longNum, int latNum){
// Find radius using simple length equation
(distance between center and northPoint)
// Find southPoint using radius.
// Cut the line segment from northPoint to southPoint
into the latitudinal number
// These will be the number of horizontal slices (ie. equator)
// Then divide 360 degrees by the longitudinal number
to find the number of vertical slices.
// Use trigonometry to determine the angle and then the
circumference point for each circle starting from the top.
// Stores these points in however format you want
and return the data structure.
}
推測ですが、おそらく (0,0,0) を中心とする球の式を使用できます。
x²+y²+z²=1
これを x について解いてから、y と z の一連の値をループして、計算した x でそれらをプロットします。
FWIW、meshzoo (私のプロジェクト) を使用して、球体のメッシュを非常に簡単に生成できます。
オプションで、さらに最適化するためにoptimesh (私の隠し場所から別のもの) を使用できます。
import meshzoo
import optimesh
points, cells = meshzoo.icosa_sphere(10)
class Sphere:
def f(self, x):
return (x[0] ** 2 + x[1] ** 2 + x[2] ** 2) - 1.0
def grad(self, x):
return 2 * x
points, cells = optimesh.cvt.quasi_newton_uniform_full(
points, cells, 1.0e-2, 100, verbose=False,
implicit_surface=Sphere(),
# step_filename_format="out{:03d}.vtk"
)