Line offset (parallel lines) without return points

I am trying to draw lines with an offset to the main line, for example, when nesting. enter image description here

I have problems with my code. It creates intersections and return points on lines. (Application)

enter image description here

Perhaps someone can help me with this code to provide any working example that I can execute.

// 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; } 

After some research, I know that the solution for drawing curved parallel lines can be difficult. I also found some algorithms ( https://hal.inria.fr/inria-00518005/document ), but for this math it is difficult for me to make the code.

After a suggestion from @jstreet, I tried the CLIPPER library. The results are very good, but is it possible to use only a parallel line instead of a closed polygon around the line (for example, on an attachment) enter image description here

UPDATE

I wrote another question because I think using CLIPPER for parallel lines is worth it. LINK To the question

enter image description here

+5
source share
2 answers

From my previous experience, a lot of time will be spent on solving your problem without applying the polyline curve offset algorithm, so my advice is to start implementing any algorithms regardless of mathematical difficulties. choose one of the published algorithms that suits exactly your case, it may be easier than implementing an algorithm for any form. But you can get the link below https://github.com/skyrpex/clipper

0
source
0
source

Source: https://habr.com/ru/post/1246256/


All Articles