How can one calculate the smoothness of a bezier curve?
-
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.
-
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 -
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... -
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 -
@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+bezierAh, yes. Forgotten about that one. Didn't get any where with that one.
-
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 }
-
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 ??
-
What criteria is used to determine smoothness is good enough?? RMS error or??
-
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 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. -
@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.
Advertisement