• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How can one calculate the smoothness of a bezier curve?

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 5 Posters 602 Views
Loading More Posts
  • 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.
  • T Offline
    thomthom
    last edited by 24 Jul 2011, 12:49

    Given a bezier curve, how can one calculate how many segments the curve needs in order to ensure a given smoothness (ideally defined by angle)

    I curious in case of optimizing a bezier curve to use as few segments as possible while visually keeping it smooth. For instance, a nearly straight curve only need 3-4 segments, while a curling loop needs lots more.

    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund

    1 Reply Last reply Reply Quote 0
    • P Offline
      Pixero
      last edited by 24 Jul 2011, 13:32

      Not sure if this is what you want:
      http://devmag.org.za/2011/06/23/bzier-path-algorithms/
      http://www.efg2.com/Lab/Graphics/Jean-YvesQueinecBezierCurves.htm

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 24 Jul 2011, 14:24

        Interesting. Followed some links and found this: http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/
        Had one algorithm, but apparently there are instances where it fails...

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 25 Jul 2011, 11:09

          Wouldn't it depend upon the camera distance to the target?

          EDIT: I also seem to recall an earlier thread on this subject.
          Search: keywords=segments+bezier

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 25 Jul 2011, 12:08

            @dan rathbun said:

            Wouldn't it depend upon the camera distance to the target?

            The smoothness will of course appear more or less depending on the camera. But that is of no concern. Just want to add more segments when the curve bends more.

            @dan rathbun said:

            EDIT: I also seem to recall an earlier thread on this subject.
            Search: keywords=segments+bezier

            Ah, yes. Forgotten about that one. Didn't get any where with that one.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 25 Jul 2011, 12:31

              Can't you simply check each of the curve.vertices [except the first and last ones] taking the two vectors from it to its immediate neighbors, which give you an angle and then it it's too small you add a vertex to divide that edge and relocate the vertices to soften?

              angle=120.degrees ### or whatever
              curve.vertices[1..-2].each_with_index{|v,i|
                if v.position.vector_to(v[i-1].position).vector_between(v.position.vector_to(v[i+1].position)).radians < angle
                  ### do stuff to split the first edge at 'v' and 
                  ### relocate 'v' and the new-vertex so angle is 'softened'...
                end
              }
              

              TIG

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 25 Jul 2011, 12:56


                Curve.move_vertices( 3dpt_array )


                Seems like we could use a new API instance method that used Edge.split for each segment of a curve, and then adjusted the new larger Curve.vertices array, using Curve.move_vertices, the question would be what would we what it's name to be?
                Curve#smooth ?? Curve#smoothen ??

                .. and what would it's arguments be?

                Fredo ??

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  mac1
                  last edited by 25 Jul 2011, 13:41

                  What criteria is used to determine smoothness is good enough?? RMS error or??

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Dan Rathbun
                    last edited by 25 Jul 2011, 15:17


                    The Sketchup UI limits the creation of Curves to segments of 2 .. 999.


                    If this limitation extends into the API, then an extention might be written thus:

                    class Sketchup;;Curve
                    
                      # instance methods will be inherited by Sketchup;;ArcCurve
                    
                      # coarseness
                      #
                      # returns Float in range 0.003 .. 1.000
                      #         for segments of 999 downto 2
                      #
                      def coarseness
                        (1000 -(self.count_edges - 2)).to_f/1000
                      end #def
                    
                      # smoothness
                      #
                      # returns Float in range 0.003 .. 1.000
                      #         for segments of 2 upto 999
                      #
                      def smoothness
                        (self.count_edges + 1).to_f/1000
                      end #def
                    
                    end #class
                    

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 25 Jul 2011, 16:46

                      I'm not talking about SketchUp entities. But a mathematically calculated Bezier curve - which later will be used to create geometry.
                      I want to be able to generate geometry with minimum segments whilst still retaining a good overall shape.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 25 Jul 2011, 16:54

                        @mac1 said:

                        What criteria is used to determine smoothness is good enough?? RMS error or??

                        I was thinking that, from a user's point of view, one set a max angle. That the segments connecting each other would not exceed this max angle.
                        Though, I am open to other definitions.

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        1 / 1
                        • First post
                          8/11
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement