3

I'd like to subdivide a curve into segments with equal chord heights. I know I can divide into equal chord lengths with the Divide Distance tool, but I can't find a height option. I've written some really dirty code that does it here. (Don't judge me, it's inelegant and inefficient, but it does the job.)

Curve divided by chord height

What I'd really like to hear is that there's no point in going on to make something like a binary search because there's already a feature in Grasshopper that does it, but failing that, does anyone have any suggestions on how to do it in a more efficient way?

David Rutten
  • 4,716
  • 6
  • 43
  • 72
Ben
  • 12,614
  • 4
  • 37
  • 69
  • How many segments? And what are you going to do with cusps? – MBo Apr 11 '13 at 12:31
  • The number of segments is a result of how curvy the curve is. Cusps is a good question, I'd imagine that a proper mathematical solution would freak out and go to infinity at that point, but some kind of iterative solution would just be a little bit unstable around there and treat it as normal bit of curve. I think it'd be safe to say that there would be no cusps for the moment. – Ben Apr 11 '13 at 23:56

1 Answers1

3

My answer concerns to finding bezier curve chord height (sagitta?), not to subdividing process.

I consider cubic bezier with control points P0, P1, P2, P3. Sagitta is maximum distance from the chord segment C=P0P3. Max distance is reached when direction vector of the curve (hodograph, 1st derivative) is parallel to the chord vector. Hodograph of cubic bezier curve is quadratic bezier curve with control points (Sederberg book CAGD, section 2.7):

D0=3(P1-P0), D1=3(P2-P1), D2=3(P3-P2)

Vectors are parallel when their cross product is zero, so we have equation

Cx*Dy-CyDx=0   or 
(P3x-P0x)*((P1y-P0y)*(1-t)^2+2*(P2y-P1y)*t*(1-t)+(P3y-P2y)*t^2) = 
(P3y-P0y)*((P1x-P0x)*(1-t)^2+2*(P2x-P1x)*t*(1-t)+(P3x-P2x)*t^2)

This is quadratic equation, it may have 0, 1 or 2 solutions for t in range [0..1] (case 2 is possible for S-shaped curve). Then we can evaluate bezier curve at the t parameter found from equation, and calculate distance to the chord.

MBo
  • 77,366
  • 5
  • 53
  • 86