visual drawing circle in c++

visual drawing circle in c++

本文关键字:c++ in circle drawing visual      更新时间:2023-10-16

下面的代码在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
     }
}