A y=f(x) function is given as path; for a set of x-coordinates, I want to place node (x,f(x)) onto the path, and connect it with (x,0) with vertical line.

I have not got very far myself:

  \def\fSpec{ (-2,-2.2) .. controls (-1,2.5) and (.5,-1.7) .. (2,1.6) }
  \draw[thin] \fSpec;
  \foreach\x in \xxx{
      %% how to find f(\x) here?

I've know about the intersections library, but it seems like overkill; I would like to learn something more elegant.

I cannot give parametrically along the path length, because there will be multiple functions with different shapes and the points need to have the same x-coordinates for all of them.

  • 1
    If you can't specify the functions exactly in the form y = f(x) then the intersections library is most definitely not overkill. Otherwise you are trying to solve p(t) = x and then substitute back in for y = q(t). The first of these involves solving a cubic which, although possible, is not pretty. The routine used by the intersection library for finding intersections is, I think, really quite an elegant solution to this problem. Nov 9, 2011 at 11:04
  • @eudoxos: Is your curved path just something you drew "by hand"? In that case, you might be better off just finding a third-order polynomial that looks appropriate for your purpose, and then using that in your drawing.
    – Jake
    Nov 9, 2011 at 11:18
  • @Jake: Thanks for the tip, I had it as back-up solution. I have to delve into how to evaluate expressions with PGF then ;-)
    – eudoxos
    Nov 9, 2011 at 11:51
  • @AndrewStacey: can you convert the comment to answer so that I can accept it? (Or is there a way I can do it myself?)
    – eudoxos
    Nov 9, 2011 at 11:53
  • Do you need anything beyond what Jake has said? I really do recommend the intersections library for this if "by eye" isn't accurate enough. Nov 9, 2011 at 12:08

1 Answer 1


Andrew Stacey said it in the comments: The only alternative to the intersections library is to provide the curve as a function. Here's one that I fitted by eye:

Your curve is shown in light gray. If you don't need to recreate the curve very closely, you could of course make do with a simpler function.


  \def\fSpec{ (-2,-2.2) .. controls (-1,2.5) and (.5,-1.7) .. (2,1.6) }
  \draw [gray!50] \fSpec;
  \foreach \x in \xxx{
      \draw (\x,0) -- ({\x},{0.25+1.3*(\x+0.15)^3/5-(\x+0.15)^2/5-\x/10});
  \draw [red] plot [domain=-2:2] ({\x},{0.25+1.3*(\x+0.15)^3/5-(\x+0.15)^2/5-(\x)/10});


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.