Вопрос

Here is example image of what I want to do: enter image description here
I want to calculate Path 1 from Path 2.

Screenshot made from Inkscape, where I'm, at first, create Path 1, then add p3 to the original path. This is didn't change the original path at all, because new point actually unneeded. So, how can I detect this point(p3) using Path 2 SVG path representation and calculate Path 1 from Path 2?

Basically, I search for the math formulas, which can help me to convert(also checking that whether it is possible):
C 200,300 300,250 400,250 C 500,250 600,300 600,400
to
C 200,200 600,200 600,400

Это было полезно?

Решение

You're solving a constraint problem. Taking your first compound curve, and using four explicit coordinates for each subcurve, we have:

points1 = point[8];
points2 = point[4];

with the following correspondences:

points1[0] == points2[0];
points1[7] == points2[3];

direction(points1[0],points1[1]) == direction(points2[0], points2[1]);
direction(points1[6],points1[7]) == direction(points2[2], points2[3]);

we also have a constraint on the relative placement for points2[1] and points2[2] due to the tangent of the center point in your compound curve:

direction(points1[2],points[4]) == direction(points2[1],points2[2]);

and lastly, we have a general constraint on where on- and off-curve points can be for cubic curves if we want the curve to pass through a point, which is described over at http://pomax.github.io/bezierinfo/#moulding

Taking the "abc" ratio from that section, we can check whether your compound curve parameters fit a cubic curve: if we construct a new cubic curve with points

A = points1[0];
B = points1[3];
C = points1[7];

with B at t=0.5 (in this case), then we can verify whether the resulting curve fits the constraints that must hold for this to be a legal simplification.

The main problem here is that we, in general, don't know whether the "in between start and end" point should fall on t=0.5, or whether it's a different t value. The easiest solution is to see how far that point is along the total curve (using arc length: distance = arclength(c1) / arclength(c1)+arclength(c2) will tell us) and use that as initial guess for t, iterating outward on either side for a few values.

The second option is to solve a generic cubic equation for the tangent vector at your "in between" point. We form a cubic curve with points

points3 = [ points1[0], points1[1], points1[6], points1[7] ];

and then solve its derivative equations to find one or more t values that have the same tangent direction (but not magnitude!) as our in-between point. Once we have those (and we might have more than 2), we evaluate whether we can create a curve through our three points of interest with the middle point set to each of those found t values. Either one or zero of the found t values will yield a legal curve. If we have one: perfect, we found a simplification. If we find none, then the compound curve cannot be simplified into a single cubic curve.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top