Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simplifying a path
#13
(05-19-2021, 07:46 AM)Ottia Tuota Wrote: (I am not quite sure if I understand your comments quite right.)

No I have not thought about P(t)=K. But I may some day. And yes there is that fact that the stroke consists of several small arcs, and we cannot tell even on which arc the most distant point K is.

I have the feeling that when searching for an approximate Bezier arc it is important to choose K somewhere close to the middle of the stroke, and I think that the most distant point works well. Also, the splitting is good to do at the same point so that the stroke will never be split anywhere close to either end point but somewhere in the middle. That is why the point K is computed rather carefully.

Finding K is not done by running along the stroke. It is (usually) done by solving the points where the tangent is parallel to the chord. That comes down to solving equations of degree 2. So it should be fast enough.

I did not know about getPointAtDist and I don't find how to call it. But I found now that a stroke has a method get_point_at_dist(). It is the same I suppose.

Yes that error measure is the trouble spot. It should be made faster before even thinking to try to make the code faster elsewhere. But we are measuring distance between something like a stroke and its candidate approximate Bezier arc. There is no guarantee that the curves are close to each other anywhere else but the three points p0,p3,K. The two curves may not run side by side, and the stroke can contain small and large bends. The measure must take into account the whole lengths of the curves somehow; one point is not enough. But anyhow, I am sure the code could be made better with some better idea. This version is working all right, and for an experimental plugin it will do so far.

As a small entertainment I mention that some years ago my Parametric curves plugin (some old version) used as the error measure the area between two curves. The area was computed by summing a large number of narrow triangles. Well, no sense in going back to that solution...

My long practice of programming says that the best algorithm is one that work fast in the most frequent cases, but doesn't fail (or has a fallback) for the pathological cases even if that makes it run much slower for these. So any shortcut is OK if you can evaluate how good/bad the result is.
Reply


Messages In This Thread
Simplifying a path - by Ottia Tuota - 05-16-2021, 09:20 AM
RE: Simplifying a path - by Ottia Tuota - 05-16-2021, 10:47 AM
RE: Simplifying a path - by denzjos - 05-16-2021, 04:24 PM
RE: Simplifying a path - by Ottia Tuota - 05-16-2021, 05:06 PM
RE: Simplifying a path - by Krikor - 05-16-2021, 05:23 PM
RE: Simplifying a path - by Ottia Tuota - 05-16-2021, 07:10 PM
RE: Simplifying a path - by Ofnuts - 05-16-2021, 09:17 PM
RE: Simplifying a path - by Ottia Tuota - 05-17-2021, 04:52 AM
RE: Simplifying a path - by Ofnuts - 05-17-2021, 10:57 AM
RE: Simplifying a path - by Ottia Tuota - 05-18-2021, 03:18 PM
RE: Simplifying a path - by Ofnuts - 05-18-2021, 05:27 PM
RE: Simplifying a path - by Ottia Tuota - 05-19-2021, 07:46 AM
RE: Simplifying a path - by Ofnuts - 05-19-2021, 12:13 PM
RE: Simplifying a path - by Ottia Tuota - 05-19-2021, 02:33 PM
RE: Simplifying a path - by Ottia Tuota - 05-31-2021, 05:36 PM
RE: Simplifying a path - by Zero01 - 05-31-2021, 08:46 PM
RE: Simplifying a path - by Ottia Tuota - 06-01-2021, 06:16 AM
RE: Simplifying a path - by Ottia Tuota - 06-27-2021, 01:02 PM
RE: Simplifying a path - by Krikor - 11-16-2021, 05:06 PM
RE: Simplifying a path - by Ottia Tuota - 11-16-2021, 06:11 PM

Forum Jump: