0

私のプロジェクトでは、緯度と経度で位置がわかっている点のデカルト座標を見つける必要があります。

これを例を挙げて説明しましょう。たとえば、緯度 30 度と経度 30 度で世界を表現し、世界の半径を R にすることにしました。ここで、緯度と経度のインデックスをパラメーターとして取り、この点の座標を返す関数を作成しようとしました。プロトタイプは次のようになります。

cartesianCoordinates(int latitudeIndex, int longitudeIndex,int radius );

それを可能にするために、私は次のコードを書きました:

int latNum=30,lonNum=30;
vectorzfloat> worldVertexDataVector;
void cartesianCoordinates(int paralelIndex,int meridianIndex,float radius )
{
    float x,y,z;
    float firstAngle,secondAngle;
    float rProj;
    firstAngle=PI/2-(PI/(latNum-1)*paralelIndex); // firstAngle is the latitude angle

    secondAngle=0+2*PI/(2*lonNum) *meridianIndex; // second angle is the longitude angle

    y=radius*sin(firstAngle);
    rProj=radius*cos(firstAngle);


    z=rProj*sin(secondAngle);
    x=rProj*cos(secondAngle);




    worldVertexDataVector.push_back(x);
    worldVertexDataVector.push_back(y);
    worldVertexDataVector.push_back(z);

}

今、worldVertexDataVector のポイントを使用して、球をレンダリングしようとしましたが、失敗しました。すべてのコード (これ以外) を検索した後、これらの座標の計算中に間違いを犯したと思われます。私のエラーを検出するのを手伝ってくれる人はいますか?

4

0 に答える 0