From: Ken Starks <ken@la...>  20080825 18:27:06

Reply sent privately (in error) on 24 August Mico Filós wrote: > Hi, > > I am sorry if this is a trivial question but I cannot figure out how > to do this. > > Imagine I have a nonlinear function f(x) and its linearization at some > point (x0,f(x0)), > given by y(x) = f'(x0) (x  x0) + y0, where y0 = f(x0). Imagine also that > I don't use the same scale for the x and y axes. How can I obtain a > straight line that > *looks* perpendicular to the tangent y(x)? > > Since the x and y scales are not the same, a line with slope equal to > 1/f'(x0) > does not look perpendicular to y(x). I want to plot a straight line > that passes through > an arbitrary point of the tangent (not necessarily (x0,y0)) and that > looks perpendicular to > it. My idea is actually to plot the projection of an arbitrary point > of the nonlinear function, > (x1,f(x1)) to the subspace spanned by the tangent at x0. For me the > most straightforward thing to do would be: > > * Compute the angle theta (on the actual canvas, i.e., as it looks > on the screen) of the path > defined by the tangent function y(x) > > * Plot a line path L with an angle theta + pi/2 that passes through > some particular point > of the tangent Q=(x0', y0'), which I specify. > > * Find the intersection R of the line L with the path defined by > the nonlinear function. > > * Ideally, I would stroke only the portion of L that connects the > point > (x0',y0') with the intersection point R. > > Describing this in words is painful. I hope you see what I mean. > > Thanks a lot in for your patience. > > Mico > >  > 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://moblincontest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > PyXuser mailing list > PyXuser@... > https://lists.sourceforge.net/lists/listinfo/pyxuser > > >  from pyx import * g = graph.graphxy(width=8, x=graph.axis.linear(min=5, max=5)) g.plot(graph.data.function("y(x)=x*x")) # Let us plot the tangent at (x0,y0) = (2,4) slope 4 g.plot(graph.data.function("y(x)=4*(x1)")) """ Let us take two more points on the tangent """ slope=4 deltaX=2 x1=3 # example, you can change this x2 = x1 + deltaX y1 = slope * (x1 1) y2 = slope * (x2  1) """ Now you need to get the two points (x1,y1), (x2,y2) into canvascoordinates rather than scaled coordinates. This is the crucial stage that will provide for your peculiar request that the line *looks* perpendicular to the tangent line. I shall call these UV coordinates, and their origin is bottom left of the canvas (g), their units the usual userunits (e.g cm) """ u1,v1= g.pos(x1,y1) u2,v2= g.pos(x2,y2) deltaU=u2u1 deltaV=v2v1 # lastly a point (u3,v3) that can define your 'normal' from (u1,v1) u3=u1deltaV v3=v1+deltaU # as these are in canvas coordinates, not graph ones, we use # stroke .. path .. etc to plot a segment from u1,v1 to u3,v3 g.stroke(path.path(path.moveto(u1,v1),path.lineto(u3,v3))) g.writePDFfile("graph3") 