簡體   English   中英

在C ++中繪制圓

[英]drawing circle in c++

下面的代碼在x和z坐標平面中為我繪制了一個3d球體對象的圓。

 double radiusCircle =0.5;
 double i;
 double j;

 for(i = 0.0f;i<6.0f;i+=0.2f){
     sphere1 = new Sphere;
     sphere1->position.x = radiusCircle *cos(i * (2.0 * 3.14) /6)+4;
     sphere1->position.z = radiusCircle *sin(i * (2.0 * 3.14) / 6 )+2;
 }

我也試圖將它們堆疊在y軸上,但無法正確處理。 我想知道是否有人可以幫助我做到這一點。

基本上,我想上面的代碼畫一個圓的30 sphere1 ,但我也想把它高4。

 double radiusCircle =0.5;
 double i;
 double j;


for (y = 0; y < 4; y++) {
     for(i = 0.0f;i<6.0f;i+=0.2f){
         sphere1 = new Sphere;
         sphere1->position.x = radiusCircle *cos(i * (2.0 * 3.14) /6)+4;
         sphere1->position.z = radiusCircle *sin(i * (2.0 * 3.14) / 6 )+2;
         sphere1->position.y = sphere1.radius * 2 * y; // <-- assign position.y to the sphere height
     }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM