29

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

代替テキスト

水平方向と横方向のスライスの数を構成可能にする必要があります

4

5 に答える 5

43

緯度(水平)が 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で調整する必要があります

于 2010-11-02T20:55:21.690 に答える
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. 

}
于 2010-11-02T20:58:46.277 に答える
1

推測ですが、おそらく (0,0,0) を中心とする球の式を使用できます。

x²+y²+z²=1

これを x について解いてから、y と z の一連の値をループして、計算した x でそれらをプロットします。

于 2010-11-02T20:47:00.503 に答える
-1

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"
)

ここに画像の説明を入力

于 2019-10-16T16:03:35.510 に答える