C# 3d线最简单情况的线缓冲

 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 };
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值