110,535
社区成员
发帖
与我相关
我的任务
分享
private void DrawSphere_Cylinder(int xyCount, int zCount, double r)
{
//计算夹角(都是弧度制)
double theta = 2 * Math.PI / xyCount;
for (int i = 0; i < zCount; i++)
{
for (int j = 0; j < xyCount; j++)
{
//坐标
//以z轴为圆柱的中心,底座在xy平面上
double x = Math.Cos(j * theta) * r;
double y = Math.Sin(j * theta) * r;
double z = i * 0.25;//每层间距
vtkSphereSource sphereSource = vtkSphereSource.New();
sphereSource.SetRadius(0.05);
sphereSource.SetCenter(x, y, z);
sphereSource.SetPhiResolution(8);
sphereSource.SetThetaResolution(16);
vtkShrinkPolyData sphereShrink = vtkShrinkPolyData.New();
sphereShrink.SetInputConnection(sphereSource.GetOutputPort());
sphereShrink.SetShrinkFactor(0.5);
vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();
sphereMapper.SetInputConnection(sphereSource.GetOutputPort());
vtkProperty shpreProperty = vtkProperty.New();
shpreProperty.SetOpacity(1.0);//不透明度
shpreProperty.SetColor(1, 1, 0.5);
shpreProperty.SetLighting(true);
vtkActor sphereActor = vtkActor.New();
sphereActor.SetMapper(sphereMapper);
sphereActor.SetProperty(shpreProperty);
renderer.AddActor(sphereActor);
}
}
}
class circleBase
{
createCircle();
copyCircle();
//.........................
}
循环体外,create一个球theCircle,填充下
for (int i = 0; i < zCount; i++)
{
for (int j = 0; j < xyCount; j++)
{
//坐标
//以z轴为圆柱的中心,底座在xy平面上
double x = Math.Cos(j * theta) * r;
double y = Math.Sin(j * theta) * r;
double z = i * 0.25;//每层间距
theCircle.copyCircle();
只调整位置就可以了