Split a line into multiple equal parts

1.4k views Asked by At

I need to split a line into multiple equal parts (so each part can be individually colour coded). I have a couple of questions :

1) Has anyone come across c# code to do this already?

2) Am I right in assuming that I can use normal 'flat' trigonometry to work out where to split the line? I'm going to assume all the lines have an altitude of 0.

1

There are 1 answers

0
Matthew On

Am I right in assuming that I can use normal 'flat' trigonometry to work out where to split the line? I'm going to assume all the lines have an altitude of 0.

This depends on what you are trying to accomplish, and how accurate you need to be and how you plan to measure distance for the point of view of splitting the line?

In any event the steps would look like this:

  1. Iterate all points in the line and calculate the total distance (Total)
  2. divide total distance by the target number of segments for per segment distance Segment
  3. Iterate over the points in the line, until the previous point P_less has you less than Segment, and the next point P_more is greater than Segment (check the edge case of the current point falls right on the segment distance)
  4. create a new point on the line defined by points P_less and P_more which provides the exact target segment distance.
  5. Start again from the point created (or used) in step 4.