I got this curve by contourc.
Assuming the points in your curve are reasonably close together, you can
approximate the arc length in terms of chord lengths between successive
points, and then use quadratic approximation over point triplets for the
derivatives of x and y with respect to the arc length at the middle points.
Let P1 = (x1,y1), P2 = (x2,y2), and P3 = (x3,y3) be any three successive
points in your curve. Then
s12 = sqrt((x2-x1)^2+(y2-y1)^2) and
s23 = sqrt((x3-x2)^2+(y3-y2)^2)
are two successive chord lengths. If you define quadratics in arc length, s by
x = ax*s^2+bx*s+cx
y = ay*s^2+by*s+cy
which run through the three points, it can be shown that the derivatives dx/
ds and dy/ds at the middle point, P2, will be given by
dxds = (s2^2*(x2-x1)+s1^2*(x3-x2))/(s1*s2*(s1+s2))
dyds = (s2^2*(y2-y1)+s1^2*(y3-y2))/(s1*s2*(s1+s2))
These should be good approximations for the components of a vector
tangent at the middle point. Hence the normal there will have a slope of
approximately
-dxds/dyds
Doing this for every triplet along the curve will give you the normal direction
at each middle point.
Does this give you enough to work through the problem?
Roger Stafford
With s denoting the (approximate) arc length along the curve, we can call s1, s2, and s3 the (ascending) values of s at the points P1, P2, and P3. We would then have s12 = s2-s1 and s23 = s3-s2.
To express x as a quadratic function of s which assumes the values x1, x2, and x3 at the arc length values s1, s2, and s3, we can use the Lagrange interpolation formula
x = x1*(s-s2)*(s-s3)/(s1-s2)/(s1-s3) + ...
x2*(s-s1)*(s-s3)/(s2-s1)/(s2-s3) + ...
x3*(s-s1)*(s-s2)/(s3-s1)/(s3-s2)
If we take the derivative of this x with respect to s and set s equal to s2 to get the derivative at the middle point P2, we get (after a little manipulation):
dx/ds (at s equal to s2) =
-x1*(s3-s2)/(s2-s1)/(s3-s1) ...
-x2*(2*s2-s1-s3)/(s2-s1/(s3-s2) ...
+x3*(s2-s1)/(s3-s1)/(s3-s2)
= ((x2-x1)*(s3-s2)^2+(x3-x2)*(s2-s1)^2) / ...
((s2-s1)*(s3-s2)*(s3-s1))
= ((x2-x1)*s23^2+(x3-x2)*s12^2) / ...
(s12*s23*(s12+s23))
This last is the expression I derived earlier (with s12 and s23 replacing the former confusing s1 and s2.)
The derivation of dy/ds with y1, y2, and y3 replacing x1, x2, and x3 is done the same way.
Roger Stafford