我正试着画一条像在附件上那样与主线有偏移的线。
c# - 线偏移(平行线),无尖点-LMLPHP
我的代码有问题。它在直线上产生交点和尖点。(附件)
c# - 线偏移(平行线),无尖点-LMLPHP
也许有人可以帮我编写这段代码,提供我可以遵循的任何工作示例。

// LEFT SIDE OF MAIN LINE
     int numberOfLines = 10;
     float offset = 10f;
     lastLinePoints = outerPoints; // outerPoint = Points from Main Line
     for(int i = 0; i < numberOfLines; i++)
     {
         List<Vector3> tempPoints = new List<Vector3> ();
         for (int k = 0; k < lastLinePoints.Count; k++) {
             if (k + 1 < lastLinePoints.Count) {
                 Vector3 direction = lastLinePoints [k + 1] - lastLinePoints [k];
                 // up direction:
                 Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
                 // find right vector:
                 Vector3 right =  Vector3.Cross(direction.normalized, up.normalized);
                 Vector3 newPoint = lastLinePoints [k] + (right * offset);
                 tempPoints.Add (newPoint);
             }


         }
         VectorLine lineTemp = new VectorLine ("lineCurved", tempPoints, 120f / _camera2DObject.GetComponent<Camera> ().orthographicSize, LineType.Continuous);
         lineTemp.Draw3D ();
         lastLinePoints = tempPoints;

     }

经过一些研究,我知道画曲线平行线的解决方案是困难的。我也发现了一些算法(https://hal.inria.fr/inria-00518005/document),但是这个数学对我来说很难从中生成代码。
在@jstreet的建议下,我尝试了clipper库。结果是很好的,但是否有可能只画平行线,而不是封闭的多边形周围的线(如附件)
c# - 线偏移(平行线),无尖点-LMLPHP
更新
我写了另一个问题,因为我认为用剪贴画平行线是值得的。LINK TO question
c# - 线偏移(平行线),无尖点-LMLPHP

最佳答案

根据我以前的经验,在不应用多段线曲线偏移算法的情况下,将花费大量时间来解决您的问题,因此我的建议是开始实现任何算法,而不考虑数学上的困难。选择一个完全适合你情况的已发布算法,它可能比为任何形状实现算法更容易。
但你可以拍到下面的链接
https://github.com/skyrpex/clipper

07-24 09:44