public static List<double[]> GenerateLineBuffer(List<double[]> line, double bufferLen)
{
double[][] lineBuffer = new double[line.Count * 2 + 1][];
for (int i = 0; i < line.Count; i++)
{
var p1 = new double[3];
var p2 = new double[3];
if (i == line.Count - 1)
{
p1 = line[i];
p2 = line[i - 1];
}
else
{
p1 = line[i];
p2 = line[i + 1];
}
var normalP = new double[3] { p1[0] - p2[0], p1[1] - p2[1], 0 };
var normalPN = Vector3.Normalize(new Vector3((float)normalP[0], (float)normalP[1], (float)normalP[2]));
var normalZ = new Vector3(0, 0, 1);
var directionV = Vector3.Cross(normalPN, normalZ);
//正反向
var direction = new double[3] { directionV.X, directionV.Y, directionV.Z };
var bufferP = DataConvertVtkUtils.movePoint(p1, direction, bufferLen);
//反方向
var dirctionF = new double[3] { -directionV.X, -directionV.Y, -directionV.Z };
var bufferPF = DataConvertVtkUtils.movePoint(p1, dirctionF, bufferLen);
if (i == line.Count - 1)
{
lineBuffer[i] = bufferPF;
lineBuffer[line.Count * 2 - 1 - i] = bufferP;
}
else
{
lineBuffer[i] = bufferP;
lineBuffer[line.Count * 2 - 1 - i] = bufferPF;
}
}
//闭合
lineBuffer[line.Count * 2] = lineBuffer[0];
return lineBuffer.ToList();
}
public static double[] movePoint(double[] inPoint, double[] normal, double distance)
{
Vector3 p3dV3 = new Vector3((float)inPoint[0], (float)inPoint[1], (float)inPoint[2]);
Vector3 normalV3 = new Vector3((float)normal[0], (float)normal[1], (float)normal[2]);
normalV3 = Vector3.Normalize(normalV3);
var resultP = p3dV3 + normalV3 * (float)distance;
return new double[] { resultP.X, resultP.Y, resultP.Z };
}
C# 3d线最简单情况的线缓冲
最新推荐文章于 2024-10-17 21:38:45 发布