## Re: [PyX-user] merging paths and graphs

 Re: [PyX-user] merging paths and graphs From: Ken Starks - 2008-08-25 18:28:35 Attachments: Message as HTML ``` Stefan Schenk wrote: > Hi Mico, > > Am Freitag 22 August 2008 20:36 schrieb Mico Filós: > [...] > >> Describing this in words is painful. I hope you see what I mean. >> > > I think i now understand the pain;-) You want to achieve something like the > following? > > #------------------------------------------------------------------------------ > > from pyx import * > > g = graph.graphxy(width=8) > f = g.plot(graph.data.function("y(x)=sin(x)/x", min=-10, max=10)) > > g.doplot(f) > > # The point that defines the tangent > l = 0.51*f.path.arclen() > x0, y0 = f.path.at(l) > > tangent = f.path.tangent(l, length=4) > g.stroke(tangent) > > # Path that is perpendicular to tangent > projector = tangent.transformed(trafo.rotate(90, x0, y0)) > > # Some other arbitrary point > l2 = 0.7*f.path.arclen() > x1, y1 = f.path.at(l2) > > # Find the intersection of a line from x1, y1 perpendicular to tangent with > # tangent > a, b = projector.transformed(trafo.translate(x1-x0, > y1-y0)).intersect(tangent) > u, v = tangent.at(b[0]) > > g.stroke(path.line(x1, y1, u, v)) > > > g.writeEPSfile("project_function_to_tangent") > > #------------------------------------------------------------------------------ > > > However there is still the problem that the points (x0, y0) and (x1, y1) > are determined by some length of the path. > > Does anyone know a way in pyx to translate some graph-coordinate x into a > path-length? > > If not, you probably have to do tangent by hand and (x1, y1) will be > something like > x1, y1 = g.pos(x, y(x)) > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > PyX-user mailing list > PyX-user@... > https://lists.sourceforge.net/lists/listinfo/pyx-user > > > There is a genuine problem here that would be useful to solve, in the context of involutes and evolutes, of constucting a curve as an envelope, and similar tasks. It is a task that should almost certainly be solved for parametric paths rather than graphs of functions, although they would be a special case. Another special case, that of applying unequal axis-scaling, possibly not even linear, as here, is possible I suppose, but is quite likely to be silly. If you distort your geometry in this way, you should surely distort your ruler/tape-measure and protractor to match. The idea of starting with such a pathological example as ("y(x)=sin(x)/x", min=-10, max=10) is either tongue-in-cheek, or a troll. ---------------------------------------------------- So let us start with the simpler (but not insubstantial) task: Same problem, but restricted to paths that consist of a single, non-self-intersecting cubic Bezier. Can this be solved analytically, and if not what is the most stable, accurate, and/or quickest numerical method that Python can provide ? I can't imagine that recursive chopping in half, followed by Pythagoras' theorem on all the bits is likely to be it. Cheers, Ken. ```

 Re: [PyX-user] merging paths and graphs From: Ken Starks - 2008-08-25 18:28:35 Attachments: Message as HTML ``` Stefan Schenk wrote: > Hi Mico, > > Am Freitag 22 August 2008 20:36 schrieb Mico Filós: > [...] > >> Describing this in words is painful. I hope you see what I mean. >> > > I think i now understand the pain;-) You want to achieve something like the > following? > > #------------------------------------------------------------------------------ > > from pyx import * > > g = graph.graphxy(width=8) > f = g.plot(graph.data.function("y(x)=sin(x)/x", min=-10, max=10)) > > g.doplot(f) > > # The point that defines the tangent > l = 0.51*f.path.arclen() > x0, y0 = f.path.at(l) > > tangent = f.path.tangent(l, length=4) > g.stroke(tangent) > > # Path that is perpendicular to tangent > projector = tangent.transformed(trafo.rotate(90, x0, y0)) > > # Some other arbitrary point > l2 = 0.7*f.path.arclen() > x1, y1 = f.path.at(l2) > > # Find the intersection of a line from x1, y1 perpendicular to tangent with > # tangent > a, b = projector.transformed(trafo.translate(x1-x0, > y1-y0)).intersect(tangent) > u, v = tangent.at(b[0]) > > g.stroke(path.line(x1, y1, u, v)) > > > g.writeEPSfile("project_function_to_tangent") > > #------------------------------------------------------------------------------ > > > However there is still the problem that the points (x0, y0) and (x1, y1) > are determined by some length of the path. > > Does anyone know a way in pyx to translate some graph-coordinate x into a > path-length? > > If not, you probably have to do tangent by hand and (x1, y1) will be > something like > x1, y1 = g.pos(x, y(x)) > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > PyX-user mailing list > PyX-user@... > https://lists.sourceforge.net/lists/listinfo/pyx-user > > > There is a genuine problem here that would be useful to solve, in the context of involutes and evolutes, of constucting a curve as an envelope, and similar tasks. It is a task that should almost certainly be solved for parametric paths rather than graphs of functions, although they would be a special case. Another special case, that of applying unequal axis-scaling, possibly not even linear, as here, is possible I suppose, but is quite likely to be silly. If you distort your geometry in this way, you should surely distort your ruler/tape-measure and protractor to match. The idea of starting with such a pathological example as ("y(x)=sin(x)/x", min=-10, max=10) is either tongue-in-cheek, or a troll. ---------------------------------------------------- So let us start with the simpler (but not insubstantial) task: Same problem, but restricted to paths that consist of a single, non-self-intersecting cubic Bezier. Can this be solved analytically, and if not what is the most stable, accurate, and/or quickest numerical method that Python can provide ? I can't imagine that recursive chopping in half, followed by Pythagoras' theorem on all the bits is likely to be it. Cheers, Ken. ```