在3D空间中绘制圆形线段

时间:2014-04-16 13:25:20

标签: vector 3d geometry

我正在尝试在3D中绘制圆形段(cs)。给定的数据是开始& cs的终点和原点。

我的想法是首先将圆圈转换为单位圆圈(忽略Z坐标)并计算起点和角度。 end.I现在可以生成一个带有下面循环的点列表,其中包含3D-Space中虚拟平面上圆弧段的数据。最后一步是围绕start和amp;之间的点旋转点。端。

问题是我的循环返回一个带有合理坐标和半径的圆弧段,但它在开始时切断了线条。结束。

我的代码:

Visual3D lines;
Vector3D start = new Vector3D(2, 2, 0); //2, 2, 0
Vector3D end = new Vector3D(4, 4, 2); //4, 4, 2
Vector3D up = new Vector3D(0, 1, 0);
Vector3D middle = pkm.ToVector3D(); //pkm.ToVector3D()
double r = Math.Sqrt(Math.Pow(start.X - middle.X, 2) + Math.Pow(start.Y - middle.Y, 2) + Math.Pow(start.Z - middle.Z, 2)); //Implement Check mechanism for possible points
List<Point3D> points = new List<Point3D>();

//calc
Vector3D idealStart = start - middle; 
Vector3D idealEnd = end - middle;
idealStart.Z = 0;
idealEnd.Z = 0;
idealStart.Normalize();
idealEnd.Normalize();

double delta = Math.Acos((Vector3D.DotProduct(up, idealStart)) / (up.Length * idealStart.Length));
double phi = Math.Acos((Vector3D.DotProduct(up, idealEnd)) / (up.Length * idealEnd.Length));

for (double i = phi; i <= delta; i += 0.01)
{
    points.Add(new Point3D(Math.Sin(i) * r + middle.X, Math.Cos(i) * r + middle.Y, middle.Z));
}



Vector3D half = (end - start) / 2;
middle = middle - start - half; //switch start with end
middle.Normalize();

lines = meschi.GetLinie(points, 2, Colors.Wheat); //Transforms the type of data
lines = meschi.ModelDrehenUmPunkt(lines, ((end + start) / 2).ToPoint3D(), middle, -Vector3D.AngleBetween(end - start, start)); // Final Rotation

我的结果示例: https://www.dropbox.com/s/xktbicrgtichsm1/circle_segment.JPG

有没有人知道代码为什么不绘制整圆段?

提前致谢!

0 个答案:

没有答案