- #1

peterbone

- 13

- 0

I'm writing a program that uses a quadratic bezier curve and I want it to stay the same length as the curve bends - as the difference in angle between the first and second line segments changes. Here is a program that demonstrates what I'm trying to do:

http://www.geocities.com/peter_bone_uk/bezier.zip

Drag the red dots to bend the curve. Select/deselect the checkbox to see what the curve looks like with constant length and with the normal bezier curve.

To make it constant length I'm recalculating the control point of the bezier curve by offsetting it from it's normal position. The green dot in the program shows the repositioned control point. The direction of offset is directly between the 2 line segments joining the 2 end points 2 the control point. The offset amount is currently calculated using an iterative method by calculating the length of the curve (also an iterative method) and adjusting the offset of the control point until the length is within the desired error limits. This works fine but it's slow because of the iteration and I was wondering if it's possible to calculate the offset analytically.

I have an analytical approximation method that works well, but only if the 2 line segments are equal length. This equation is a polynomial approximation that I found using the polynomial curve fitting function in MATLAB. The equation is:

OffsetDistance = (-0.002993458 * A^4 + 0.00862333 * A^3 - 0.00551 * A^2 + 0.18482917 * A) * (L1+L2)

where

A is the difference in polar angle between the 2 line segments (ie if the curve is straight the angle difference is 0)

L1, L2 are the lengths of the line segments from the end points to the control point.

This equation only works if L1 = L2.

So anyway, this is a rather complex problem and I don't see much hope of finding an analytical solution but I thought I'd ask you anyway.

Any help would be greatly appreciated

Peter Bone

http://www.geocities.com/peter_bone_uk