Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Polyline offset algorithm

Polyline offset algorithm

Scheduled Pinned Locked Moved Algorithms
algorithmstutorialquestion
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    beko
    wrote on last edited by
    #1

    Hello, i have set of 2D points and i want to offset with a given distance (like offset command in AutoCAD) i do not know how to deal with corners. i have searched on Internet, there are advanced methods like straight skeletons etc. but my polyline is not self crossing and no holes in it. Is there any simple method? any references? Best Regards. Bekir

    A L 2 Replies Last reply
    0
    • B beko

      Hello, i have set of 2D points and i want to offset with a given distance (like offset command in AutoCAD) i do not know how to deal with corners. i have searched on Internet, there are advanced methods like straight skeletons etc. but my polyline is not self crossing and no holes in it. Is there any simple method? any references? Best Regards. Bekir

      A Offline
      A Offline
      Alan Balkany
      wrote on last edited by
      #2

      Why can't you just iterate through the points and add your offset to each one? It seems like this should translate the corners along with everything else.

      B 1 Reply Last reply
      0
      • A Alan Balkany

        Why can't you just iterate through the points and add your offset to each one? It seems like this should translate the corners along with everything else.

        B Offline
        B Offline
        beko
        wrote on last edited by
        #3

        Just translating the edges with the offset distance will not work. I have found an algorithm not tested throughly, but it is working at least for my very simple 3 points polyline test :) http://objectmix.com/graphics/132987-draw-parallel-polyline-algorithm-needed.html[^] Best Regards. Bekir.

        CPalliniC 1 Reply Last reply
        0
        • B beko

          Just translating the edges with the offset distance will not work. I have found an algorithm not tested throughly, but it is working at least for my very simple 3 points polyline test :) http://objectmix.com/graphics/132987-draw-parallel-polyline-algorithm-needed.html[^] Best Regards. Bekir.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          beko wrote:

          Just translating the edges with the offset distance will not work.

          Why not?

          beko wrote:

          I have found an algorithm not tested throughly, but it is working at least for my very simple 3 points polyline test

          What kind of test you did? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          In testa che avete, signor di Ceprano?

          B 1 Reply Last reply
          0
          • CPalliniC CPallini

            beko wrote:

            Just translating the edges with the offset distance will not work.

            Why not?

            beko wrote:

            I have found an algorithm not tested throughly, but it is working at least for my very simple 3 points polyline test

            What kind of test you did? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            B Offline
            B Offline
            beko
            wrote on last edited by
            #5

            Hello, At the end, it is a translation however it must be implemented with respect to the normals, as far as i read through if it is a parametric curve then it is rather complicated. If you like to see how much it can further get complicated, you can have a look at the link below. http://timeguy.com/cradek-files/emc/liu2007_line_arc_offset.pdf[^] for the test, i have just created a polyline with three points and used the algorithm from Eduardo in my earlier reply, and compared it with AutoCAD output :) Best Regards.

            C 1 Reply Last reply
            0
            • B beko

              Hello, At the end, it is a translation however it must be implemented with respect to the normals, as far as i read through if it is a parametric curve then it is rather complicated. If you like to see how much it can further get complicated, you can have a look at the link below. http://timeguy.com/cradek-files/emc/liu2007_line_arc_offset.pdf[^] for the test, i have just created a polyline with three points and used the algorithm from Eduardo in my earlier reply, and compared it with AutoCAD output :) Best Regards.

              C Offline
              C Offline
              cp9876
              wrote on last edited by
              #6

              That paper seems to give a good description of how to do it. It's complicated, you will have lots of cases - you'll just have to get used to it.

              Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

              1 Reply Last reply
              0
              • B beko

                Hello, i have set of 2D points and i want to offset with a given distance (like offset command in AutoCAD) i do not know how to deal with corners. i have searched on Internet, there are advanced methods like straight skeletons etc. but my polyline is not self crossing and no holes in it. Is there any simple method? any references? Best Regards. Bekir

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                There is no simple solution to this problem, the best known general solution, is to create capsules between consecutive point pairs of your polyline where the capsule width is the offset, then union the capsule outlines. The capsule may be centered around the edge or it may be biased towards one side of the edge it is really up to the end requirement. For the union operation use something like Alan Murta's Generic Polygon Clipper library. If you know your polyline is enclosed and represents a convex polygon, then simply calculate the centroid, then offset each edge by the product of the desired offset amount and the vector composed of the mid-point of the edge at hand minus the centroid. A simple example can be found here: http://www.codeproject.com/KB/recipes/Wykobi.aspx

                B 1 Reply Last reply
                0
                • L Lost User

                  There is no simple solution to this problem, the best known general solution, is to create capsules between consecutive point pairs of your polyline where the capsule width is the offset, then union the capsule outlines. The capsule may be centered around the edge or it may be biased towards one side of the edge it is really up to the end requirement. For the union operation use something like Alan Murta's Generic Polygon Clipper library. If you know your polyline is enclosed and represents a convex polygon, then simply calculate the centroid, then offset each edge by the product of the desired offset amount and the vector composed of the mid-point of the edge at hand minus the centroid. A simple example can be found here: http://www.codeproject.com/KB/recipes/Wykobi.aspx

                  B Offline
                  B Offline
                  beko
                  wrote on last edited by
                  #8

                  Thank you for the all answers, I will have a look at it. Best Regards.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups